> ## Documentation Index
> Fetch the complete documentation index at: https://docs.startree.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Delta Lake: Onboarding via SQL DDL

> Read Delta Lake tables straight from their Delta log, through Unity Catalog or from a storage path, with one CREATE TABLE ... WITH statement.

> [!WARNING]
>
> **Not in a StarTree Cloud release yet.** Contact StarTree support to find out when it's available for your environment. There's no Data Portal flow for these tables, so you onboard them with [SQL DDL](#create-the-table) or a [table config](#table-config).

`type = 'delta'` reads a Delta table's transaction log directly, so the table doesn't need Iceberg reads (UniForm) turned on. Delta tables that do have UniForm can still be read as Iceberg through [Unity Catalog](https://docs.startree.ai/corecapabilities/external-table/unity/onboarding-api.md).

You point Pinot at a table in one of two ways:

| Source | Options | Storage access |
| - | - | - |
| Unity Catalog | `catalog_uri`, `catalog_name`, `schema_name`, `table_name`, plus OAuth or a personal access token | Unity vends short-lived credentials, or you supply your own |
| A storage path | `location` | You supply storage credentials, or grant StarTree's Google identity for GCS |

## Unity Catalog prerequisites

* **The workspace URL as `catalog_uri`**, with nothing after the host:

  | Cloud | `catalog_uri` |
  | - | - |
  | AWS | `https://<workspace-name>.cloud.databricks.com` |
  | Azure | `https://adb-<workspace-id>.<n>.azuredatabricks.net` |
  | Google Cloud | `https://<workspace-id>.<n>.gcp.databricks.com` |

  This is the workspace URL itself, not the `/api/2.1/unity-catalog/iceberg-rest` URL used for Iceberg tables. Other hosts, including custom domains, are rejected.
* **A principal to authenticate as:** a service principal with an OAuth secret (OAuth M2M), or a personal access token. Pinot gets OAuth tokens from the workspace's `/oidc/v1/token` endpoint with the `all-apis` scope. You can't change either.
* **Grants for that principal:** `USE CATALOG` on the catalog, `USE SCHEMA` on the schema, and `SELECT` on the table. To have Unity vend storage credentials (`storage.access_policy = 'unity'`), also grant `EXTERNAL USE SCHEMA` on the schema and turn on external data access for the metastore. [Prepare Databricks](https://docs.startree.ai/corecapabilities/external-table/unity/prepare-databricks.md#set-up-a-service-principal-and-grants) shows how to create the principal and run the grants.

## Create the table

From Unity Catalog with OAuth, on S3 with Unity-vended credentials:

```sql theme={null}
CREATE TABLE delta_orders WITH (
  type = 'delta',
  catalog_uri = 'https://<workspace-name>.cloud.databricks.com',
  catalog_name = '<catalog>',
  schema_name = '<schema>',
  table_name = '<table>',
  client_id = '<client-id>',
  client_secret = 'srn2:secret#<client-secret-reference>',
  storage.provider = 's3',
  storage.access_policy = 'unity',
  storage.region = 'us-west-2',
  refresh_interval = '5m'
);
```

Send it to `POST /sql/ddl` as described in [SQL DDL](https://docs.startree.ai/corecapabilities/external-table/sql-ddl.md). Add `?dryRun=true` to compile and validate without creating anything. Pinot picks the snapshot it will start from, infers the schema from that snapshot, reads one data file to check storage access, and creates an OFFLINE table.

* **OAuth.** `client_id` and `client_secret` imply `auth_type = 'oauth'`. Leave out `oauth_scope` and `oauth_token_uri`; they're rejected.
* **Personal access token.** Replace the two OAuth lines with `token = 'srn2:secret#<pat-reference>'`. Use OAuth or a token, not both.
* **Authentication is required** for a Unity table, even when storage uses your own keys.
* **`table_name`** defaults to the Pinot table name. **`catalog_type`** is optional, and `unity` is the only value it takes.
* **Deleted rows.** Add `'enableDeletionVectors' = 'true'` to hide rows deleted through Delta deletion vectors. Without it, those rows stay visible.

### Storage

| Storage | `storage.provider` | Access | Other storage options |
| - | - | - | - |
| S3 | `s3` | `storage.access_policy = 'unity'` (Unity tables only) | `storage.region`, required. Keys are rejected. |
| S3 | `s3` | Your access keys | `storage.access_key`, `storage.secret_key`, optional `storage.session_token`, and `storage.region`. Leave out `storage.access_policy`. |
| GCS | `gcs` | `storage.access_policy = 'unity'` (Unity tables only) or `'gcs-adc'` (the default) | None. Storage keys are rejected. |
| Azure | `azure` | `storage.access_policy = 'unity'` (Unity tables only) | None. `storage.sas_token` and `storage.credential_prefix` are rejected. |
| Azure | `azure` | Your SAS token | `storage.sas_token` and `storage.credential_prefix`, as in [Unity Catalog + ADLS](https://docs.startree.ai/corecapabilities/external-table/unity/adls/onboarding-api.md#a-sas-token-you-provide). Leave out `storage.access_policy`. |

With `unity`, Unity issues read-only credentials scoped to the table's storage location, and Pinot renews them before they expire. With `gcs-adc`, Pinot reads GCS as StarTree's Google identity. Grant it `storage.objects.get` and `storage.objects.list` on the bucket; the **Storage Object Viewer** role covers both. Contact StarTree support for the identity to grant.

### A table by storage path

Without Unity, set `location` to the Delta table's root:

```sql theme={null}
CREATE TABLE delta_events WITH (
  type = 'delta',
  location = 's3://<bucket>/<path-to-table>',
  storage.provider = 's3',
  storage.access_key = 'srn2:secret#<access-key-reference>',
  storage.secret_key = 'srn2:secret#<secret-key-reference>',
  storage.region = 'us-west-2',
  refresh_interval = '5m'
);
```

* `location` must be an object-store path starting with `s3://`, `s3a://`, `gs://`, `abfs://` or `abfss://`.
* `catalog_name`, `auth_type`, `token`, `client_id` and `client_secret` are rejected, and so is `storage.access_policy = 'unity'`. There's no catalog to vend credentials.
* `schema_name` and `table_name` are optional. They only label the table.
* For GCS, use `storage.provider = 'gcs'` and grant StarTree's Google identity as above. For Azure, use a SAS token.

### Table config

If you manage table configs directly, put these keys in the `ExternalTableSyncTask` section of the OFFLINE table config:

```json theme={null}
{
  "catalogType": "delta-unity",
  "executor": "controller",
  "schedule": "0 */5 * * * ?",
  "catalog.delta-unity.uri": "https://<workspace-name>.cloud.databricks.com",
  "catalog.delta-unity.catalogName": "<catalog>",
  "catalog.delta-unity.table.namespace": "<schema>",
  "catalog.delta-unity.table.tableName": "<table>",
  "catalog.delta-unity.auth.rest.oauthClientId": "<client-id>",
  "catalog.delta-unity.auth.rest.oauthClientSecret": "srn2:secret#<client-secret-reference>",
  "catalog.delta-unity.auth.storage.region": "us-west-2",
  "sourceStorageProvider": "s3",
  "externalTableAccessPolicy": "unity"
}
```

| Key | Value |
| - | - |
| `catalogType`, `executor` | Must be `delta-unity` and `controller`. Leave out `enabled` entirely; even `enabled = false` is rejected. |
| `schedule` | How often Pinot checks for a new version, as a Quartz cron expression. `refresh_interval = '5m'` in SQL becomes `0 */5 * * * ?`. |
| `uri`, `catalogName`, `table.namespace`, `table.tableName` | The SQL options `catalog_uri`, `catalog_name`, `schema_name` and `table_name`. |
| `auth.rest.oauthClientId`, `auth.rest.oauthClientSecret` | OAuth. For a personal access token, use `catalog.delta-unity.auth.rest.token` instead. |
| `location` | For a table by storage path, `catalog.delta-unity.location` replaces the Unity and `auth.rest` keys. |
| `sourceStorageProvider`, `externalTableAccessPolicy` | `s3`, `gcs` or `azure`, and `unity` or `gcs-adc`. |

After the first sync, Pinot adds `catalog.delta-unity.sourceIdentity` to the config. Don't change or remove it.

### Run the first sync

DDL doesn't run a sync. Wait for `refresh_interval`, or start one now:

```bash theme={null}
curl -X POST "$BASE_URL/tasks/schedule?taskType=ExternalTableSyncTask&tableName=delta_orders_OFFLINE"
```

## Snapshots

* `snapshot_mode = 'latest'`, the default, starts from the newest version.
* `snapshot_mode = 'snapshot_id'` with `snapshot_id = '<id>'` starts from a specific snapshot. The ID is Pinot's encoded snapshot ID, not a Delta version number. Setting `snapshot_id` alone implies this mode.
* `snapshot_mode = 'earliest'` isn't supported.
* After the first sync, every sync moves to the newest version.

## What's supported

* **Delta reader features:** deletion vectors, column mapping, `timestampNtz`, type widening, V2 checkpoints, `vacuumProtocolCheck`, and variant types, including shredded variants. Partitioned and liquid-clustered tables work.
* **Catalog-managed tables** (the `catalogManaged` table feature). Pinot reads the commits published to the table's `_delta_log`. A commit Unity has accepted but not published yet isn't visible until it's published, so the table in Pinot can trail Databricks. To refuse these tables instead, add `'catalog.delta-unity.catalogManaged.readPublishedLog' = 'false'`.

## Limits

* **Snapshot size.** One snapshot can list up to 100,000 data files and about 64 MiB of file metadata, which counts paths, statistics, partition values and inline deletion vectors. A larger snapshot fails without syncing part of it. Compact the table, or contact StarTree support about raising the limits.
* **Version number.** Tables past Delta version 2,097,151 are refused.
* **Refused tables.** Views, shallow clones, and Unity tables in other formats. Serve the source table or a deep clone instead of a shallow clone.
* **Refused features.** Unknown reader features, type changes Pinot can't apply to older files, and nested fields whose physical names differ from their logical names (column-mapping renames inside structs, arrays or maps). Top-level renames work.
* **Files outside the table.** Data files or deletion vectors stored outside the table's root are refused.
* **One source per table.** On its first sync, Pinot binds the table to the Delta table's identity. If the Delta table is dropped and recreated, or replaced, create a new Pinot table with a new name. Reusing the name of a deleted Pinot table can also fail, so pick a new name.
* **No switching formats.** You can't change an existing table between `type = 'delta'` and Iceberg. Create a new table.

## Common errors

Errors from the catalog connection arrive wrapped as `Failed to resolve the external table '<schema>.<table>' from the catalog: <cause>`. Errors about the table itself, such as views, clones and unsupported features, arrive unwrapped.

| Error contains | Cause |
| - | - |
| `type = 'delta' requires exactly one of 'catalog_uri' (Unity Catalog) and 'location' (a Delta table path).` | Both or neither are set |
| `type = 'delta' supports only catalog_type = 'unity'.` | `catalog_type` is set to something else. Remove it |
| `type = 'delta' uses the workspace OAuth endpoint and scope 'all-apis'; remove 'oauth_scope' and 'oauth_token_uri'.` | Remove both options |
| `needs Unity Catalog ('catalog_uri'); a 'location' table reads the path directly.` | A table by storage path sets a Unity or auth option |
| `storage.access_policy = 'unity' vends credentials through Unity Catalog; a 'location' table needs storage keys or a cloud identity.` | A table by storage path uses `unity`. Supply storage credentials instead |
| `requires the 'storage.region' option.` | S3 with `unity` and no `storage.region` |
| `Option '<key>' is incompatible with storage.provider = '<provider>'.` | A storage option that doesn't go with the provider and access policy. See [Storage](#storage) |
| `Unity Delta catalog requires authentication` | A Unity table without `client_id` and `client_secret`, or `token` |
| `catalog.delta-unity.uri must be a Databricks workspace (https://<workspace host>)` | `catalog_uri` has a path, a port or a host that isn't a Databricks workspace host |
| `Databricks OAuth token request for client <client-id> failed with HTTP <status>` | Wrong client ID or secret, or the service principal has no OAuth secret |
| `Unity Catalog denied /tables/<catalog>.<schema>.<table> (HTTP 403)` | The principal is missing `USE CATALOG`, `USE SCHEMA` or `SELECT` |
| `Unity Catalog denied /temporary-table-credentials (HTTP 403)` | With `unity`, the principal is missing `EXTERNAL USE SCHEMA`, or external data access is off for the metastore |
| `Unity Catalog object not found: /tables/` | The catalog, schema or table name is wrong, or the principal can't see the table |
| `, not a Delta table` | The Unity table is a view or isn't stored as Delta |
| `is a shallow clone, whose data files live in its source table; serve the source table or a deep clone` | Shallow clones aren't supported |
| `cannot be served` | The Delta table uses a feature or layout from [Limits](#limits). The message names it |
| `must be an object store path (s3://, s3a://, gs://, abfs:// or abfss://)` | `location`, or the table's location in Unity, isn't an object-store path |
| `Delta tables support only snapshot_mode = 'latest' or 'snapshot_id'.` | `snapshot_mode = 'earliest'` |
| `Delta snapshot exceeds catalog.delta-unity.maxSnapshotFiles` or `maxSnapshotMetadataBytes` | The snapshot is over a [size limit](#limits) |
| `Delta source generation changed` | The Delta table was dropped and recreated, or replaced. Create a new Pinot table with a new name |
| `Delta snapshot artifacts already exist for <table>` | The Pinot table name was used before. Create the table under a new name |
| `changing the catalog type of a table is not supported. Create a new table instead.` | The table config switched between Delta and Iceberg |

## Not supported

* The Data Portal wizard.
* Delta tables registered in catalogs other than Unity Catalog. Read them by `location` instead.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.