Use Case: Round Trip Between Databricks and Nexadata
The quickest way to prove a Databricks connection end to end is a round trip: read a table from Databricks into Nexadata, run it through a Workflow, write the result back to Databricks, and check that the totals match. This use case walks through that round trip with Beverage Sales, a sample planning fact table that Nexadata provides, but any table of your own works the same way.
By the end, you will have:
-
A Nexadata dataset that reads from Databricks with a SQL statement
-
A Workflow that writes its output to a new Databricks table
-
Proof that every row arrived and the amounts tie to the cent
-
Proof that rerunning the Workflow does not duplicate rows
Part 1: Set Up Databricks
Section titled “Part 1: Set Up Databricks”This example uses one catalog with two schemas: one Nexadata reads from, and one it writes to. Your names can differ.
| Object | Purpose | Privileges for the service principal |
|---|---|---|
finance | Catalog | USE CATALOG |
finance.actuals | Source data, read by Nexadata | USE SCHEMA, SELECT |
finance.planning | Results, written by Nexadata | USE SCHEMA, SELECT, MODIFY, READ VOLUME, WRITE VOLUME, CREATE TABLE, CREATE VOLUME |
Splitting read and write this way keeps Nexadata’s access to your source data read-only. See Setting up a Databricks Connection for how to create the service principal and grant these privileges.
Step 1: Create the Catalog and Schemas
Section titled “Step 1: Create the Catalog and Schemas”In the Databricks SQL Editor, run:
CREATE CATALOG IF NOT EXISTS finance;CREATE SCHEMA IF NOT EXISTS finance.actuals;CREATE SCHEMA IF NOT EXISTS finance.planning;Step 2: Load the Source Table
Section titled “Step 2: Load the Source Table”-
Download beverage-sales-fact.csv (1.4 MB). It holds the Beverage Sales fact table, generated sample data for a beverage company: 28,800 rows with the columns
month,measures,product,market,scenario,pkg_type, anddata. -
In Catalog, open
finance→actuals, then click Create → Table. -
Upload
beverage-sales-fact.csvand name the tablebeverage_sales_raw. Click Create table. -
In the SQL Editor, copy the table and store the amount as an exact decimal:
CREATE OR REPLACE TABLE finance.actuals.beverage_sales ASSELECT month, measures, product, market, scenario, pkg_type, CAST(data AS DECIMAL(18,2)) AS dataFROM finance.actuals.beverage_sales_raw;
DROP TABLE finance.actuals.beverage_sales_raw;Step 3: Record the Source Totals
Section titled “Step 3: Record the Source Totals”SELECT COUNT(*) AS row_count, SUM(data) AS totalFROM finance.actuals.beverage_sales;For Beverage Sales, this returns 28,800 rows totalling 5,613,357.84. Keep these numbers; you will compare against them at the end.
Part 2: Read the Table into Nexadata
Section titled “Part 2: Read the Table into Nexadata”-
Create a Databricks connection using Service Principal. See Setting up a Databricks Connection.
-
Create a dataset from that connection. Choose your SQL Warehouse and enter this SQL Statement:
SELECT month, measures, product, market, scenario, pkg_type, dataFROM finance.actuals.beverage_sales- Click Submit. On Define Columns, you should see the seven columns above. Save the dataset.
See Using a Databricks Connection for the dataset options in detail.
Part 3: Write the Results Back to Databricks
Section titled “Part 3: Write the Results Back to Databricks”-
Create a Workflow that uses the dataset. See Creating Nexadata Workflows. For this round trip, the data can pass through unchanged; in practice, this is where your transformations and mappings go.
-
Add an output and select your Databricks connection. Set:
-
SQL Warehouse: The same warehouse as the dataset.
-
Target Table:
finance.planning.beverage_sales -
Write Mode: Upsert, with Business Key Columns
month,measures,product,market,scenario, andpkg_type. -
Create the table if it doesn’t exist: On, with
account usersas the Read Access Group so that others in your Databricks account can see the result.
-
-
Save the output and run the Workflow.
Part 4: Confirm the Round Trip
Section titled “Part 4: Confirm the Round Trip”Check the Totals
Section titled “Check the Totals”In the Databricks SQL Editor, run:
SELECT COUNT(*) AS row_count, SUM(data) AS totalFROM finance.planning.beverage_sales;The result should match the source totals from Part 1 exactly: 28,800 rows totalling 5,613,357.84. Matching to the cent confirms that every amount was written as an exact decimal.
Check the Run ID
Section titled “Check the Run ID”In Catalog, open finance → planning → beverage_sales. Alongside the seven source columns, the table has a nexadata_run_id column holding the ID of the Workflow run that wrote each row.
Run It Again
Section titled “Run It Again”Run the Workflow a second time, then repeat the totals query. The row count stays at 28,800: Upsert matched every row on the business key and updated it rather than inserting a duplicate. The nexadata_run_id on each row now holds the second run’s ID.
Where to Go Next
Section titled “Where to Go Next”Replace Beverage Sales with your own tables, add transformations and mappings to the Workflow, and write the results to the schemas your planning teams use. If anything in the round trip fails, see Troubleshooting the Databricks Connector.