BigQuery
import { Aside } from ‘@astrojs/starlight/components’;
Connection
Section titled “Connection”In workflow_settings.yaml:
warehouse: kind: bigquery project: my-gcp-project # GCP project ID location: US # BigQuery region defaultDataset: analytics # default dataset for actionsCredentials are resolved via Application Default Credentials. Run gcloud auth application-default login locally, or attach a service account in CI.
Partitioning and clustering
Section titled “Partitioning and clustering”Use partitionBy and clusterBy in the action config block:
-- definitions/orders.sqlxconfig { type: "table", partitionBy: "DATE(created_at)", clusterBy: ["customer_id", "region"], partitionExpirationDays: 90}
SELECT order_id, customer_id, region, created_atFROM ${ref("raw_orders")}Incremental tables
Section titled “Incremental tables”SQLAnvil generates a BigQuery MERGE statement for incremental tables:
-- definitions/events_incremental.sqlxconfig { type: "incremental", uniqueKey: ["event_id"], partitionBy: "DATE(event_timestamp)"}
SELECT event_id, event_timestamp, user_id, event_nameFROM ${ref("raw_events")}${when(incremental(), `WHERE event_timestamp > (SELECT MAX(event_timestamp) FROM ${self()})`)}Labels
Section titled “Labels”Attach BigQuery labels to any action for cost tracking:
config { type: "table", labels: { team: "analytics", env: "production" }}SELECT ...Materialized views
Section titled “Materialized views”config { type: "view", materialized: true, partitionBy: "DATE(created_at)"}SELECT ...BigQuery reservations
Section titled “BigQuery reservations”To run actions on a specific BigQuery reservation (slot commitment):
defaultReservation: projects/my-project/locations/US/reservations/my-reservationOr per-action in YAML:
actions:- table: filename: heavy_model.sql reservation: projects/my-project/locations/US/reservations/heavyAdditional BigQuery options
Section titled “Additional BigQuery options”Pass arbitrary BigQuery table options via additionalOptions:
config { type: "table", additionalOptions: { kms_key_name: "projects/my-proj/locations/us/keyRings/my-ring/cryptoKeys/my-key" }}SELECT ...Assertions
Section titled “Assertions”SQLAnvil generates assertion views in BigQuery under your defaultDataset. A failing assertion (one that returns rows) is reported as an error:
config { type: "assertion"}SELECT * FROM ${ref("orders")} WHERE order_total < 0