Replicate to Databricks with Auto Loader¶
Auto Loader replicates to Databricks without the Spark connector notebook, so Databricks needs no connection back to the Stelo VM. Stelo Capture writes the rows as Parquet files to an Azure Data Lake Storage (ADLS) Gen2 container, Databricks Auto Loader loads the new files, and Stelo Capture merges them into the Delta tables through a serverless SQL warehouse. To compare the methods, see Choose how rows reach Databricks. This page covers what's specific to Auto Loader; the rest is on Set up a Databricks destination.
What you need¶
| Required | |
|---|---|
| Databricks | An Azure Databricks workspace with Unity Catalog. |
| Storage | An ADLS Gen2 storage account and container that the Stelo VM can write to and the workspace can read. |
| Compute | A serverless SQL warehouse, which runs the load and the merge. |
| Identities | A Microsoft Entra App registration, which writes the files, and a Databricks service principal, which runs the SQL. |
| Replication | Snapshot and incremental. The source needs a Capture Agent, also for snapshots. A snapshot uses the destination's Default Parameters. Baselines and snapshots of a table with sql_variant, spatial or destination-expression columns go through the ODBC connection instead. |
| Network | Outbound HTTPS (port 443) from the Stelo VM to the storage account and the workspace (see Firewall rules). Nothing connects in to the Stelo VM. |
How changes are applied¶
- The Replicator Service creates or empties the destination table through the ODBC connection, as the subscription's settings say.
- The Capture Agent writes each table's baseline and changes as Parquet files, in dated folders under
<directoryPath>/<schema>.schema/<table>/in the container. - The SQL warehouse, on the Capture Agent's request, loads the new files with Auto Loader into a streaming table
z__<table>, merges the latest version of each key into the destination table, and empties the streaming table.
The streaming tables stay in the destination schema unless you set stagingSchema (see
Parameters), so users of that schema see them.
The files stay in the container. Stelo Capture removes a table's files only when the table gets a new baseline, so
the container grows with every change. Add an Azure
lifecycle management rule that deletes
old files under directoryPath, and keep them for longer than a group can stay stopped.
Prepare Azure storage¶
Create the App registration¶
Stelo Capture signs in to the storage account as this application.
- In the Azure portal, create an App registration.
- Under Certificates & secrets, create a client secret, and choose its expiry. When it expires, replication to this destination stops: create a new one before then and change the stored secret.
- Note the Application (client) ID, the Directory (tenant) ID and the secret's Value, which is shown only once.
Create the storage account and container¶
- Create a Storage account with Azure Blob Storage or Azure Data Lake Storage as its primary service.
- Under Data management > Data protection, turn off soft delete for blobs and for containers.
-
Under Settings, run the Data Lake Gen2 upgrade, unless you turned on the hierarchical namespace when you created the account.
-
Create a container for the files.
- Give the App registration the role Storage Blob Data Contributor on the storage account.
Create the access connector¶
The access connector is the identity Databricks reads the storage with.
- In the Azure portal, create an Access Connector for Azure Databricks, and note its Resource ID.
-
On the storage account, under Access control (IAM), give the access connector these roles:
- Storage Account Contributor
- Storage Blob Data Contributor
- EventGrid EventSubscription Contributor
- Storage Queue Data Contributor
Prepare Databricks¶
First create the schema and get the credentials of the ODBC
connection. Skip the sections marked (Spark connector). The examples use mycatalog, myschema,
my_external_location and sqdr_principal (the service principal's application ID).
- Create a storage credential. In Catalog, under Credentials, create a Storage Credential with the access connector's Resource ID as its Access connector ID.
- Create an external location with that credential and the container's URL:
abfss://<container>@<storage account>.dfs.core.windows.net/. -
Create a serverless SQL warehouse, and note its JDBC URL on the Connection details tab.
-
Create a service principal with an OAuth secret, and give it CAN USE on the SQL warehouse (see Create the service principal).
-
Grant it the privileges in Grant the privileges, and let it read the files:
GRANT READ FILES ON EXTERNAL LOCATION `my_external_location` TO `sqdr_principal`;
Create the destination¶
- Store the two secrets as secrets in the Data Replicator Manager (DRM): the App registration's client secret and the service principal's OAuth secret.
- Create the Databricks destination with its ODBC connection (see Create the Databricks destination). The connection can use the same service principal. Verify tests only this connection.
-
In Default Parameters, choose the
classNamecom.starquest.sqdr.apply.databricks.AutoLoaderProcessorand fill in the parameters the DRM suggests:className=com.starquest.sqdr.apply.databricks.AutoLoaderProcessor accountUrl=https://mystorageaccount.blob.core.windows.net fileSystemName=mycontainer directoryPath=sqdr tenantId=<directory (tenant) ID> clientId=<application (client) ID> clientSecret=$$adls_client_secret$$ utc=false jdbcUrl=<JDBC URL of the SQL warehouse> jdbcClientId=<application ID of the service principal> jdbcClientSecret=$$databricks_oauth_secret$$
Parameters¶
| Parameter | What to enter |
|---|---|
accountUrl |
The storage account's URL, https://<storage account>.blob.core.windows.net. |
fileSystemName |
The container. |
directoryPath |
The folder in the container for the files. |
tenantId, clientId, clientSecret |
The App registration's tenant ID, client ID and secret. |
utc |
false writes timestamps as local time, true as UTC. |
jdbcUrl |
The SQL warehouse's JDBC URL. Without it, the files are written but nothing loads them into the tables. |
jdbcClientId, jdbcClientSecret |
The service principal's application ID and OAuth secret. |
stagingSchema |
Optional: a schema for the z__ streaming tables, to keep them out of the destination schema. The service principal needs the same privileges on it. |
maxThreads |
Optional: how many tables a group applies at the same time (default 5). Each one uses the SQL warehouse. |
Group settings¶
Follow Group settings for Databricks; there's no Spark connector to start. Every member needs a replication key: the merge fails without one.
Check the destination¶
After the first baseline or snapshot:
- Files. The container has a folder for the table under
directoryPath, with Parquet files. -
Rows. A table's row count matches 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.
If it fails¶
| Message | Cause and what to do |
|---|---|
Failed to ingest rows for: <table> |
The files were written, but the load or the merge failed in Databricks. Check the Capture Agent's Diagnostics for the cause: usually a missing privilege, a stopped or inaccessible SQL warehouse, or a member without a replication key. |
Failed to drop streaming table for: <table> |
A baseline couldn't reset the table's streaming table. Check the service principal's privileges on the schema. |
Authentication failed for the service principal (check tenantId, clientId and clientSecret) |
The App registration's values are wrong, or its client secret expired. |