Google BigQuery

Go deep on BigQuery: serverless execution, slots and bytes-scanned pricing, partitioning and clustering, nested and repeated fields, and cost controls.

Intermediate · about 8 hours · difficulty 3/5

Learn first: How Cloud Data Warehouses Work

BigQuery is Google Cloud's serverless warehouse. There is no cluster to manage, and the free sandbox lets students practise without a credit card, which makes it the easiest warehouse to learn on.

Core concepts

  • Projects, datasets, tables: the hierarchy for organising data and permissions.
  • Serverless execution with slots (units of compute). On-demand pricing charges per TB scanned; capacity pricing reserves slots.
  • Partitioned tables (by ingestion time, a date column or integer range) and clustered tables (sorted by up to four columns) reduce bytes scanned.

Working with data

  • Load from Cloud Storage, stream with the Storage Write API, or query files directly as external tables.
  • Nested and repeated fields (STRUCT and ARRAY) store an order with its items in one row; use UNNEST to flatten.
  • Standard SQL with window functions, QUALIFY, MERGE and scripting.
  • Public datasets are great for practice.

Cost control

  • Always check the bytes estimate before running.
  • Require partition filters on big tables.
  • Set custom quotas and budget alerts.
  • Avoid SELECT *; select columns.

Ecosystem

BigQuery pairs with Cloud Storage, Pub/Sub, Dataflow, Dataproc (managed Spark), Cloud Composer (managed Airflow) and Looker.

Pitfalls

  • Assuming LIMIT reduces cost.
  • Partitioning tables that are too small, or partitioning by a column queries never filter on.

You are ready to move on when you can load data into a partitioned and clustered table, query nested data with UNNEST, and show bytes scanned dropping because of your table design.

Key concepts

  • Projects, datasets, tables
  • Slots and on-demand pricing
  • Partitioned tables
  • Clustered tables
  • STRUCT, ARRAY and UNNEST
  • Public datasets and sandbox
  • Quotas and budget alerts
  • Storage Write API

Other options for this step

  • Snowflake: Go deep on Snowflake: virtual warehouses, micro-partitions, stages and COPY, time travel, zero-copy cloning, roles and cost controls.
  • Amazon Redshift: Go deep on Redshift: provisioned and serverless options, distribution and sort keys, COPY from S3, Spectrum and workload management.

Mini project

In the BigQuery sandbox, load a CSV from Cloud Storage into a date-partitioned, clustered table. Write five analytical queries and record bytes processed for each with and without partition filters.

Check yourself

When would you store order items as a repeated STRUCT inside the orders table instead of a separate order_items table?

Free resources