Introducing Onehouse Autopilot to run your data platform for you. Check out the demos

Write once, query anywhere with Onehouse OneSync

Write once, query anywhere. A single orders table in S3, registered by Onehouse OneSync in AWS Glue and in Databricks Unity Catalog; Amazon Athena and Databricks both read it and return the same revenue.

TL;DR

Analysts on Amazon Athena and data scientists on Databricks often read different copies of the same table, kept in step by a nightly copy job, so the numbers drift. Both engines can read the same files in S3; the work is registering the table in each engine's catalog and keeping both up to date. In Onehouse we connected two catalogs, AWS Glue for Athena and Databricks Unity Catalog for Databricks, and added one Metadata sync table service on the table. The same query returned 200 orders and 23,208.47 in revenue on both engines. Then a load job added five orders: Athena showed 205 orders and 23,843.34 about a minute after the job finished, and Databricks a few minutes later, with no copy job. With permission sync on the Unity catalog, we also imported an existing Databricks grant into Onehouse, granted write access from Onehouse, and synced it back: Databricks then showed MODIFY and SELECT for the group.

Write once, query anywhere with Onehouse OneSync

In a lot of data teams, analysts query the lake in Amazon Athena while data scientists work in Databricks. This is common across enterprise teams and departments: finance teams might prefer Athena, while RevOps works in Databricks. Each side has its own copy of the important tables, and a copy job runs every night to keep them in step. Some mornings the two revenue numbers don’t match, and someone spends the day finding out why.

This post keeps one copy of an orders table in S3 and has Onehouse OneSync™ register it in both engines’ catalogs after every write. We run the same query in Athena and in Databricks, change the data, and run it again. Then we use OneSync permission sync to manage who can change the table.

The problem: two catalogs to keep up to date

Athena and Databricks can both read the same files in S3. What they can’t share is the catalog. Athena finds tables through AWS Glue, and Databricks finds them through Unity Catalog. So someone has to register the table in both places, and update both after every write: new files, new partitions, a changed schema. Miss one, and the two engines answer from different versions of the table.

Here’s how Onehouse solves this for its customers. The goal is to keep one copy of the table, register it in both catalogs, or as many as you need, and keep each one fresh within minutes of every write. You connect the catalogs once, and OneSync publishes the table to all of them after every write.

The result

Here’s what we set up and what each engine returned:

Item Result
Copies of the table one, in S3
Catalogs AWS Glue (for Athena) and Databricks Unity Catalog (for Databricks)
Setup in Onehouse two catalog connections and one Metadata sync table service
Before the change 200 orders, revenue 23,208.47 on both engines
After adding five orders 205 orders, revenue 23,843.34 on both engines
Time to show the change Athena about 1 minute after the load job finished, Databricks about 4 minutes
Copy jobs none
Access to the table a Databricks grant imported into Onehouse, write access granted from Onehouse and synced back to Unity Catalog

Step 1: connect the catalogs

In the Onehouse console, open Catalogs and click Add New Catalog. The Type list shows the catalogs Onehouse can register tables in, including AWS Glue, Apache Hive™ Metastore, Databricks Unity Catalog, Snowflake and its own Onehouse Catalog. In our example, we need two:

New catalog: the Type list with Glue Metastore, Hive Metastore, Databricks Unity Catalog, Snowflake Horizon Catalog, Snowflake Open Catalog and Onehouse Catalog

For Athena, pick Glue Metastore (that’s AWS Glue), give it a name and pick the AWS region the data is in. We called ours athena_glue, in us-west-2:

New catalog: name athena_glue, type Glue Metastore (HMS), region us-west-2 (Oregon)

For Databricks, pick Databricks Unity Catalog. It asks for the Unity catalog to publish into (ours is sales), the workspace host, the HTTP path of a SQL warehouse, and the OAuth client ID and secret of a service principal that can create tables in that catalog:

New catalog: name databricks_unity, type Databricks Unity Catalog, Unity catalog name sales, server hostname, HTTP path and client ID blurred, credentials stored by Onehouse, OAuth

If you’ll manage permissions from Onehouse too (Step 6), tick Enable Permission Sync further down the same form; it can only be set when the catalog is created. It needs the OAuth client ID and secret of a Databricks service principal with account admin rights, the workspace URL and the Databricks account ID, because groups live at the account level:

New catalog, Databricks Unity Catalog: Enable Permission Sync ticked, with Account OAuth Client Id, Account OAuth Secret, Workspace URL and Account ID; values blurred

Both now show up under Catalogs:

Catalogs list: athena_glue (GLUE), databricks_unity (UNITY) and sales_catalog (ONEHOUSE_CATALOG)

Step 2: load the table

The data comes from a load job on Onehouse. It’s a Python job, load-orders, on a Spark cluster called sales-etl. It reads a file of raw orders from S3 and writes them to the orders table in our sales lake:

Create Job: name load-orders, type Python, cluster sales-etl, executable orders_load.py and the --input parameter pointing at orders-0001.parquet; bucket name blurred

The first run creates the table and loads 200 orders:

The load-orders job in Onehouse, Runs tab: the first run Completed in 2 min 33 sec on the sales-etl cluster; executable path blurred

The table is store.orders: one row per order, with the customer, region, amount and status. In this post, revenue means the sum of amount.

Step 3: sync the table

Open the table under Data, go to Resources, and click Add Table Service:

The orders table in Onehouse, Resources tab, with the Add Table Service button; storage path blurred

Pick Metadata sync as the service type:

New Table Service: name orders-sync-athena-databricks, and the Service Type list with Clustering, Compaction, Cleaning and Metadata sync

Tick both catalogs:

New Table Service: service type Metadata sync, trigger mode Automatic, and the Catalogs list with athena_glue and databricks_unity ticked

Then pick the orders table and create the service. With the trigger mode on Automatic, it runs after every write to the table:

New Table Service: catalogs athena_glue and databricks_unity, the orders table ticked, and the Create Service button

After the next write, the table shows up in AWS Glue:

AWS Glue: table orders in database store, Table details; location and ARN blurred

And in Databricks, under the sales catalog. Both point to the same files in S3:

Databricks Catalog Explorer: sales, store, Tables (1), orders

Step 4: ask both engines

Now the same query in both:

SELECT count(*) AS orders, round(sum(amount), 2) AS revenue
FROM store.orders;           -- in Athena
-- FROM sales.store.orders;  -- in Databricks

Athena returns 200 orders and 23,208.47 in revenue:

Amazon Athena: the query on store.orders, Completed, 200 orders and revenue 23208.47

Databricks returns the same two numbers:

Databricks SQL editor: the query on sales.store.orders, 200 orders and revenue 23208.47

Step 5: change the data

Five new orders arrived in a new file, orders-0002.parquet. We pointed the same load job at it:

The load-orders job's parameter: --input pointing at onesync-demo/raw/orders/orders-0002.parquet; bucket name blurred

The job merges the file into the table by order ID, so new orders are added and changed orders are updated:

MERGE INTO store.orders t
USING incoming s
ON t.order_id = s.order_id
WHEN MATCHED THEN UPDATE SET *
WHEN NOT MATCHED THEN INSERT *

The run finished in about three minutes:

The load-orders job in Onehouse, Runs tab: the latest run Completed in 3 min 13 sec on the sales-etl cluster; executable path blurred

Within a minute, Athena picked up the new orders: 205 orders, and revenue up to 23,843.34:

Amazon Athena: the same query, 205 orders and revenue 23843.34

A few minutes later, Databricks showed the same. We didn’t run a copy job or register anything by hand:

Databricks SQL editor: the same query, 205 orders and revenue 23843.34

Step 6: manage who can change the table

The table now lives in two catalogs, and access to it is set in each one, by that catalog’s admin. Say that at month end the reporting-analysts team needs to fix orders in Databricks. Usually that’s a ticket to the Databricks admin, and no one place shows who can change the table, or who changed that.

OneSync permission sync moves that to Onehouse. You manage access next to the table, and Onehouse applies it in the catalog.

We turned it on in Step 1, when we connected the Unity catalog (Enable Permission Sync in the New catalog form).

Policies are managed under Catalogs, on the Access Control Sync tab. It lists the policies Onehouse manages and the history of every change, with Import, Grant/Revoke and Sync:

Catalogs, Access Control Sync tab: Policies and History, both empty, with the Reset, Import, Grant/Revoke and Sync buttons

First, bring in the access that’s already set. Click Import and pick databricks_unity as the source. It found that reporting-analysts can read store.orders:

Import Policies from databricks_unity: one Insert row, reporting-analysts, Role, store.orders, Table, SELECT

After the import, the rule is a policy in Onehouse, and History records where it came from:

Access Control Sync: policy reporting-analysts, Role, store.orders, Table, SELECT, last updated by databricks_unity; History: Import from databricks_unity, Completed, 1/1 policies updated

Now the month-end request. Click Grant/Revoke and write the statement. It takes GRANT or REVOKE on a database or a table, for a role:

GRANT INSERT, UPDATE, DELETE ON TABLE store.orders TO ROLE `reporting-analysts`

Validate & Preview shows exactly what changes before you submit it:

Grant/Revoke: the GRANT INSERT, UPDATE, DELETE statement, and the diff from INSERT, SELECT to DELETE, INSERT, UPDATE, SELECT for reporting-analysts on store.orders

Then click Sync and pick the catalog to send it to, databricks_unity. The preview shows the one change, and other catalogs, like AWS Glue, aren’t touched:

Sync Policies to databricks_unity: one Update row for reporting-analysts on store.orders, from SELECT to DELETE, INSERT, UPDATE, SELECT

History shows each change and when it reached Databricks:

Access Control Sync: policy reporting-analysts with DELETE, INSERT, UPDATE, SELECT; History: Sync to databricks_unity Completed 1/1, Grant in Onehouse Completed 1/1

In Databricks, the group now has MODIFY and SELECT on the table. MODIFY is Unity Catalog’s name for insert, update and delete:

Databricks SQL editor: SHOW GRANTS `reporting-analysts` ON TABLE sales.store.orders returns MODIFY and SELECT

Two things we learned on the way. Grant/Revoke only shows a change for a role Onehouse already knows, so import first. And for Unity Catalog, write access has to be granted as INSERT, UPDATE, DELETE together; a single INSERT is skipped at Sync, and History shows why.

Conclusion

Two engines don’t need two copies of a table. They need the same table in both of their catalogs, kept up to date after every write. With OneSync, that’s two catalog connections and one table service in Onehouse. In our run, Athena and Databricks gave the same answer before and after the change, and nobody had to copy a file or register a table by hand. With permission sync, who can change the table is managed in the same place, and applied in Databricks without a ticket.

Other recommended blogs:

To try it on your own tables, start at onehouse.ai, or get in touch with our team at gtm@onehouse.ai.

Frequently asked questions

Do I need to copy the data for each engine?

No. There’s one copy of the table in S3. OneSync registers that same table in each catalog, and every engine reads the same files.

Which catalogs can Onehouse register a table in?

The New catalog Type list includes AWS Glue, Apache Hive Metastore, Databricks Unity Catalog, Snowflake Horizon Catalog, Snowflake Open Catalog and the Onehouse Catalog. One Metadata sync service can publish a table to several of them at once.

How soon does each engine see a change?

The Metadata sync service runs after every write to the table. In our run, Athena showed the new orders about a minute after the load job finished, and Databricks about four minutes after.

What does Databricks need?

A service principal that can create tables in the target Unity catalog, with OAuth credentials for Onehouse, and a SQL warehouse. Unity Catalog also needs a storage credential and an external location for the S3 bucket. People who query the table need USE CATALOG, USE SCHEMA and SELECT on it.

What does permission sync need on Databricks?

Enable Permission Sync when you create the Unity catalog connection; it can’t be turned on later. It needs a Databricks service principal with account admin rights (OAuth client ID and secret), the workspace URL and the account ID. Without account admin rights, Import fails with “Failed to fetch policies from external catalog”.

Why does my Grant/Revoke preview show no difference?

Grant/Revoke only changes policies for roles Onehouse already knows. Import from the catalog first, so the role is in the policy list, then grant or revoke.

How are privileges mapped to Unity Catalog?

Grant/Revoke uses SELECT, INSERT, UPDATE and DELETE. Unity Catalog’s MODIFY covers insert, update and delete, so grant all three together; a single INSERT isn’t synced. See Announcing OneSync™ Permissions.

Read More:

Subscribe to the Blog

Be the first to hear about news and product updates

We are hiring diverse, world-class talent — join us in building the future