Bigquery

From G1Joshi/Agent-Skills · View interactive version

Bigquery is an AI agent skill from the GitHub repository G1Joshi/Agent-Skills. Expert Google Cloud BigQuery assistance covering standard SQL, partitioning, clustering, cost optimization, and ML. Use when running petabyte analytics queries, designing data warehouse schemas, or optimizing BI workloads.

How to use this skill

Skill file

Google BigQuery

BigQuery is Google's serverless, highly scalable, and cost-effective multi-cloud data warehouse. It processes terabytes in seconds.

When to Use

Quick Start

-- Standard SQL
SELECT name, COUNT(*) as count
FROM `bigquery-public-data.usa_names.usa_1910_2013`
GROUP BY name
ORDER BY count DESC
LIMIT 10;

Core Concepts

Capacitor Columnar Storage & Dremel Query Engine

Data is stored in proprietary Capacitor columnar format with dynamic tree-based Dremel execution slots:

-- Partitioned & Clustered Table DDL
CREATE OR REPLACE TABLE `my_project.analytics.user_events`
(
  event_id STRING,
  user_id STRING,
  event_name STRING,
  event_timestamp TIMESTAMP,
  metadata JSON
)
PARTITION BY DATE(event_timestamp)
CLUSTER BY user_id, event_name
OPTIONS(
  description="Partitioned clickstream events with clustering for point lookups",
  require_partition_filter=true
);

Semi-Structured Native JSON Querying

Queries nested JSON attributes efficiently without schema migrations:

SELECT
  user_id,
  JSON_VALUE(metadata.device.os) AS os_name,
  JSON_EXTRACT_SCALAR(metadata, '$.cart.total') AS cart_total
FROM `my_project.analytics.user_events`
WHERE DATE(event_timestamp) = CURRENT_DATE()
  AND JSON_VALUE(metadata.action) = 'checkout';

BigQuery ML Model Training

Trains and evaluates predictive models entirely inside SQL:

CREATE OR REPLACE MODEL `analytics.churn_prediction_model`
OPTIONS(model_type='logistic_reg', input_label_cols=['has_churned']) AS
SELECT
  total_spend,
  session_count,
  has_churned
FROM `analytics.customer_features`;

Common Patterns

Partitioning and Clustering for Cost-Optimized Queries

Problem: Full table scans across billions of event rows lead to astronomical query costs and high latency.

Solution:

Partition by date and cluster by high-cardinality lookup keys:

CREATE TABLE `project.analytics.events` (
  event_id STRING,
  user_id STRING,
  event_type STRING,
  event_timestamp TIMESTAMP
)
PARTITION BY DATE(event_timestamp)
CLUSTER BY user_id, event_type
OPTIONS (
  require_partition_filter = TRUE,
  partition_expiration_days = 365
);

Best Practices

Do:

Don't:

Troubleshooting

| Error | Cause | Solution |

| :------------------------------------------ | :--------------------------------------------------------------------- | :---------------------------------------------------------------------------------------- |

| Cannot query without partition filter | require_partition_filter enabled but query lacked date WHERE clause. | Include WHERE DATE(event_timestamp) >= 'YYYY-MM-DD' in query. |

| Resources exceeded during query execution | Memory exhaustion from large skew in JOIN or ORDER BY. | Pre-aggregate data, filter early, and avoid ORDER BY without LIMIT. |

| Quota exceeded: Exceeded rate limits | Too many concurrent DDL/DML mutation queries per table. | Batch append mutations using BigQuery Storage Write API rather than small single INSERTs. |

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.