BigQuery
Connect & Ingest data from / to a BigQuery database
Setup
The following credentials keys are accepted:
project(required) -> The GCP project ID for the projectdataset(required) -> The default dataset (like a schema)gc_bucket(optional) -> The Google Cloud Storage Bucket to use for loading (Recommended)key_file(optional) -> The path of the Service Account JSON. If not provided, the Google Application Default Credentials will be used.key_body(optional) -> The Service Account JSON key content as a string. You can also provide the JSON content in env varGC_KEY_BODY.location(optional) -> The location of the account, such asUSorEU. Default isUS.extra_scopes(optional) -> An array of strings, which represent scopes to use in addition tohttps://www.googleapis.com/auth/bigquery. e.g.["https://www.googleapis.com/auth/drive", "https://www.googleapis.com/auth/spreadsheets"]use_adbc(optional) -> Enable Arrow Database Connectivity (ADBC) driver for high-performance data transfer. See ADBC for setup and details. (v1.5.2+)adbc_uri(optional) -> Override the automatically constructed ADBC connection URI when usinguse_adbc=true.
If you'd like to have sling use the machine's Google Cloud Application Default Credentials (usually with cloud auth application-default login), don't specify a key_file (or the env var GC_KEY_BODY).
Using sling conns
Here are examples of setting a connection named BIGQUERY. We must provide the type=bigquery property:
$ sling conns set BIGQUERY type=bigquery project=<project> dataset=<dataset> gc_bucket=<gc_bucket> key_file=/path/to/service.account.json location=<location>Environment Variable
See here to learn more about the .env.sling file.
You can also provide Sling the Service Account JSON in key_body as a string, or via environment variable GC_KEY_BODY, instead of a key_file.
Sling Env File YAML
See here to learn more about the sling env.yaml file.
BigQuery Table Partitioning
BigQuery as a target
When BigQuery is the target, Sling writes with BigQuery load jobs, not streaming inserts. The write path is:
Stage the data as files. Sling writes the incoming stream to files (CSV by default). If the
gc_bucketcredential is set, the files are staged in that Google Cloud Storage bucket; if it is not set, they are staged locally and streamed to the load job. Settinggc_bucketis recommended for anything but small loads.Run a load job. Sling submits a BigQuery load job to read the staged files into a temporary table. Load jobs are batched and rate-limited, so a load is one job per batch rather than a row-by-row insert. Sling does not use BigQuery streaming inserts.
Finalize. For
full-refreshthe target is dropped and replaced. ForincrementalSling runs a native BigQueryMERGEfrom the temporary table into the target using yourprimary_keyand the resolvedmerge_strategy— all four merge strategies are supported.
For BigQuery-specific incremental caveats (partitioned targets, require_partition_filter), see BigQuery Table Partitioning above and BigQuery as a source below.
BigQuery as a source
BigQuery is a standard SQL source: Sling reads it with a SELECT statement, so full-refresh, incremental, and backfill all work.
Partitioned tables
A plain full-refresh reads a partitioned table with SELECT * — partitioning by itself does not block the read.
If the source table sets require_partition_filter = TRUE, BigQuery rejects any query that does not filter on the partition column. Sling does not detect this option or inject a partition predicate automatically, so a plain SELECT * fails. Add a where source option (or --where flag) that filters the partition column to satisfy the requirement:
Incremental from BigQuery
BigQuery works as an incremental source with primary_key + update_key like any SQL database. Sling pulls rows where update_key > max(update_key) in the target:
If the table also has require_partition_filter = TRUE, the incremental predicate is on the update_key, which is not necessarily the partition column. Add a where on the partition column, or make the partition column your update_key, so BigQuery's filter requirement is met.
Multiple datasets to Snowflake (full-refresh, wildcards)
Use a wildcard stream to replicate every table across datasets. Reference the source dataset in the object name with the {stream_schema} runtime variable:
Source partitioning does not affect full-refresh ingestion (unless require_partition_filter is set — see above).
If you are facing issues connecting, give sling assist a try, or reach out to us at support@slingdata.io, on discord or open a Github Issue here.
Last updated
Was this helpful?