Skip to content

Sources

BigQuery

Load BigQuery (beta) tables, views and query results through the Storage Read API: connections, choosing tables, query tables, cursors, types, cost and permissions.

This source is in beta: it is tested, but gets less everyday use than the other connectors, so expect rough edges, and please report them in GitHub issues.

A bigquery source loads tables, views and query results from BigQuery. SQLLoad reads the rows as Arrow through the Storage Read API, several streams at once. No bucket is needed.

[connections.bq]
kind = "bigquery"
location = "EU"
service_account_key = "${ENV:BIGQUERY_KEY}"
[sources.marts]
kind = "bigquery"
connection = "bq"
description = "Tables of the marts datasets."
include = ["marts.*"]
exclude = ["marts.tmp_*"]
write_strategy = "replace"
[sources.marts.tables."marts.events"]
description = "Events, one row per event."
cursor_column = "event_at"
write_strategy = "append"
[sources.marts.tables.recent]
description = "Orders of the last week, with their customer."
sql = """
SELECT o.*, c.name
FROM marts.orders o JOIN marts.customers c USING (customer_id)
"""
cursor_column = "ordered_at"
write_strategy = "append"

A source uses a bigquery connection, the same kind a BigQuery target uses. Read sessions and query jobs are billed to the connection’s project, and query jobs run in its location. To read tables that live in another project, set the source’s project.

include and exclude are dataset.table patterns, such as marts.*, and are case-sensitive, as BigQuery names are. Listing them bills nothing. Query tables, where and column settings work as for every database source; see Sources.

BigQuery doesn’t enforce primary keys, and plan refuses unique_key = "{primary_key}" when a key column is NULLABLE, as it usually is: name the unique_key columns instead (see NULLs in keys).

Write a query table’s sql in GoogleSQL, naming tables as dataset.table in the connection’s project, or as `project.dataset.table` in another, the source’s project included. plan describes it with a dry run, which bills nothing.

  • Tables are read through a read session, in up to eight parallel streams, with the cursor window as its row filter. All of a table’s windows see the data as of the moment its load starts.
  • Views, materialized views, external tables, query tables and tables with where run a query job, whose result is read through a read session. They read the data as it is when the job runs.

When the target is BigQuery and writes through the source’s own connection, no rows pass through SQLLoad. BigQuery selects each batch’s rows with one INSERT ... SELECT query job into the load’s staging or build table, with the same types SQLLoad’s reader would give them:

route BigQuery INSERT ... SELECT on the source's connection (nothing through the loader)

SQLLoad reads the rows itself, and plan -v says why, for a table that:

  • has a STRUCT, RANGE, GEOGRAPHY or repeated column, which SQLLoad converts to JSON or text;
  • pins a column to another type than its own;
  • is in another location than the connection’s, which a query job can’t reach;
  • has a mask, parse, transform or checks;
  • loads into a target on another bigquery connection, even with the same key.

where is a condition in GoogleSQL, such as where = "region = 'EU' AND status != 'void'"; see Filtering rows. A table with where is read through a query job, which bills the bytes it scans.

BigQuery type Loads as
INT64 int
NUMERIC(p,s), BIGNUMERIC(p,s), p up to 38 decimal(p,s); a NUMERIC with no precision is decimal(38,9)
FLOAT64 float
BOOL bool
STRING, STRING(n) text, varchar(n)
BYTES binary
DATE, TIME, DATETIME date, time, timestamp_ntz
TIMESTAMP timestamp_tz, in UTC
JSON, STRUCT, RANGE json
ARRAY<T> json, or array(T) when pinned
GEOGRAPHY text, as WKT
BIGNUMERIC with no precision none: pin a decimal(p,s) its values fit, or text
INTERVAL none: pin text, which writes it as 14 mons 3 days 4 hours 5 mins 6.500000000 secs, or exclude the column

Pin a type to load a column another way, such as columns = { total = "decimal(18,2)" }; a value that doesn’t fit fails the read, naming the column. NaN and infinities inside a repeated FLOAT64 load as null in its JSON. See Types.

Read sessions bill the bytes of the columns and rows they read. Query jobs (views, query tables, where, and tables BigQuery loads itself) bill their scan. Listing tables, describing them and dry runs bill nothing.

An incremental read of a NULLABLE cursor column under the default null_cursor = "fail" first counts its NULL cursors in a query job, which bills a scan of the cursor column. See NULL cursor values.

The service account needs bigquery.readSessionUser on the connection’s project, and bigquery.dataViewer on the datasets it reads. Views, query tables and tables with where also need bigquery.jobUser on the connection’s project, and so does a table read from a NULLABLE cursor column under the default null_cursor = "fail", whose count of NULL cursors runs as a query job (bigquery.jobs.create).