Set up a Databricks destination¶
A Databricks destination is written in two ways. The Replicator Service connects to the workspace through the
Databricks ODBC driver to create and change the destination tables (Delta tables). The rows (baselines, snapshots and
incremental changes) don't use that connection: by default, the Stelo Capture Apply extension for Databricks
(ApplyPullProcessor) stages them in the Stelo Capture Db2 database, and the Spark connector
(SqdrSparkApply.jar), a Scala notebook on your Databricks compute, pulls them over JDBC and merges them into the Delta
tables.
Choose how rows reach Databricks¶
The main decision is whether Databricks may connect back to the Stelo VM. The Spark connector is a notebook that needs that connection, to the Stelo Capture Db2. Zerobus and Auto Loader need no notebook and no connection back: the Stelo VM only connects out.
| Spark connector (default) | Zerobus (beta) | Auto Loader | |
|---|---|---|---|
| How rows travel | A notebook pulls them from the Stelo VM | Streamed directly into Databricks | Parquet files in your Azure storage |
| Connection from Databricks to the Stelo VM | Required (Db2 port) | None | None |
| Snapshot and incremental replication | Yes | Yes | Yes |
| Runs in Databricks | A cluster with the notebook | A serverless SQL warehouse | A serverless SQL warehouse |
| You also set up | Libraries, a notebook or job, and the network route | A service principal | A storage account, an App registration, an external location and a service principal |
All three use the same destination, with the ODBC connection that creates the tables; the method is set by the Apply extension in its Default Parameters. The steps below cover the Spark connector and say which ones also apply to the other two.
Supported configurations¶
| Supported | |
|---|---|
| Databricks | Azure Databricks workspaces, with or without Unity Catalog. Unity Catalog needs the Premium pricing tier. For Databricks on another cloud, ask Stelo Support. |
| Compute for the Spark connector | A Databricks cluster (all-purpose or job compute). SqdrSparkApply.jar is built for Spark 4 and Scala 2.13 (Databricks Runtime 17.3 LTS); SqdrSparkApply3.jar for Spark 3.5 and Scala 2.13 (Databricks Runtime 16.4 LTS with Scala 2.13). For other runtimes, ask Stelo Support. |
| Driver on the Stelo VM | Databricks ODBC Driver or Simba Spark ODBC Driver. |
| SQDR | On the same server, with the Stelo Capture Db2 for LUW database SQDRC as the control database (the default installation, and the SQDR container). The Spark connector connects to that Db2 with JDBC: to the control database and to every staging database, on the same host and port. |
| Snapshot replication | Yes, with each method. The rows go through the source's Capture Agent, so the source needs one (see ODBC and Java connectors). |
| Incremental replication | Yes, with each method. |
| Apply method | Always Merge: each table's changes are merged into the Delta table by the replication key (see How changes are applied). |
| Authentication | ODBC connection: a personal access token, or OAuth with a Databricks service principal (client ID and secret). Spark connector to Db2: the Stelo Capture Db2 user and its password. |
| Encryption | ODBC connection: always (TLS on port 443; the templates set SSL=1). Spark connector to Db2: optional, see TLS to the Stelo Capture Db2. |
Docker
The SQDR container includes both ODBC drivers (see ODBC drivers in the container).
How changes are applied¶
With the Spark connector, who does what explains the privileges and network access below. For the other methods, see Auto Loader and Zerobus.
- The Replicator Service (ODBC connection) creates the destination tables (
CREATE OR REPLACE TABLE) and changes them when a source table changes (ALTER TABLE). It creates no indexes. - The Capture Agent stages the rows: for incremental changes, the Apply extension records each batch of a table as a piece of work in the agent's staging database; for a baseline or snapshot, the agent copies the source rows into temporary staging tables (see Databricks baselines).
- The Spark connector (the notebook) polls the control database
SQDRCfor the incremental groups to your destination and starts one worker per Capture Agent whose source replicates to it. Each worker polls the agent's staging database for work, creates a view over the staged rows there, reads it over JDBC, and applies the rows: baselines are inserted; changes are written to a work table4711<table>in the destination schema and merged into the destination table on the replication key. It reports its progress back to the staging database.
The Spark connector runs in your workspace, under the identity that runs the notebook, on your compute. It is the only thing in Databricks that connects to the Stelo VM (the server where SQDR runs).
Firewall rules on the Stelo VM¶
| From | To | Port | Why |
|---|---|---|---|
| The Stelo VM | The workspace host (for example adb-1234567276565967.7.azuredatabricks.net) |
443 | The Replicator Service's ODBC connection. |
| The Databricks compute | The Stelo VM's Db2 | 50000 (the Db2 port; with TLS, the Db2 TLS port) | Spark connector only: it reads the staged rows. |
| The Stelo VM | The Zerobus endpoint (<workspace ID>.zerobus.<region>.azuredatabricks.net) |
443 | Zerobus only: streams the rows. |
| The Stelo VM | The storage account | 443 | Auto Loader only: writes the files. |
Docker
On the SQDR container, the Db2 port is the one published as EXPOSE_CONTROL_DB_PORTS (see
.env settings).
Prepare Databricks¶
The examples use the placeholders mycatalog, myschema and sqdr_principal (the user or service principal SQDR
uses). In SQL, name a user by the email address and a service principal by its application ID, both in backticks
(`[email protected]`). Run the SQL in a SQL notebook or the workspace's SQL editor.
Every method needs the schema and the credentials of the ODBC connection. The sections marked (Spark connector) apply only to that method; for the others, continue on the Zerobus or Auto Loader page.
Create the compute (Spark connector)¶
Create a cluster for the Spark connector with Databricks Runtime 17.3 LTS (for SqdrSparkApply.jar), or
16.4 LTS with Scala 2.13 (for SqdrSparkApply3.jar). Both libraries are built for Scala 2.13: a 16.4 LTS cluster
with Scala 2.12 can't run the Spark connector. For other runtimes, ask Stelo Support. With Unity Catalog, choose the
access mode:
- Dedicated (formerly single user): the simpler choice. The cluster's assigned user or group runs the notebook.
When the libraries are installed, it gets
READ VOLUMEon the volume that holds them. - Standard (formerly shared): needs more setup; see Standard access mode.
Create the schema¶
Create the schema for the replicated tables, if it doesn't exist, in a Unity Catalog catalog you choose (to create
one, CREATE CATALOG IF NOT EXISTS mycatalog;, which needs CREATE CATALOG on the metastore). With Unity Catalog:
CREATE SCHEMA IF NOT EXISTS mycatalog.myschema;
Without Unity Catalog, leave out the catalog (CREATE SCHEMA IF NOT EXISTS myschema;).
Get the credentials¶
The Replicator Service signs in to Databricks in one of two ways:
- Personal access token: create a token for the Databricks user SQDR connects as (see Microsoft: Azure Databricks personal access tokens), and give that user CAN ATTACH TO on the cluster or CAN USE on the SQL warehouse the destination connects to. You enter the token as the destination's password, which SQDR stores encrypted; no secret needed.
- OAuth service principal: create the service principal and its OAuth secret (see Create the service
principal), and note its client ID and the secret. The secret goes into the
connection string, so store it as a secret in the Data Replicator Manager (DRM) when you
create the destination, and refer to it as
$$name$$.
Tokens and OAuth secrets expire: create a new one before then, and change it in the destination (or its secret).
Grant the privileges¶
Two identities need access to the schema: the one the Replicator Service connects as (the token's owner, or the service principal), which creates the tables, and the one that runs the Spark connector notebook (you, or the job's Run as identity), which fills them. With Unity Catalog:
GRANT USE CATALOG ON CATALOG mycatalog TO `sqdr_principal`;
GRANT USE SCHEMA, CREATE TABLE, SELECT, MODIFY ON SCHEMA mycatalog.myschema TO `sqdr_principal`;
Grant them to both identities, or use one identity for both. See Why these
privileges. With Zerobus or Auto Loader there's no notebook: grant them to the
service principal that runs the SQL (Auto Loader also needs READ FILES; see its page).
Open the network (Spark connector)¶
The compute must resolve and reach the Stelo VM: usually a VPN or private network link between the workspace's network and the Stelo VM, and a firewall rule for the Db2 port. See also Ports.
Store the Db2 password in a secret (Spark connector)¶
The Spark connector logs in to the Stelo Capture Db2 with the password of the Stelo Capture Db2 user: the Windows
account entered when Stelo Capture was installed (get the password from whoever installs Stelo Capture; see Install Db2
for LUW). Keep it in a Databricks secret scope, not in the notebook. With
the Databricks CLI (version 0.205 or later; see Microsoft: Install or update the Databricks
CLI), signed in to the workspace (for example
databricks auth login --host https://adb-1234567276565967.7.azuredatabricks.net):
databricks secrets create-scope sqdr
databricks secrets put-secret sqdr db2-password
put-secret prompts for the password. The notebook in Run the Spark connector reads the scope sqdr and
the key db2-password; if you use other names, change them there too.
The scope's creator has MANAGE on it, which includes reading. If the notebook runs as another identity (for example a job's Run as service principal), give that identity READ:
databricks secrets put-acl sqdr <principal> READ
<principal> is a user's email address, a service principal's application ID, or a group name. To keep the password
in Azure Key Vault instead, see Keep the Db2 password in Azure Key Vault.
Create the destination¶
Once SQDR is installed: install the Spark connector's libraries on the compute, create the destination in the DRM, and start the Spark connector. With Zerobus or Auto Loader, only create the destination, with the parameters from the Zerobus or Auto Loader page.
Install the libraries on the compute (Spark connector)¶
SqdrSparkApply.jar comes from the Stelo Capture Tools folder, so do this once Stelo Capture is installed. Besides
mycatalog and myschema, the examples use notebook_identity: the identity that runs the notebook (on Dedicated
compute, the cluster's assigned user or group; for a job, its Run as identity), named as in the other grants (a
user by email address, a service principal by application ID, a group by name, in backticks).
The Spark connector needs three JAR files on the compute:
| File | Where to find it |
|---|---|
SqdrSparkApply.jar, or SqdrSparkApply3.jar for Databricks Runtime 16.4 LTS |
The Stelo Capture Tools folder (C:\Program Files\StarQuest\sqdrplus\Tools on Windows) |
db2jcc4.jar and db2jcc_license_cu.jar (the IBM Db2 JDBC driver) |
The Db2 java folder (C:\Program Files\IBM\SQLLIB\java on Windows) |
With Unity Catalog, keep the files in a Unity Catalog volume:
-
Create the volume (this needs
CREATE VOLUMEon the schema, which its owner has), and letnotebook_identityread it (on Standard compute, see Standard access mode). That identity also needsUSE CATALOGandUSE SCHEMA(see Grant the privileges).CREATE VOLUME IF NOT EXISTS mycatalog.myschema.sqdr_libs; GRANT READ VOLUME ON VOLUME mycatalog.myschema.sqdr_libs TO `notebook_identity`; -
Upload the files to the volume.
- Standard access mode only: allowlist the volume and grant
SELECT ON ANY FILE; see Standard access mode. - Install them on the cluster's Libraries tab, with the Library Source Volumes, one file at a time
(for example
/Volumes/mycatalog/myschema/sqdr_libs/SqdrSparkApply.jar). - Restart the cluster.
See Microsoft: Install libraries from a volume. Without Unity Catalog, see Install the libraries without Unity Catalog.
Use the SqdrSparkApply.jar of the Stelo Capture version you run: after upgrading Stelo Capture, replace the library
and restart the cluster.
Create the Databricks destination¶
-
Install the ODBC driver on the Stelo VM: the Databricks ODBC Driver from Databricks.
Docker
The SQDR container already has it.
-
Get the connection details of a cluster or SQL warehouse of the workspace: the Server hostname and HTTP path, on the cluster's JDBC/ODBC tab (under Advanced options) or the SQL warehouse's Connection details tab. The ODBC connection carries no rows, so any compute of the workspace will do.
- With the OAuth template, first store the service principal's OAuth secret as a secret (see Get the credentials).
- Name (see Create a destination): choose the DBMS Type Databricks.
-
Connection: choose ODBC Driver, the Databricks driver and a Template:
Template Authentication Method Apache Spark/Databricks - user and password or access token (Remote Credentials) Remote Credentials: User ID tokenand the personal access token as the Password.Databricks - OAuth service principal (Authentication Method: Connection String) Connection String (driver-specific): the connection string holds the login; the Client secret is a secret reference ( $$name$$).What the templates set: More about the connection.
-
Authentication: the method from the table. Click Verify.
- Tick Advanced and check:
- Default Parameters:
className=com.starquest.sqdr.apply.ApplyPullProcessor, suggested for Databricks destinations. The Apply extension has no other parameters; its settings are in the notebook. For the other methods, enter the parameters for Zerobus or Auto Loader instead. - Database: the Unity Catalog catalog (
mycatalog). - Object Schema: the Databricks schema (
myschema). The default is the user ID (tokenwith the token template), which isn't a schema.
- Default Parameters:
Test the connection. Verify tests only the ODBC connection. The Spark connector's connection to the Stelo Capture Db2 is tested when you start the notebook (see Run the Spark connector).
Run the Spark connector¶
The Spark connector is a Scala notebook on the cluster that calls ApplyJdbc.apply. One notebook serves one
destination, with all its incremental groups and Capture Agents.
- Check that the Databricks secret
sqdr/db2-passwordread by the code below exists (see Store the Db2 password in a secret), and that the identity that runs the notebook has READ on the scope (its creator has it already). - Create a notebook with the language Scala, attached to the cluster with the libraries.
-
Paste this code and replace the values:
import com.starquest.sqdr.spark.scala.ApplyJdbc val jdbcHostname = "sqdr-host.example.com" // the Stelo VM, as Databricks reaches it val jdbcUsername = "sqdr" // the Stelo Capture Db2 user val jdbcPassword = dbutils.secrets.get(scope = "sqdr", key = "db2-password") val destinationName = "DATABRICKS_DEST" // the destination's name in the Data Replicator Manager ApplyJdbc.apply(spark, destinationName, jdbcUsername, jdbcPassword, jdbcHostname)The user is the Db2 user Stelo Capture connects as (entered during the Stelo Capture installation;
sqdrin the SQDR container). It must be able to create views in the staging databases.All parameters, and TLS for this connection: Parameters of ApplyJdbc.apply and TLS to the Stelo Capture Db2.
-
Click Run all. The output starts with
SqdrSparkApply Version=and the JAR file's version. - To keep it running, run the notebook as a Databricks job (see Microsoft: Create and run jobs). By default it runs until it's stopped; to run it on a schedule, see Parameters of ApplyJdbc.apply.
Group settings for Databricks¶
Start the Spark connector (see Run the Spark connector) before you create the incremental groups and subscriptions to this destination. Create the incremental group as usual (see Group properties):
- The group's Parameters get
className=com.starquest.sqdr.apply.ApplyPullProcessorfrom the destination (see Source/Destination). - Row Limit (on the group's Apply card): Stelo recommends a much larger value than the default, for example 2000000, so that each merge in Databricks handles more rows. See Apply.
- The members' loader is Automatic (see Baseline Replication Options): the Capture Agent stages baselines and the Spark connector loads them. The Capture Agent properties for Databricks baselines are in Databricks baselines.
- Every member needs a replication key (a primary key, a unique index, or the RRN or ROWID; see The RRN or ROWID column): the Spark connector merges by it.
- Databricks keeps table and column names in lowercase. With Fold case of identifiers per destination default on, SQDR uses lowercase names (see Mapping Options).
With Zerobus or Auto Loader there's no Spark connector to start or wait for: the Capture Agent loads the baselines itself. The group takes that method's parameters from the destination; the replication key and lowercase names apply the same way.
Check the destination¶
These checks are for the Spark connector; for the other methods, see Zerobus or Auto Loader. After the incremental group's first baseline (for snapshots, after the first run):
-
Spark connector status. In the SQDR Control Center, the Summary tab of each Capture Agent that replicates to the destination shows the connector (see Summary tab). While it's Active, Last Update changes each time it polls for work; on Failed, look at the notebook's output. If the cluster stops without ending the notebook, the status stays Active with an old Last Update: check that time.
-
Group status. On the Groups page, the group shows Actively monitoring and applying change data (see Group status). Baselines wait for the notebook, which loads them.
-
Rows at the destination. Compare a table's row count with the source:
SELECT COUNT(*) FROM mycatalog.myschema.mytable; -
Changes. Change a row at the source and check that it arrives after the group's next poll and the Spark connector's next poll (
pollInterval).
Data types¶
The Replicator Service maps the source columns to Databricks types; see
Per-database notes. For Databricks, STRING and BINARY have no length,
and the destination table is created with CREATE OR REPLACE. Spatial columns arrive as binary values (see
Spatial and hierarchyid columns).
Limitations¶
- The Spark connector must reach the Stelo Capture Db2. It reads the control database and every staging database
through one host and port, so they must be on the same Db2 instance, and the control database must be the Stelo
Capture Db2 database
SQDRC. - A replication key is required. A member without one fails with "Subscription for table is defined without any Primary Key". See Tables without a usable key.
- Interrupted baselines start over: checkpoint/restart doesn't apply to Databricks destinations (see Checkpoint/Restart), and parallel baselines aren't available.
- No derived columns (see Derived columns) and no indexes at the destination.
- Changes wait for the notebook. While the Spark connector isn't running, nothing is applied: the changes stay staged, and the group's requests wait for it.
Troubleshooting¶
Problems and messages, with their causes and fixes, are in Troubleshooting › Cloud and streaming destinations.