Skip to content

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

Closed
micahyoung wants to merge 1 commit into
goccy:mainfrom
micahyoung:fix-query-dryrun-errors
Closed

Fix Query DryRun failures should return early with status codes#185
micahyoung wants to merge 1 commit into
goccy:mainfrom
micahyoung:fix-query-dryrun-errors

Conversation

@micahyoung

Copy link
Copy Markdown

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:

@micahyoung micahyoung force-pushed the fix-query-dryrun-errors branch from e2b0019 to c38b714 Compare May 10, 2023 14:48
@micahyoung micahyoung closed this Jul 21, 2024
@micahyoung micahyoung deleted the fix-query-dryrun-errors branch July 21, 2024 01:33
@micahyoung micahyoung restored the fix-query-dryrun-errors branch July 21, 2024 01:33
@micahyoung micahyoung deleted the fix-query-dryrun-errors branch July 21, 2024 01:33
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.

1 participant