evidence-dev / sqltools-bigquery-driver

Query and Explore BigQuery from VSCode
https://marketplace.visualstudio.com/items?itemName=Evidence.sqltools-bigquery-driver
MIT License
40 stars 5 forks source link

Query Cost Estimation #19

Closed Italosayan closed 11 months ago

Italosayan commented 11 months ago

I'm looking to make a contribution to the project.

@archiewood have you looked into adding the query cost estimation to the plugin?

image
from google.cloud import bigquery

# Construct a BigQuery client object.
client = bigquery.Client()

# Set your query here
query = """
SELECT name, count
FROM `table`
WHERE state = 'TX'
"""

# Set up the dry run query configuration
job_config = bigquery.QueryJobConfig(dry_run=True, use_query_cache=False)

# API request - dry run query
dry_run_query_job = client.query(query, job_config=job_config)

# A dry run query does not provide a row iterator, only statistics
print(f"This query will process {dry_run_query_job.total_bytes_processed} bytes.")
archiewood commented 11 months ago

Hi @Italosayan

I've briefly looked into it, but not extensively. Contributions are certainly welcomed!

I think calling the dry run function shouldn't be too bad, similar to your example above.

I suspect the hard part is wiring it up into SQLtools, as it does not have inbuilt functionality to support cost estimation.

We need:

Feel free to reach out on slack if I can help at all.

archiewood commented 11 months ago

Also I think this is a duplicate of #13 - let's continue over there!