Databricks v2
Provides integration with Databricks using the Databricks SQL Statement Execution API for parameterized queries, stored procedures, Delta table mutations, and polling triggers. The Node runs SQL on a Databricks SQL warehouse against a Unity Catalog catalog and schema.
Revision History
0.0.0.10 - Initial release.
Connection
Use the Connection to configure the Databricks workspace, SQL warehouse, Unity Catalog context, and credentials used by all methods.
| Property | Type | Description |
|---|---|---|
WorkspaceUrl |
String | The exact HTTPS workspace origin without an API path, for example, https://<workspace>.cloud.databricks.com. |
WarehouseId |
String | The ID of the SQL warehouse that executes statements. The principal must have CAN USE permission on the warehouse. |
Catalog |
String | The exact Unity Catalog catalog name. This is the default catalog for SQL statements and template discovery. |
Schema |
String | The exact name of an existing schema within Catalog. Templates list tables, views, and procedures from this schema. |
ProcedureResultSchemas |
String | Optional JSON that declares the result columns returned by stored procedures. See Stored procedure result schemas. |
AuthenticationType |
Enum | The authentication mode. OAuthClientCredentials (default) obtains and renews tokens by using a service principal's OAuth client credentials. AccessToken uses a bearer token that you supply and does not renew it. |
ClientId |
String | The OAuth client ID. Used with OAuthClientCredentials. |
ClientSecret |
Masked | The OAuth client secret. Used with OAuthClientCredentials. |
Scopes |
String | The space-delimited OAuth scopes assigned to the client. The default is sql unity-catalog. Used with OAuthClientCredentials. |
AccessToken |
Masked | The bearer token used with AccessToken authentication. You must replace this token before it expires. |
OAuthAccessToken |
Masked | The current OAuth token used with OAuthClientCredentials. Leave it empty; the Connection acquires and renews it automatically by using ClientId and ClientSecret. |
TimeoutSeconds |
Integer | The overall deadline in seconds for each SQL statement, including submission, completion, and result retrieval. The default is 300. |
Setup Notes
- Identify the Databricks workspace URL, the SQL warehouse ID, and the Unity Catalog catalog and schema that the Workflow will use.
- For
OAuthClientCredentials, create a Databricks service principal with an OAuth secret, and record its client ID and client secret. The client must be allowed the scopes entered inScopes, includingsqlandunity-catalog. - Grant the principal
CAN USEon the SQL warehouse, andUSE CATALOGandUSE SCHEMAon the configured catalog and schema. - Grant table privileges for the methods used in the Workflow.
Query,Listen, andListenChangesrequireSELECT.Insert,Update,Delete, andMergerequireMODIFY.StoredProcedurerequiresEXECUTEon the procedure. - Create a Databricks
Connectionin the Flowgear Console and enterWorkspaceUrl,WarehouseId,Catalog, andSchema. - Select the
AuthenticationType. ForOAuthClientCredentials, enterClientId,ClientSecret, andScopes. ForAccessToken, enter the token inAccessToken. - Test the Connection. The test confirms that the SQL warehouse and the configured schema are accessible. It does not create schemas.
If the OAuth token request is refused, for example because a requested scope is not allowed for the client, the method fails. Correct the credentials or the client's allowed scopes before running the Workflow again.
Methods
The Databricks Node exposes methods for running parameterized SQL, calling stored procedures, inserting, updating, deleting, and merging Delta table rows, and two trigger methods that poll for changes. Templates are generated from accessible tables, views, and procedures in the configured Catalog and Schema. Template names omit the configured catalog and schema, while the generated SQL and TableName values remain fully qualified. Refresh templates when a table is renamed, removed, or changed.
Query
Executes one parameterized SQL statement and streams the returned rows. Select Blank Query for a parameterized example, or select a table or view template to generate a query and Items schema for that object.
| Parameter | Type | Description |
|---|---|---|
Connection |
Connection | The Databricks Connection. |
Query |
String | One SQL statement. Use :Name markers for external values. Multiple statements are not supported. |
CustomParameters |
Object | Optional JSON scalar values keyed by marker name without the colon, for example, CustomerId for :CustomerId. |
| Return | Type | Description |
|---|---|---|
Items |
Array | The returned rows, emitted as objects with the provider column names. A query with no matching rows returns an empty result. |
Table and view templates include a RowLimit custom parameter with a default of 10, bound to LIMIT :RowLimit. Use aliases when a query returns duplicate column names.
StoredProcedure
Executes a Unity Catalog stored procedure by using a generated CALL statement and streams the returned rows. Select the template for the procedure to generate the statement and its CustomParameters.
| Parameter | Type | Description |
|---|---|---|
Connection |
Connection | The Databricks Connection. |
Query |
String | One CALL statement. Use :Name markers for external values. |
CustomParameters |
Object | Optional JSON scalar values keyed by marker name without the colon. |
| Return | Type | Description |
|---|---|---|
Items |
Array | The rows returned by the procedure. A procedure that returns no result returns an empty stream. |
Stored procedures require a Databricks SQL warehouse that supports Unity Catalog stored procedures, such as Databricks Runtime 17.0 or later. Selecting a template reads the procedure's parameters without executing it. Generated templates bind each input to markers named Input1, Input2, and so on, and label each value with the procedure's parameter name. Complex inputs are supplied as JSON strings, and binary inputs are supplied as base64 text.
Templates support IN parameters only. Procedures with OUT or INOUT parameters cannot be loaded as templates. Multiple result sets and output variables are not returned.
Insert
Inserts connected items into a managed or external Delta table.
| Parameter | Type | Description |
|---|---|---|
Connection |
Connection | The Databricks Connection. |
TableName |
String | The fully qualified table name selected by its template. |
Items |
Array | The rows to insert. Property names must match writable table columns exactly. Omitted fields use their column defaults; an explicit null is written as null. |
| Return | Type | Description |
|---|---|---|
Response |
Array | One response per input item, including Flowgear.IsSuccess, Flowgear.Message, Flowgear.Request, BatchItemCount, and the provider row counts such as num_affected_rows and num_inserted_rows. |
Insert groups up to 100 consecutive items with the same Properties into one statement, within a 1 MiB request limit. A change in item Properties starts a new batch. The row counts in each response are totals for the whole batch, repeated on every item in that batch. Use BatchItemCount to identify the batch size, and do not add the repeated totals together.
Update
Updates rows identified by exact key values. Only the supplied non-key fields are changed.
| Parameter | Type | Description |
|---|---|---|
Connection |
Connection | The Databricks Connection. |
TableName |
String | The fully qualified table name selected by its template. |
KeyFields |
String | Exact, comma-separated key column names used to identify rows. |
Items |
Array | The rows to update. Each item must contain a non-null value for every key field and at least one writable non-key field. |
| Return | Type | Description |
|---|---|---|
Response |
Array | One response per input item, including Flowgear.IsSuccess, Flowgear.Message, Flowgear.Request, and the provider row counts such as num_affected_rows. |
Delete
Deletes rows identified by exact key values.
| Parameter | Type | Description |
|---|---|---|
Connection |
Connection | The Databricks Connection. |
TableName |
String | The fully qualified table name selected by its template. |
KeyFields |
String | Exact, comma-separated key column names used to identify rows. |
Items |
Array | Items containing only the non-null key values of the rows to delete. |
| Return | Type | Description |
|---|---|---|
Response |
Array | One response per input item, including Flowgear.IsSuccess, Flowgear.Message, Flowgear.Request, and the provider row counts such as num_affected_rows. |
Merge
Updates the row that matches the supplied key values, or inserts a new row when no match exists.
| Parameter | Type | Description |
|---|---|---|
Connection |
Connection | The Databricks Connection. |
TableName |
String | The fully qualified table name selected by its template. |
KeyFields |
String | Exact, comma-separated key column names used to match rows. |
Items |
Array | The rows to merge. Each item must contain a non-null value for every key field. Supplied writable non-key fields are updated on a match and all supplied fields are inserted otherwise. |
| Return | Type | Description |
|---|---|---|
Response |
Array | One response per input item, including Flowgear.IsSuccess, Flowgear.Message, Flowgear.Request, and the provider row counts such as num_affected_rows, num_updated_rows, num_deleted_rows, and num_inserted_rows. |
Listen
A trigger method that polls a query and emits the current result snapshot. Use Listen to watch the result of a query, or use ListenChanges to receive individual row changes from a Delta table. Select Blank Listen or a table or view template to generate a query that selects all declared columns.
| Parameter | Type | Description |
|---|---|---|
Connection |
Connection | The Databricks Connection. |
WatchQuery |
String | A SELECT or common table expression query that can be used as a derived table. Omit the trailing semicolon. |
CustomParameters |
Object | Optional JSON scalar values bound to :Name markers in WatchQuery. |
PollIntervalSeconds |
Integer | The delay in seconds between completed polls. The default is 30. |
FireOn |
Enum | Select RowsChanged (default) to emit only when the result changes, or RowsReturned to also emit every non-empty result. |
MaxSnapshotRows |
Integer | The maximum number of rows in one snapshot. The default is 10000. A larger result fails without emitting partial data. |
| Return | Type | Description |
|---|---|---|
Event |
Array | The emitted events. Each event includes DetectedAtUtc, RowCount, ResultHash, and the complete current result in Rows. |
With RowsChanged, the first snapshot is recorded as a baseline without emitting an event. Later events are emitted when the result changes, including when it becomes empty. With RowsReturned, every non-empty snapshot is emitted, including the first. Comparison ignores row order and Property order, but detects changes to values, nulls, duplicate rows, and the order of nested arrays.
Polling can miss a change that is made and reversed between polls. Keep WatchQuery narrow for large tables, because each snapshot is read in full for comparison. When you replace a template query with a different column selection, refresh the return schema.
ListenChanges
A trigger method that polls the Change Data Feed of a Delta table and emits one event per table commit that contains inserted, updated, or deleted rows.
| Parameter | Type | Description |
|---|---|---|
Connection |
Connection | The Databricks Connection. |
TableName |
String | The fully qualified Delta table selected by its template. The table must be in the configured Catalog and Schema and have an accessible Change Data Feed. |
StartingVersion |
Integer | Optional inclusive table version to start from. Omit it to listen only for commits made after the listener starts. Supply a saved NextVersion to resume. |
PollIntervalSeconds |
Integer | The delay in seconds between checks when no new commit exists. The default is 30. |
MaxCommitRows |
Integer | The maximum number of change rows in one commit. The default is 10000. A larger commit stops the listener without emitting partial data. |
| Return | Type | Description |
|---|---|---|
Event |
Array | The emitted events. Each event includes DetectedAtUtc, TableName, Version, NextVersion, RowCount, and Rows. |
Each row in Rows contains the table's declared columns plus _change_type, _commit_version, and _commit_timestamp. _change_type is insert, delete, update_preimage, or update_postimage. An update produces separate before and after rows; their order within a commit does not guarantee that they are paired. Commits without change rows advance the listener without emitting an event.
The listener keeps its position in memory only. When the Workflow restarts without StartingVersion, it starts from the current table version and does not read changes made while it was stopped. To resume, store NextVersion after the Workflow has fully processed an event and supply it as StartingVersion on the next start. There is no built-in checkpoint or acknowledgement, so a retry can process the same version again.
The listener stops instead of skipping data when the Change Data Feed is disabled or unavailable, a requested version is no longer retained, the table identity or schema changes, or a commit exceeds MaxCommitRows. Refresh the template after a schema change. Views and non-Delta tables are not available as ListenChanges templates.
Usage Notes
- Use
:Namemarkers withCustomParametersinstead of inserting external values into SQL text.CustomParametersaccepts JSON scalar values only. To pass a complex value, supply it as a JSON string and convert it in SQL, for example, withfrom_json. Insert,Update,Delete, andMergetarget managed or external Delta tables. Table, column, andKeyFieldsnames are matched exactly and are not trimmed. Do not add spaces around the commas inKeyFields.- Templates suggest key fields from informational primary-key constraints. When no primary key is available, the template suggests the first eligible column. Databricks does not enforce these constraints, so duplicate target keys can affect several rows. Review the suggested key before use.
Deleteaccepts key fields only. Remove all non-key Properties from each input item.- Generated and identity columns can be used as
UpdateandDeletekeys, but cannot be assigned or supplied toInsertorMerge. - Each item must contain at least one known column. An empty connected stream performs no writes.
Update,Delete, andMergeexecute one statement per item. For all four mutation methods, a failure in the first statement or batch stops the method. For later items, input validation and provider failures produce failed responses with the error inFlowgear.Message, and processing continues. Authentication, connection, and service failures stop the method.- Successful statements remain committed when a later statement fails. If the outcome of a write cannot be confirmed because of a transport failure, the method fails and the statement is not resubmitted.
- Query results are returned inline and are limited by Databricks to 25 MiB. Oversized or truncated results fail.
- Multi-statement scripts are not supported. Use a separate Node invocation for each statement.
Data types
- Integers, decimals, finite floating-point numbers, booleans, ISO dates and timestamps, and base64-encoded binary values are supported.
- Decimals with a precision greater than 28 are returned as strings to preserve up to 38 digits.
TIMESTAMPvalues retain their UTC offset, andTIMESTAMP_NTZvalues remain without a time zone.- Arrays of strings and integers are represented as CSV strings. Quote values that contain commas, quotes, or line breaks, and escape a quote by doubling it. Empty text represents an empty array, and an unquoted
\Nrepresents a null element. STRUCTcolumns are represented as objects, and arrays ofSTRUCTas arrays of objects.MAP<STRING,STRING>columns are represented as arrays ofKeyandValueobjects.- When a table has a single
STRUCTcolumn, its child fields appear at the root of each item. VARIANT, geospatial, and interval types are not supported. Queries and tables that use them fail instead of omitting fields.
Stored procedure result schemas
Databricks procedure metadata does not describe the columns a procedure returns. Without a declaration, a StoredProcedure template loads with a blank Items schema. You can then use schema inference to populate it, which runs the procedure with the supplied inputs. Use a test environment and suitable test data when you infer a schema.
To declare result columns, set ProcedureResultSchemas on the Connection to a JSON object. Each key is the exact catalog.schema.specific_name identity shown in the template description, which can differ from the procedure's CALL name. Each value maps a result column name to its Databricks SQL type. Declare result-set columns only, not OUT parameters.
{
"workspace.default.report_identity": {
"label": "STRING"
}
}
Update the declaration when the procedure's results change. Invalid JSON or unsupported SQL types prevent the template from loading.
Examples
Query with external values
Set Query to:
SELECT customer_id, company_name
FROM customers
WHERE customer_id = :CustomerId
LIMIT 10
Set CustomParameters to:
{
"CustomerId": 123
}
Resume ListenChanges after a restart
Store NextVersion from each event after the Workflow has processed all of its Rows, for example, in a database table that persists across Workflow restarts. When the Workflow starts again, supply the stored value as StartingVersion. The listener replays changes from that version if Databricks still retains them.