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

Add support for validate_sql method to BigQuery #819

Merged
merged 1 commit into from
Jul 12, 2023

Conversation

tlento
Copy link
Contributor

@tlento tlento commented Jul 12, 2023

resolves #805

Problem

In CLI contexts MetricFlow will issue dry run queries as part
of its warehouse validation operations, and so we are adding a
validate_sql method to all adapters.

The implementation we use for SQLAdapter classes does not
work with BigQuery, as BigQuery does not support the EXPLAIN
keyword.

Solution

This PR adds support for the validate_sql method to BigQuery. It
does so by creating a BigQuery-specific dry_run method on the
BigQueryConnectionManager. This simply passes through the input SQL
with the dry_run QueryJobParameter flag set True. This will result
in BigQuery computing and returning a cost estimate for the query,
or raising an exception in the event the query is not valid.

Note: constructing the response object involves some repetitive value
extraction from the QueryResult returned by BigQuery. While I would
ordinariy prefer to tidy this up first we are pressed for time, and so
we postpone that cleanup in order to keep this change as isolated
as possible.

Checklist

  • I have read the contributing guide and understand what's expected of me
  • I have run this code in development and it appears to resolve the stated issue
  • This PR includes tests, or tests are not required/relevant for this PR
  • This PR has no interface changes (e.g. macros, cli, logs, json artifacts, config files, adapter interface, etc) or this PR has already received feedback and approval from Product or DX

@cla-bot cla-bot bot added the cla:yes label Jul 12, 2023
@github-actions
Copy link
Contributor

Thank you for your pull request! We could not find a changelog entry for this change. For details on how to document a change, see the dbt-bigquery contributing guide.

@tlento tlento force-pushed the CT-2773-add-validate-sql-method branch 3 times, most recently from 9136532 to 7772764 Compare July 12, 2023 13:33
@tlento tlento marked this pull request as ready for review July 12, 2023 13:33
@tlento tlento requested a review from a team as a code owner July 12, 2023 13:33
@tlento tlento force-pushed the CT-2773-add-validate-sql-method branch from 7772764 to 5c14854 Compare July 12, 2023 13:36
In CLI contexts MetricFlow will issue dry run queries as part
of its warehouse validation operations, and so we are adding a
validate_sql method to all adapters.

This commit adds support for the validate_sql method to BigQuery. It
does so by creating a BigQuery-specific `dry_run` method on the
BigQueryConnectionManager. This simply passes through the input SQL
with the `dry_run` QueryJobParameter flag set True. This will result
in BigQuery computing and returning a cost estimate for the query,
or raising an exception in the event the query is not valid.

Note: constructing the response object involves some repetitive value
extraction from the QueryResult returned by BigQuery. While I would
ordinariy prefer to tidy this up first we are pressed for time, and so
we postpone that cleanup in order to keep this change as isolated
as possible.
@tlento tlento force-pushed the CT-2773-add-validate-sql-method branch from 5c14854 to 0e79408 Compare July 12, 2023 13:38
@mikealfare mikealfare merged commit d0d593e into main Jul 12, 2023
24 checks passed
@mikealfare mikealfare deleted the CT-2773-add-validate-sql-method branch July 12, 2023 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ADAP-666] [CT-2773] Implement validate_sql for BigQuery adapter
3 participants