Sub topic 11
Sharing with Databricks: open sharing and Databricks-to-Databricks
This chapter assumes you know the share model (shares, schemas, tables), the provider and recipient roles, and how profile files and bearer tokens work. It covers how Databricks with Unity Catalog implements those ideas, and the two ways a provider can share.
Two sharing modes
Databricks supports two recipient types. Which one you create decides how the recipient connects.
- Open sharing is for recipients who are not on Databricks, or who have no Unity Catalog workspace. The recipient gets a credential file (a profile file) and reads with any Delta Sharing connector, such as pandas or Spark.
- Databricks-to-Databricks sharing is for recipients who have a Unity Catalog metastore. No token or profile file is needed. Databricks handles authentication between the two accounts, and the recipient sees the share inside their own workspace.
| Aspect | Open sharing | Databricks-to-Databricks |
|---|---|---|
| Recipient platform | Any client that speaks the protocol | Databricks with Unity Catalog |
| Credential | Profile file with bearer token | None to manage. Identified by metastore |
| How the recipient reads | Connectors such as `delta_sharing` or Spark | Mounts the share as a catalog |
| Token expiry and rotation | You manage it | Not applicable |
Provider side: create and grant
A provider with Unity Catalog manages sharing in SQL. You create a share, add tables, create a recipient, and grant the recipient read access.
CREATE SHARE retail_share;
ALTER SHARE retail_share ADD TABLE main.sales.orders;
CREATE RECIPIENT partner_co;
GRANT SELECT ON SHARE retail_share TO RECIPIENT partner_co;The statements are the same for both modes. The difference is in CREATE RECIPIENT. For an open recipient, Databricks generates an activation link. The recipient downloads the profile file from that link, and the link works only once. For a Databricks-to-Databricks recipient, you create the recipient with the sharing identifier of their metastore, and no link is involved.
The share is a pointer to your table. Nothing is copied into the share, so the recipient reads the current version of the table.
Recipient side: mount the share
A Databricks-to-Databricks recipient sees the provider and its shares in Unity Catalog. A user with the right privileges creates a catalog from a share, then queries it like any other table.
CREATE CATALOG partner_data USING SHARE provider_name.retail_share;
SELECT * FROM partner_data.sales.orders LIMIT 10;Shared tables are read-only. The recipient cannot insert, update or delete rows. Access inside the recipient's account is controlled by ordinary Unity Catalog grants on the new catalog, so the recipient's administrator decides which of their own users can query it.
An open sharing recipient does not use these statements. They read with the profile file, as shown in earlier chapters:
import delta_sharing
table_url = "config.share#retail_share.sales.orders"
df = delta_sharing.load_as_pandas(table_url)
print(df.head())Note that the share name in the URL is the share you created, retail_share. The schema and table names come from the source table, unless you gave an alias when adding it.
Common errors
- Profile file already downloaded. The activation link for an open recipient is single use. If the file is lost, rotate the recipient's token and send a new link.
- Wrong recipient type. A recipient created as open cannot be switched to Databricks-to-Databricks. Create a new recipient with the correct type.
- Missing privileges on the recipient side. Creating a catalog from a share needs the right Unity Catalog privileges. A user who can see the provider but cannot create the catalog usually lacks them on the metastore.
- Expired token. Open recipients have a token with a lifetime. Reads fail with an authentication error after it expires.
Choosing a mode
Use Databricks-to-Databricks when the recipient is on Databricks, since it avoids token handling and gives them native catalog access. Use open sharing when the recipient uses other tools or platforms. A provider can serve both kinds from the same share by creating one recipient of each type.
Exercise
A partner runs a Databricks workspace with Unity Catalog and also has an analyst who only uses pandas on a laptop. Which recipient types do you create, and what does each receive?
Show answer
Create a Databricks-to-Databricks recipient for the partner's metastore. It needs no token, and they mount the share as a catalog. Create an open sharing recipient for the laptop analyst. They receive an activation link to download a profile file, which they use with the delta_sharing pandas connector. Both recipients can be granted SELECT on the same share.