Skip to content

Set up a Google BigQuery destination

A BigQuery destination is written in two ways. The Replicator Service connects through the Simba ODBC Driver for Google BigQuery to create and change the destination tables, and to map columns when a subscription uses an existing table. The rows (baselines, snapshots and incremental changes) are written by the Stelo Capture Apply extension for BigQuery (BigQueryApplyProcessor) through BigQuery's own interfaces. Both sign in as a Google Cloud service account with a JSON key file.

Supported configurations

Supported
BigQuery Google BigQuery datasets in a Google Cloud project.
Driver on the Stelo VM Simba ODBC Driver for Google BigQuery (64-bit).
SQDR On the same server, so that both can read the key file, with the Stelo Capture Db2 for LUW database SQDRC as the control database (the default installation, and the SQDR container). For another control database, ask Stelo Support.
Snapshot replication Yes. The rows are streamed through the source's Capture Agent, so the source needs one (see ODBC and Java connectors).
Incremental replication Yes, through the BigQueryApplyProcessor Apply extension of Stelo Capture.
Apply method Always Merge: the Apply extension writes each table's changes into a staging table and runs one MERGE (see How changes are applied).
Authentication A service account with a JSON key file.
Encryption Always: the driver and the Apply extension connect to Google Cloud over HTTPS (port 443).

Docker

The SQDR container includes the Simba ODBC Driver for Google BigQuery (see ODBC drivers in the container).

How changes are applied

What SQDR runs in BigQuery explains the roles below.

  • The Replicator Service (ODBC connection) creates the destination tables and changes them when a source table changes (ALTER TABLE). It creates no indexes. BigQuery runs each statement on its own: the Replicator Service uses no transactions with it.
  • The Apply extension writes the rows with the BigQuery Storage Write API. For incremental changes, it first creates a staging table for the table's changes, named sq followed by the group's ID, a time stamp, and the destination schema and table name, in the destination dataset (or the dataset named by mergeSchema). The staging table expires after 12 hours (expirationHours). It then runs a MERGE query job that applies the last change of each row to the destination table, matched on the replication key. A truncate of the source table is applied with TRUNCATE TABLE.
  • When Stelo Capture starts the Apply extension for a project, it cancels its own MERGE jobs still pending or running from before.

Firewall rules on the Stelo VM

The Stelo VM needs outbound HTTPS (port 443) to Google Cloud's APIs (*.googleapis.com), for the ODBC driver and the Apply extension.

Prepare BigQuery

The examples use the placeholders myproject (the project ID), mydataset and sqdr (the service account).

1. Choose the project and create the dataset

Note the project ID. Create the dataset for the replicated tables, in the location you need:

CREATE SCHEMA IF NOT EXISTS `myproject.mydataset` OPTIONS (location = 'US');

2. Create the service account and grant the roles

Create a service account (for example sqdr; its e-mail address is then sqdr@myproject.iam.gserviceaccount.com) and grant it two roles on the project:

gcloud iam service-accounts create sqdr --project=myproject
gcloud projects add-iam-policy-binding myproject \
  --member="serviceAccount:sqdr@myproject.iam.gserviceaccount.com" --role="roles/bigquery.jobUser"
gcloud projects add-iam-policy-binding myproject \
  --member="serviceAccount:sqdr@myproject.iam.gserviceaccount.com" --role="roles/bigquery.dataEditor"

What each role is for: see Roles.

3. Create the JSON key file

  1. Create a JSON key for the service account (its Keys tab); the browser downloads the key file.
  2. Copy the file to the Stelo VM. Stelo recommends a gbq folder in the Stelo Capture data folder, C:\ProgramData\StarQuest\sqdrplus\gbq\.

    Docker

    In the SQDR container, use /var/sqdrplus/gbq/, which is on the sqplus-config volume and so survives a new container (see Volumes).

The Replicator Service and Stelo Capture both read the file, so both services' accounts need read access to it. Anyone who can read it can sign in as the service account: allow no one else. Service account keys don't expire unless your organization's policy sets an expiry; if it does, create a new key before then and copy it over the old file.

Create the destination

  1. Install the ODBC driver on the Stelo VM: the Simba ODBC Driver for Google BigQuery, 64-bit.

    Docker

    The SQDR container already has it.

  2. Name (see Create a destination): choose the DBMS Type BigQuery.

  3. Connection: choose ODBC Driver, the Simba driver and the Template "Google BigQuery; EnableSession=1 required for SQDR". Fill in:

    Field Keyword What to enter
    Project ID Catalog The project ID (myproject).
    Service account e-mail Email The service account's e-mail address.
    Key file path KeyFilePath The full path of the JSON key file on the Stelo VM, for example C:\ProgramData\StarQuest\sqdrplus\gbq\mykey.json.

    The template also sets OAuthMechanism=0 (sign in with a service account key) and EnableSession=1, which SQDR requires.

    Docker

    In the SQDR container, the key file path is a path in the container, for example /var/sqdrplus/gbq/mykey.json.

  4. Authentication: choose Connection String (driver-specific): the e-mail and key file in the connection string are the login. Click Verify (see Testing the connection and Test the destination).

  5. Tick Advanced and check:
    • Default Parameters: className=com.starquest.sqdr.gbq.apply.BigQueryApplyProcessor, with keyFilePath and project taken from the connection string's KeyFilePath and Catalog. On Windows, write the path with double backslashes (C:\\ProgramData\\StarQuest\\sqdrplus\\gbq\\mykey.json). See Default Parameters.
    • Database: the project ID.
    • Object Schema: the dataset (mydataset).
    • Create Table: optionally, a clause appended to the CREATE TABLE statements, for example BigQuery table options (see Defaults).

A BigQuery destination created by SQDR 6.x uses Use Integrated Security, and keeps working after the upgrade.

Group settings for BigQuery

Create the incremental group as usual (see Group properties). Its Parameters get the destination's Default Parameters (see Source/Destination); to change how the Apply extension works for the group, add parameters there (see Apply extension parameters).

DML Replication is always Merge. Members use the Automatic loader (see Baseline Replication Options): the Apply extension streams baselines too.

Check the destination

After the incremental group's first baseline (for snapshots, after the first run):

  1. Group status. On the Groups page, the group shows Actively monitoring and applying change data (see Group status). If a run fails with "Key File not found" or "Unable to authenticate using" and the path, the Apply extension can't read the key file named by keyFilePath: check the path, its double backslashes on Windows, and the file's permissions.
  2. Rows at the destination. Compare a table's row count with the source:

    SELECT COUNT(*) FROM `myproject.mydataset.mytable`;
    
  3. Changes. Change a row at the source. After the group's next poll (the Poll Interval; see Scheduling), the change is in the table.

Data types

The Replicator Service maps the source columns to BigQuery types; see Per-database notes. For BigQuery, NUMERIC and BIGNUMERIC precision depends on the scale, and MySQL datetime maps to TIMESTAMP. Spatial columns: see Spatial and hierarchyid columns.

Limitations

  • LOB values are cut at maxBlobLength and maxClobLength (see Apply extension parameters).
  • Table names are case-sensitive in BigQuery: write them in SQDR exactly as they are in BigQuery. For lowercase table names, clear Fold case of identifiers per destination default in the subscription's Mapping Options and enter the names in lowercase.
  • No derived columns (see Derived columns) and no indexes at the destination.

Troubleshooting

Problems and messages, with their causes and fixes, are in Troubleshooting › Cloud and streaming destinations.