Skip to content

add external_udf_uris support to query() #120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 26, 2016

Conversation

robin900
Copy link
Contributor

...with docstring and test coverage. Change write_to_table code to use the same
list comprehension to construct userDefinedFunctionResources.

@tylertreat
Copy link
Owner

lgtm, just one thing regarding the kwarg. Thanks!

@@ -276,7 +276,7 @@ def _insert_job(self, body_object):
body=body_object
).execute()

def query(self, query, max_results=None, timeout=0, dry_run=False, use_legacy_sql=None):
def query(self, query, max_results=None, timeout=0, dry_run=False, use_legacy_sql=None, external_udf_uris=[]):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't use lists as a default value for kwargs (see http://reinout.vanrees.org/weblog/2012/04/18/default-parameters.html). This should default to None and check if it's None and assign it to an empty list.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I've fixed the existing write_to_table's default arg as well, in a force update.

test coverage. Change write_to_table code to use the same
list comprehension to construct userDefinedFunctionResources.
@robin900
Copy link
Contributor Author

Are you up to making a quick 1.9.1 release to PyPI with this change? I'm using BigQuery-Python in my production code, and would like to avoid sourcing this package from my own git repo.

@tylertreat tylertreat merged commit dfdc222 into tylertreat:master Oct 26, 2016
@tylertreat
Copy link
Owner

@robin900 I will try to get a release made later today.

@robin900
Copy link
Contributor Author

@tylertreat So the bad news is that query() -- that is, the synchronous query endpoint in the v2 REST API (POST to /queries) -- doesn't support external UDFs, and there are no plans to add it. Instead, only asynchronous queries -- a POST to the /jobs endpoint -- allow support for UDFs.

I see two possible solutions:

  1. Implement BigQueryClient.query so that it uses self._insert_job(query_job_request), and does a wait_on_job and then returning when job is complete.
  2. Doing Move import to avoid possible ImportError. #1 but only in cases where external_udf_uris are present.

What are your thoughts?

An additional need: external UDFs can be inlined via inlineCode instead of resourceUri. I have a local change that accepts both external_udf_uris and external_udf_inlines as arguments to query(). Shall I include that additional argument for all relevant client methods?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants