BigQuery Destinations
Bizon offers three BigQuery destination variants optimized for different workloads.
Installation
Section titled “Installation”pip install bizon[bigquery]Destination Variants
Section titled “Destination Variants”| Variant | Method | Best For | Latency |
|---|---|---|---|
bigquery | GCS Load Jobs | Large batch loads | Minutes |
bigquery_streaming | Legacy Streaming | Low-latency, small volume | Seconds |
bigquery_streaming_v2 | Storage Write API | High-throughput streaming | Seconds |
BigQuery (Batch Load)
Section titled “BigQuery (Batch Load)”Uses GCS as a staging area, then loads via BigQuery load jobs. Best for large batch workloads.
destination: name: bigquery config: project_id: my-project dataset_id: my_dataset dataset_location: US create_dataset: true gcs_buffer_bucket: my-staging-bucket buffer_size: 50 time_partitioning: type: DAYConfiguration
Section titled “Configuration”| Field | Type | Required | Default | Description |
|---|---|---|---|---|
project_id | string | Yes | - | GCP project ID |
dataset_id | string | Yes | - | BigQuery dataset ID |
dataset_location | string | No | US | Dataset location, used when the dataset is created |
create_dataset | bool | No | false | Create the dataset if it is missing. When false, a missing dataset fails the run up front |
gcs_buffer_bucket | string | Yes | - | GCS bucket for staging |
gcs_buffer_format | enum | No | parquet | Staging format. Only parquet is implemented |
buffer_size | int | No | 50 | Buffer size in MB |
buffer_flush_timeout | int | No | 600 | Max buffer age in seconds |
time_partitioning | object | No | {type: DAY, field: _bizon_loaded_at} | See Time Partitioning |
enforce_partitioning | bool | No | false | On a full refresh, drop and recreate a table whose partitioning doesn’t match the config. See Changing partitioning |
table_prefix | string | No | _bizon_ | Prefix for auto-named tables. See Table Naming |
job_timeout_seconds | float | No | 600 | Cancel a load or copy job after this long and fail the stream with a TimeoutError. null waits forever |
async_load | bool | No | false | Submit load jobs asynchronously and batch GCS files into fewer jobs |
load_files_per_job | int | No | 10 | GCS files per load job when async_load is on (min 1) |
load_max_in_flight_jobs | int | No | 3 | Load jobs in flight before the consumer waits, when async_load is on (min 1) |
Async Load Jobs
Section titled “Async Load Jobs”By default each buffer flush uploads one file to GCS and waits for its load job. With async_load: true, flushes upload and submit without blocking, and up to load_files_per_job files share one load job. This raises throughput and cuts the per-table load-job quota usage.
destination: name: bigquery config: project_id: my-project dataset_id: my_dataset gcs_buffer_bucket: my-staging-bucket async_load: true load_files_per_job: 10 load_max_in_flight_jobs: 3Delivery stays at-least-once: destination cursors are written in submission order and only once a load lands, and a failed load aborts the run before any later cursor is written. A resumed run re-fetches from the last landed load.
BigQuery Streaming
Section titled “BigQuery Streaming”Uses the legacy streaming API. Good for low-latency with moderate volume.
destination: name: bigquery_streaming config: project_id: my-project dataset_id: my_dataset dataset_location: US buffer_size: 50 buffer_flush_timeout: 300Configuration
Section titled “Configuration”| Field | Type | Required | Default | Description |
|---|---|---|---|---|
project_id | string | Yes | - | GCP project ID |
dataset_id | string | Yes | - | BigQuery dataset ID |
dataset_location | string | No | US | Dataset location |
buffer_size | int | No | 50 | Buffer size in MB |
buffer_flush_timeout | int | No | 600 | Max buffer age in seconds |
bq_max_rows_per_request | int | No | 5000 | Max rows per API call (max 10000) |
time_partitioning | object | No | {type: DAY, field: _bizon_loaded_at} | See Time Partitioning. null disables partitioning |
table_prefix | string | No | _bizon_ | Prefix for auto-named tables |
BigQuery Streaming V2 (Recommended)
Section titled “BigQuery Streaming V2 (Recommended)”Uses the Storage Write API for high-throughput streaming. Best for production real-time pipelines.
destination: name: bigquery_streaming_v2 config: project_id: my-project dataset_id: my_dataset dataset_location: US buffer_size: 100 buffer_flush_timeout: 300 bq_max_rows_per_request: 5000Configuration
Section titled “Configuration”| Field | Type | Required | Default | Description |
|---|---|---|---|---|
project_id | string | Yes | - | GCP project ID |
dataset_id | string | Yes | - | BigQuery dataset ID |
dataset_location | string | No | US | Dataset location |
buffer_size | int | No | 50 | Buffer size in MB |
buffer_flush_timeout | int | No | 600 | Max buffer age in seconds |
bq_max_rows_per_request | int | No | 5000 | Max rows per API call (max 10000) |
time_partitioning.type | enum | No | DAY | DAY, HOUR, MONTH or YEAR |
time_partitioning.field | string | No | _bizon_loaded_at | Partition column. null for ingestion-time partitioning |
enforce_partitioning | bool | No | false | On a full refresh, drop and recreate a table whose partitioning doesn’t match the config |
table_prefix | string | No | _bizon_ | Prefix for auto-named tables |
Set time_partitioning: null to create unpartitioned tables.
Authentication
Section titled “Authentication”Service Account Key
Section titled “Service Account Key”Provide a service account JSON key:
destination: name: bigquery_streaming_v2 config: project_id: my-project dataset_id: analytics authentication: service_account_key: | { "type": "service_account", "project_id": "my-project", ... }Or reference it from the environment or a secret manager (see Secrets):
authentication: service_account_key: ${gsm://bigquery-sa-key}Application Default Credentials
Section titled “Application Default Credentials”If running on GCP (GKE, Cloud Run, etc.) or with gcloud auth, omit authentication:
destination: name: bigquery_streaming_v2 config: project_id: my-project dataset_id: analyticsTable Naming
Section titled “Table Naming”When no destination_id is set, the table is named {table_prefix}{source}_{stream}, so _bizon_hubspot_contacts by default. This applies to all three variants.
- If the legacy unprefixed table (
hubspot_contacts) already exists, bizon keeps writing to it. table_prefix: ""disables the prefix.- An explicit
destination_idis used as-is and never prefixed. - Staging tables (
_temp,_incremental) take the resolved name as their base.
Schema Configuration
Section titled “Schema Configuration”Without unnest, every table gets bizon’s metadata columns: _source_record_id, _source_timestamp, _source_data, _bizon_extracted_at, _bizon_loaded_at and _bizon_id. They are all NULLABLE. Load jobs allow field addition and relaxation, so additive schema changes don’t need a migration.
Define schemas for structured loading with unnest: true. The table then holds exactly the columns in record_schema, and none of the metadata columns:
destination: name: bigquery_streaming_v2 config: project_id: my-project dataset_id: analytics unnest: true record_schemas: - destination_id: my-project.analytics.events record_schema: - name: event_id type: STRING mode: REQUIRED - name: event_type type: STRING mode: REQUIRED - name: user_id type: STRING mode: NULLABLE - name: payload type: JSON mode: NULLABLE - name: created_at type: TIMESTAMP mode: REQUIRED clustering_keys: - event_type - user_idColumn Types
Section titled “Column Types”| Type | Description |
|---|---|
STRING | Text |
INTEGER / INT64 | 64-bit integer |
FLOAT / FLOAT64 | 64-bit float |
BOOLEAN | True/false |
TIMESTAMP | Date and time |
DATE | Date only |
DATETIME | Date and time (no timezone) |
TIME | Time only |
JSON | JSON object |
BYTES | Binary data |
NUMERIC / BIGNUMERIC | Exact numeric |
GEOGRAPHY | Geographic data |
RECORD | Nested record |
Column Modes
Section titled “Column Modes”| Mode | Description |
|---|---|
NULLABLE | Can be null (default) |
REQUIRED | Cannot be null |
REPEATED | Array of values |
Multi-Table Routing
Section titled “Multi-Table Routing”Route records to different tables based on destination_id:
source: name: kafka stream: topic topics: - name: user-events destination_id: my-project.analytics.user_events - name: order-events destination_id: my-project.analytics.order_events
destination: name: bigquery_streaming_v2 config: project_id: my-project dataset_id: analytics unnest: true record_schemas: - destination_id: my-project.analytics.user_events record_schema: - name: user_id type: STRING mode: REQUIRED - name: action type: STRING mode: REQUIRED
- destination_id: my-project.analytics.order_events record_schema: - name: order_id type: STRING mode: REQUIRED - name: amount type: FLOAT64 mode: REQUIREDTime Partitioning
Section titled “Time Partitioning”All three variants take the same time_partitioning block:
| Field | Default | Description |
|---|---|---|
type | DAY | DAY, HOUR, MONTH or YEAR |
field | _bizon_loaded_at | Column to partition on. null selects ingestion-time partitioning |
A bare time_partitioning: DAY is still accepted and means {type: DAY}. Unknown keys are rejected.
The partition column must be a TIMESTAMP, DATE or DATETIME column of the table, and HOUR is not allowed on a DATE column. On bigquery a bad column fails config validation. On the streaming variants it only fails when bizon creates a new table, and otherwise logs a warning, since BigQuery keeps an existing table’s partitioning anyway.
With unnest: true, _bizon_loaded_at doesn’t exist in the table. If you don’t set field, bizon falls back to ingestion-time partitioning (_PARTITIONDATE) and logs it. To partition on your own column, name it explicitly:
destination: name: bigquery config: project_id: my-project dataset_id: analytics gcs_buffer_bucket: my-bucket time_partitioning: type: DAYdestination: name: bigquery_streaming_v2 config: project_id: my-project dataset_id: analytics unnest: true time_partitioning: type: DAY field: created_at record_schemas: - destination_id: my-project.analytics.events record_schema: - name: event_id type: STRING mode: REQUIRED - name: created_at type: TIMESTAMP mode: REQUIREDdestination: name: bigquery_streaming_v2 config: project_id: my-project dataset_id: analytics time_partitioning: type: DAY field: nullChanging Partitioning on an Existing Table
Section titled “Changing Partitioning on an Existing Table”BigQuery cannot repartition a table in place, and publishing into an existing table keeps that table’s spec. Before publishing, bizon compares the staging table’s partitioning with the destination table’s and logs a warning when they differ.
To fix a mismatched table, set enforce_partitioning: true (on bigquery and bigquery_streaming_v2):
- A full refresh drops the destination table and recreates it with the configured partitioning.
- An incremental run never drops the table. It warns and points to
bizon stream reset, which republishes the stream as a full refresh. See Sync Modes.
How Publishing Works
Section titled “How Publishing Works”Full refresh and incremental runs don’t write to the destination table directly. They stage rows, then publish once the run succeeds:
| Sync mode | Staging table | Publish |
|---|---|---|
full_refresh | {table}_temp | Replace the table |
incremental | {table}_incremental | Append to the table |
stream | none | Rows are written to the table directly |
On bigquery, publishing is a copy job: WRITE_TRUNCATE for a full refresh, WRITE_APPEND for incremental. Copy jobs are free and metadata-only. On the first incremental run, the copy creates the table with the staging table’s partitioning.
On bigquery_streaming_v2, publishing is a query:
- Full refresh with a partition column:
CREATE OR REPLACE TABLE ... PARTITION BY ... CLUSTER BY ... AS SELECT. - Full refresh with ingestion-time partitioning:
TRUNCATEthenINSERT. This is not atomic: the table is empty between the two statements. - Incremental: the table is created if missing, then an
INSERTby column name.
The staging table is deleted after publishing. On bigquery, a new full-refresh run also starts by dropping any _temp table left by a crashed run.
A failed write fails the run and nothing is published: a full refresh leaves the previous table intact. On an incremental run, rows already staged in _incremental are published by the next successful run.
bigquery_streaming has no staging table and always appends.
Clustering
Section titled “Clustering”Add clustering keys for better query performance:
record_schemas: - destination_id: my-project.analytics.events record_schema: - name: event_type type: STRING mode: REQUIRED - name: user_id type: STRING mode: NULLABLE clustering_keys: - event_type - user_idChoosing the Right Variant
Section titled “Choosing the Right Variant”┌─────────────────────────────────────────────────────────────┐│ Is latency critical? ││ (< 1 minute required) │└─────────────────────────────┬───────────────────────────────┘ │ ┌───────────────┴───────────────┐ │ │ Yes No │ │ ▼ ▼┌─────────────────────────────┐ ┌──────────────────────────┐│ Is throughput high? │ │ bigquery ││ (> 1000 records/sec) │ │ (GCS Load Jobs) │└──────────────┬──────────────┘ └──────────────────────────┘ │ ┌───────────┴───────────┐ │ │ Yes No │ │ ▼ ▼┌─────────────────┐ ┌─────────────────────┐│ bigquery_ │ │ bigquery_streaming ││ streaming_v2 │ │ (Legacy API) │└─────────────────┘ └─────────────────────┘Production Configuration
Section titled “Production Configuration”Complete production example:
name: kafka-to-bigquery
source: name: kafka stream: topic sync_mode: stream bootstrap_servers: kafka:9092 message_encoding: utf-8 topics: - name: events destination_id: my-project.analytics.events authentication: type: basic params: username: BIZON_ENV_KAFKA_USER password: BIZON_ENV_KAFKA_PASSWORD
destination: name: bigquery_streaming_v2 config: project_id: my-project dataset_id: analytics dataset_location: US buffer_size: 100 buffer_flush_timeout: 300 bq_max_rows_per_request: 5000 unnest: true time_partitioning: type: DAY field: timestamp record_schemas: - destination_id: my-project.analytics.events record_schema: - name: event_id type: STRING mode: REQUIRED - name: event_type type: STRING mode: REQUIRED - name: payload type: JSON mode: NULLABLE - name: timestamp type: TIMESTAMP mode: REQUIRED clustering_keys: - event_type authentication: service_account_key: BIZON_ENV_GCP_SERVICE_ACCOUNT
engine: backend: type: postgres config: host: db.example.com port: 5432 database: bizon schema: public username: bizon password: ${env://DB_PASSWORD}
runner: type: stream log_level: INFORun it with the stream runner:
bizon run config.yml --runner streamNext Steps
Section titled “Next Steps”- Kafka to BigQuery Tutorial - Complete streaming guide
- Kafka Source - Configure Kafka consumption
- Engine Configuration - Production backend setup
- bizon-rs - Native Kafka to BigQuery worker