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

Fix Query DryRun failures should return early with status codes #185

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

micahyoung
Copy link

This change brings Query dry-run exceptions (syntax errors, inaccessible tables, etc) closer to BigQuery behavior and adds test coverage.

Current behavior:

Test script with invalid query syntax, intended to trigger dry run exception:

from google.cloud.bigquery import Client, QueryJobConfig

def callback(callback_job):
    print(f"Callback Job: {callback_job}" )

invalid_query = "SEL"
job = Client().query(invalid_query, job_config=QueryJobConfig(dry_run=True))
job.add_done_callback(callback)

print(f"Query Job: {job}")

When: Run against BigQuery (BIGQUERY_EMULATOR_HOST is undefined)
Then: BigQuery correctly returns Syntax error exception

Traceback (most recent call last):
...
    raise exceptions.from_http_response(response)
google.api_core.exceptions.BadRequest: 400 POST https://bigquery.googleapis.com/bigquery/v2/projects/<redacted>/jobs?prettyPrint=false: Syntax error: Expected end of input but got identifier "SEL" at [1:1]

Location: None
Job ID: 28ee0424-c7ec-4b79-a61b-63e94475fad8

When: Run against Emulator (BIGQUERY_EMULATOR_HOST=http://localhost:9050, branch is main)
Then: Emulator incorrectly returns successful job and triggers callback

Callback Job: QueryJob<project=test-project, location=None, id=8bb89ea1-fb35-47f7-badb-a316a3ff8d14>
Query Job: QueryJob<project=test-project, location=None, id=8bb89ea1-fb35-47f7-badb-a316a3ff8d14>

PR behavior:

When: Run against Emulator (BIGQUERY_EMULATOR_HOST=http://localhost:9050, branch is fix-query-dryrun-errors)
Then: Emulator correctly returns Syntax error exception)

Traceback (most recent call last):
...
    raise exceptions.from_http_response(response)
google.api_core.exceptions.BadRequest: 400 POST http://localhost:9050/bigquery/v2/projects/<redacted>/jobs?prettyPrint=false: failed to parse statements: failed to parse statement: INVALID_ARGUMENT: Syntax error: Unexpected identifier "SEL" [type.googleapis.com/zetasql.ErrorLocation='\x08\x01\x10\x01']

Location: None
Job ID: b00bcf80-36dc-4bb0-847f-0b63ddb18a03
  • Note: exception message is not same but that can be improved separately

Closest equivalent tests for:

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.

None yet

1 participant