Skip to content
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

BigQuery: error when using created table ref as query destination #6938

Closed
bspeice opened this issue Dec 17, 2018 · 3 comments
Closed

BigQuery: error when using created table ref as query destination #6938

bspeice opened this issue Dec 17, 2018 · 3 comments
Assignees
Labels
api: bigquery Issues related to the BigQuery API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@bspeice
Copy link

bspeice commented Dec 17, 2018

Environment details

BigQuery API, Linux, Python 2.7

Steps to reproduce

I'm getting a 400 error when using a newly-created table ref as a destination:

Code example

from google.cloud import bigquery
client = biquery.Client()
export_ref = client.create_table('project_name.dataset.table')
config = bigquery.QueryJobConfig()
config.destination = export_ref
client.query('SELECT MY_FIELDS', job_config=config)

Stack trace

Traceback (most recent call last):
  File "bq_export.py", line 112, in <module>
    main(args.table_ref[0])
  File "bq_export.py", line 102, in main
    export_block(client, table_ref, block_id, block[0], block[1])
  File "bq_export.py", line 50, in export_block
    q = client.query(query, job_config=q_config)
  File "/home/user/.local/lib/python2.7/site-packages/google/cloud/bigquery/client.py", line 1439, in query
    query_job._begin(retry=retry)
  File "/home/user/.local/lib/python2.7/site-packages/google/cloud/bigquery/job.py", line 553, in _begin
    retry, method="POST", path=path, data=self.to_api_repr()
  File "/home/user/.local/lib/python2.7/site-packages/google/cloud/bigquery/client.py", line 382, in _call_api
    return call()
  File "/home/user/.local/lib/python2.7/site-packages/google/api_core/retry.py", line 270, in retry_wrapped_func
    on_error=on_error,
  File "/home/user/.local/lib/python2.7/site-packages/google/api_core/retry.py", line 179, in retry_target
    return target()
  File "/home/user/.local/lib/python2.7/site-packages/google/cloud/_http.py", line 319, in api_request
    raise exceptions.from_http_response(response)
google.api_core.exceptions.BadRequest: 400 POST https://www.googleapis.com/bigquery/v2/projects/my_bucket/jobs: Required parameter is missing

What appears to be happening when I enable httplib logging is that the table ref internal representation includes a bunch of extra fields. However, the error message is incredibly confusing, as it says something required is missing, when the docs mention very clear that all parameters are optional.

@shollyman
Copy link
Contributor

create_table() returns the Table, not a TableReference. To confirm, does it work when you change the setting of the destination to export_ref.reference?

Perhaps we should extract the TableReference when the destination is passed a Table.

@shollyman shollyman self-assigned this Dec 18, 2018
@tseaver tseaver changed the title Error when using created table ref as query destination BigQuery: error when using created table ref as query destination Dec 18, 2018
@tseaver tseaver added the api: bigquery Issues related to the BigQuery API. label Dec 18, 2018
@tseaver
Copy link
Contributor

tseaver commented Dec 18, 2018

@shollyman That seems sensible, given that Client.create_table itself is willing to take any of a Table, a TableReference, or a string for its table argument. We've explicitly avoided doing client-side validation for the various job configuration fields, but that conversion would be a different thing.

Likely we'd want to do the same for any job / job configuration arguments currently expecting DatasetReference(s) or TableReference(s):

  • LoadJob.destination
  • CopyJob.sources
  • CopyJob.destination
  • ExtractJob.source
  • QueryJobConfig.default_dataset
  • QueryJobConfig.destination
  • QueryJobConfig.ddl_target_table

@tseaver tseaver added the type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. label Dec 18, 2018
@tswast
Copy link
Contributor

tswast commented Apr 2, 2019

Thanks for the exhaustive list @tseaver

The specific request of query destination was fixed in #7560 It looks like the others were tackled as part of the client methods update in #6164

@tswast tswast closed this as completed Apr 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigquery Issues related to the BigQuery API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

4 participants