Skip to content

Instantly share code, notes, and snippets.

View shanecglass's full-sized avatar

Shane Glass shanecglass

View GitHub Profile
@shanecglass
shanecglass / generate_sql.py
Created January 30, 2025 21:51
Generate SQL using table metadata and ERD
def generate_sql(request: str, project_id: str = project_id) -> str:
"""
Generate a valid BigQuery SQL query that fulfills the user request
Args:
request (str): The task that defines the query output
project_id (str): A string the project ID for the relevant project
Returns:
json: A JSON object containing a BigQuery SQL query that fulfills the user request and an explanation of why this query was generated
@shanecglass
shanecglass / sql_gen_tool.py
Created January 30, 2025 21:49
Creating a tool for Gemini models that uses the SQL generation function to parse ERDs and metadata
generate_sql_func = FunctionDeclaration(
name="generate_sql",
description="""
Generate a valid BigQuery SQL query that fulfills the user request
Args:
request (str): The task that defines the query output
project_id (str): The project ID for the relevant Google Cloud project
Returns:
@shanecglass
shanecglass / erd.json
Created January 30, 2025 20:58
Example of the ERD generated by Gemini 1.5 Pro
{
"from_table": "order_items",
"from_join_columns": [
"product_id"
],
"to_table": "products",
"to_join_columns": [
"id"
],
"join_type": "INNER JOIN"
@shanecglass
shanecglass / parse_bq_metadata.py
Created January 30, 2025 20:26
Parsing BigQuery for table and dataset metadata within a given project
def get_table_schemas(schema_folder=schema_dir,
project_id=project_id):
"""
Generate schema files for all tables in BigQuery datasets within the given project
Used to improve the quality of sql generation across the project.
Args:
schema_folder (str): The directory with a folder for each BigQuery dataset that contain schema files for each table
project_id (str): A string the project ID for the relevant project
@shanecglass
shanecglass / bq_models.md
Last active May 1, 2024 15:51
Models with a direct integration to BigQuery (as of May 1, 2024)