Add support for validate_sql method to BigQuery #819
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 theBigQueryConnectionManager. This simply passes through the input SQL
with the
dry_run
QueryJobParameter flag set True. This will resultin 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