Skip to content

Add new Unity catalog implementation with Delta Lake and Iceberg support - #115879

Merged
asya-ch merged 52 commits into
masterfrom
asya/unity_v2
Sep 24, 2026
Merged

asya-ch merged 52 commits into
masterfrom
asya/unity_v2

Conversation

@asya-ch

@asya-ch asya-ch commented Aug 21, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • Experimental Feature

Changelog entry:

Added a new implementation of the unity catalog type in the DataLakeCatalog database engine. It serves both Delta Lake and Iceberg tables from a single Unity Catalog, detecting the format of each table and routing Iceberg tables through the Unity Catalog Iceberg REST endpoint. Enable it with the database setting use_unity_catalog_v2, or set the session setting of the same name before CREATE DATABASE. Switch an existing database with ALTER DATABASE ... MODIFY SETTING use_unity_catalog_v2 = 1.

Summary

Add a new implementation of the "unity" catalog. It supports both Delta and Iceberg tables, in contrast to the current implementation, which only supports Delta. The new implementation is behind the use_unity_catalog_v2 database setting, so existing databases keep the old behavior. After a release or two, we can make it the default.

Credit to @melvynator for the prototype in #100669.

Tests

Added integration tests. Also, ran manual tests. I first created the following tables in Databricks.

  CREATE TABLE delta_managed (id INT, v DOUBLE) USING DELTA;
  INSERT INTO delta_managed VALUES (1, 1.0);

  CREATE TABLE delta_external (id INT, v DOUBLE) USING DELTA
  LOCATION 's3://<test-bucket>/tables/delta_external';
  INSERT INTO delta_external VALUES (2, 2.0);

  CREATE TABLE iceberg_managed (id INT, v DOUBLE) USING ICEBERG;
  INSERT INTO iceberg_managed VALUES (3, 3.0);

  CREATE TABLE uniform_managed (id INT, v DOUBLE) USING DELTA
  TBLPROPERTIES ('delta.enableIcebergCompatV2' = 'true',
                 'delta.universalFormat.enabledFormats' = 'iceberg');
  INSERT INTO uniform_managed VALUES (4, 4.0);

  CREATE TABLE uniform_external (id INT, v DOUBLE) USING DELTA
  LOCATION 's3://<test-bucket>/tables/uniform_external'
  TBLPROPERTIES ('delta.enableIcebergCompatV2' = 'true',
                 'delta.universalFormat.enabledFormats' = 'iceberg');
  INSERT INTO uniform_external VALUES (5, 5.0);

Then created the following databases:

CREATE DATABASE unity_oauth_token
  ENGINE = DataLakeCatalog('https://dbc-xxxxx.cloud.databricks.com/api/2.1/unity-catalog')
  SETTINGS
      catalog_type = 'unity',
      use_unity_catalog_v2 = 1,
      warehouse = 'external-loc-catalog',
      catalog_credential = 'eyJ...';

  CREATE DATABASE unity_static
  ENGINE = DataLakeCatalog('https://dbc-xxxxx.cloud.databricks.com/api/2.1/unity-catalog')
  SETTINGS
      catalog_type = 'unity_v2',
      use_unity_catalog_v2 = 1,
      warehouse = 'external-loc-catalog',
      catalog_credential = '{client_id}:{client_secret}';

CREATE DATABASE unity_pat_token
  ENGINE = DataLakeCatalog('https://dbc-xxxxx.cloud.databricks.com/api/2.1/unity-catalog')
  SETTINGS
      catalog_type = 'unity_v2',
      use_unity_catalog_v2 = 1,
      warehouse = 'external-loc-catalog',
      catalog_credential = 'dapi....';

For each database, I ran the following queries and verified expected results:

show tables from db;
select * from db.`test_schema.delta_managed`;
select * from db.`test_schema.delta_external`;
select * from db.`test_schema.iceberg_managed`;
select * from db.`test_schema.uniform_managed`;
select * from db.`test_schema.uniform_external`;
show create table db.`test_schema.delta_managed`;
show create table db.`test_schema.delta_external`;
show create table db.`test_schema.iceberg_managed`;
show create table db.`test_schema.uniform_managed`;
show create table db.`test_schema.uniform_external`;

Also verified that CREATE still works for Delta and that CREATE / INSERT / UPDATE work for Iceberg.

 SET allow_insert_into_iceberg = 1, write_full_path_in_iceberg_metadata = 1, async_insert = 0;

  INSERT INTO unity_pat_token.`default.iceberg_managed` VALUES (6, 6.0);
  SELECT * FROM unity_pat_token.`default.iceberg_managed` ORDER BY id;

  -- Databricks, then ClickHouse right after
  INSERT INTO external_loc_catalog.default.iceberg_managed VALUES (7, 7.0);
  INSERT INTO unity_pat_token.`default.iceberg_managed` VALUES (8, 8.0);

  ALTER TABLE unity_pat_token.`default.iceberg_managed` ADD COLUMN note Nullable(String);
  DESCRIBE unity_pat_token.`default.iceberg_managed`;

  CREATE TABLE unity_pat_token.`default.ch_iceberg` (id Int32, v Float64)
  ENGINE = IcebergS3('https://<test-bucket>.s3.us-east-2.amazonaws.com/tables/ch_iceberg/', '<access_key>', '<secret_key>', '<session_token>');
  SHOW TABLES FROM unity_pat_token LIKE '%ch_iceberg%';
  INSERT INTO unity_pat_token.`default.ch_iceberg` VALUES (1, 1.0);
  SELECT * FROM unity_pat_token.`default.ch_iceberg`;

  -- Expected: DATALAKE_DATABASE_ERROR, no schema `no_such_schema`, nothing written to S3
  CREATE TABLE unity_pat_token.`no_such_schema.t` (id Int32)
  ENGINE = IcebergS3('https://<test-bucket>.s3.us-east-2.amazonaws.com/tables/t/', '<access_key>', '<secret_key>', '<session_token>');

Workflow [PR]
Sync PR [sync-upstream/pr/115879]

Version info

  • Merged into: 26.10.1.568-master (included in 26.10 and later)

@clickhouse-gh

clickhouse-gh Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [6434dfc]

Summary: ✅


AI Review

Summary

This PR adds a new use_unity_catalog_v2 implementation for the unity DataLakeCatalog, routing Delta tables through the Unity tables API and Iceberg tables through the Unity Iceberg REST endpoint. I do not think the current HEAD is ready to approve yet: several persisted settings and operational flows still promise more than the implementation actually honors.

PR Metadata
  • Changelog category is correct: Experimental Feature.
  • Changelog entry is required and mostly specific, but it currently says users can "set the session setting of the same name before CREATE DATABASE". That is not how this feature is wired: use_unity_catalog_v2 is a database-engine setting loaded from the CREATE DATABASE ... SETTINGS clause (or later ALTER DATABASE ... MODIFY SETTING), not a general session setting.
  • Suggested replacement for the changelog entry: Added a new implementation of the \unity` catalog type in the `DataLakeCatalog` database engine. It serves both Delta Lake and Iceberg tables from a single Unity Catalog, detecting the format of each table and routing Iceberg tables through the Unity Catalog Iceberg REST endpoint. Enable it by setting `use_unity_catalog_v2 = 1` in the `CREATE DATABASE ... SETTINGS` clause, or switch an existing database with `ALTER DATABASE ... MODIFY SETTING use_unity_catalog_v2 = 1`.`
  • The free-form manual-test snippets lower in the PR body still use catalog_type = 'unity_v2', but that catalog type no longer exists in the current code. Those examples should be updated to catalog_type = 'unity' with use_unity_catalog_v2 = 1.
Findings

⚠️ Majors

  • [src/Databases/DataLake/DatabaseDataLake.cpp:375-381; src/Databases/DataLake/UnityV2Catalog.cpp:192-203] [dismissed by author -- https://github.com/ClickHouse/ClickHouse/pull/115879#discussion_r3847293206] oauth_server_use_request_body = 0 is still accepted for catalog_type = 'unity', use_unity_catalog_v2 = 1, but the setting never reaches UnityV2Catalog and token retrieval always uses request-body mode. That means a persisted DataLakeCatalog setting can silently authenticate with the wrong request shape at runtime instead of either working or being rejected up front. Suggested fix: either thread oauth_server_use_request_body through UnityV2Catalog::retrieveAccessToken the same way RestCatalog does, or reject oauth_server_use_request_body = 0 in the Unity-v2 validation path.
  • [src/Databases/DataLake/DatabaseDataLake.cpp:361-367; src/Databases/DataLake/UnityCatalog.cpp:539-549] [dismissed by author -- https://github.com/ClickHouse/ClickHouse/pull/115879#discussion_r4045923301] ALTER DATABASE ... MODIFY SETTING use_unity_catalog_v2 = 0 is not a safe rollback for two of the auth modes this PR adds. The rollback branch rebuilds legacy UnityCatalog, which only stores catalog_credential as a raw bearer token and has no auth_header or OAuth client-credential support, so a database created with auth_header or <client_id>:<client_secret> will start failing after the advertised implementation switch. Suggested fix: either reject rollback for v2-only auth configurations, or teach the legacy client to honor the same persisted auth settings before presenting the switch as reversible.
  • [src/Databases/DataLake/UnityV2Catalog.cpp:46-60] [dismissed by author -- https://github.com/ClickHouse/ClickHouse/pull/115879#discussion_r4065856812] The Unity alter validator still forbids changing catalog_credential or auth_header, so the new static-token auth modes cannot be rotated in place. A pre-obtained OAuth bearer token is inherently short-lived, and even PAT rotation now requires drop/recreate; test_static_token_expiry only recovers by restoring the proxy's out-of-band state, not by updating database metadata. Suggested fix: allow the same auth-setting alters that RestCatalog supports, or stop accepting/advertising static-token modes until there is an in-product recovery path.
Tests
  • ⚠️ [tests/integration/test_database_unity_v2/test.py:201-215] There is still no end-to-end proxied case for auth_header = 'Authorization: Bearer ...'. The suite covers PAT and OAuth-through-catalog_credential, but not the header-only path or its forwarding into the embedded Iceberg REST client. A small proxied test that creates the database with auth_header and reads marksheet_uniform would close this gap.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required action: either implement or explicitly reject oauth_server_use_request_body = 0 for Unity v2.
  • Minimum required action: make the operational contract match the auth-mode story, either by supporting auth-setting rotation and safe rollback for the newly supported auth modes or by narrowing the documented/advertised behavior to the modes that actually work.
  • Minimum required action: add a focused auth_header integration test and fix the stale PR-description text (catalog_type = 'unity_v2', “session setting” wording).

LLVM Coverage Report

Measured on commit 6434dfc.

Metric Baseline Current Δ
Lines 88.10% 88.10% +0.00%
Functions 91.70% 91.70% +0.00%
Branches 79.40% 79.40% +0.00%

Changed lines: Changed C/C++ lines covered: 436/563 (77.44%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-experimental Experimental Feature label Aug 21, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Commit 6434dfcdbda876cbbc2dba0fe182e84ece37cf0d was not compared: the CI logs cluster did not answer (every POST attempt failed with an exception).

See the job log for details.

@scanhex12 scanhex12 self-assigned this Aug 24, 2026
@asya-ch

asya-ch commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator Author

test_database_unity_v2/test.py::test_uniform_table_reads_as_delta is failing because the build doesn't support the Delta kernel. I have a PR open (#116415) to block such queries instead of returning wrong results. I will merge master on top of it and resolve the test then.

@asya-ch

asya-ch commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator Author

test_database_unity_v2/test.py::test_uniform_table_reads_as_delta is failing because the build doesn't support the Delta kernel. I have a PR open (#116415) to block such queries instead of returning wrong results. I will merge master on top of it and resolve the test then.

Never mind, it is getting overly complicated. I will skip the test for this PR.

@clickhouse-gh clickhouse-gh Bot added the comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. label Sep 4, 2026
Comment thread src/Core/SettingsChangesHistory.cpp Resolved
/// Databricks OIDC expects `all-apis`; the default `auth_scope` value targets Iceberg REST catalogs.
const std::string unity_auth_scope = settings[DatabaseDataLakeSetting::auth_scope].changed
? settings[DatabaseDataLakeSetting::auth_scope].value
: "all-apis";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just

const std::string unity_auth_scope = settings[DatabaseDataLakeSetting::auth_scope].value

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default value is PRINCIPAL_ROLE:ALL, which is correct for REST catalogs, but not for the Unity catalog. So we do need to set the default here.

return json.dumps(body).encode()


class Handler(BaseHTTPRequestHandler):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need proxy?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The OSS server used in tests has some differences from the actual Databricks server. There's a comment at the top of the file that summarizes the differences:

"""Makes the open-source Unity Catalog server look like Databricks to
`UnityV2Catalog`, for the tables in `UNIFORM_TABLES` only:

- serves the Iceberg REST catalog at `/iceberg-rest`, not `/iceberg`;
- reports an Iceberg `securable_kind`, which the open-source server never sends;
- writes the table location as `file:///tmp/...`, which `setLocation` requires.

It also emulates Databricks authentication:

- `POST /oidc/v1/token` mints OAuth tokens for `CLIENT_ID:CLIENT_SECRET`, and
  requires `scope=all-apis` as Databricks service principals do;
- every proxied route requires `Authorization: Bearer <token>`, where the token
  is either `PAT_TOKEN` or a minted OAuth token, and replies 401 otherwise;
- `/control/*` endpoints let the test expire tokens.
"""

});
}

return tryGetDeltaTableMetadata(full_table_name, object, result);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we have retries for iceberg but don't have for delta?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tryGetDeltaTableMetadata only parses the JSON, it does not make any HTTP requests. For Iceberg, we do need to make a second request to get metadata for Iceberg tables. The retry refreshes the OAuth token if needed (it's not a generic retry).

return f"{prefix}_{uuid.uuid4()}".replace("-", "_")


def create_database(node, db_name, url=UC_URL, catalog_credential=None):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The auth coverage here still never exercises the auth_header mode that UnityV2Catalog now supports.

create_database only injects catalog_credential, and the tests below cover PAT and OAuth through that path, but not auth_header = 'Authorization: Bearer ...'. That leaves the third advertised auth mode unproven end-to-end, including forwarding the header into the embedded Iceberg REST client for SHOW CREATE / reads on the Iceberg arm.

Please add one proxied case that creates the database with auth_header (no catalog_credential) and reads marksheet_uniform, so a regression in the header-only path does not slip through.

SettingsChanges catalog_settings_changes;
for (const auto & change : settings_changes)
{
if (change.name != "use_unity_catalog_v2")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's move "use_unity_catalog_v2" to some static constexpr const char* variable

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I wanted to remove the harded-coded copy altogethrer, so I went a bit further and added a call to DB::DatabaseDataLakeSettings::getSettingName(DB::DatabaseDataLakeSetting::use_unity_catalog_v2).


/// UniForm ("DELTA_UNIFORM_ICEBERG") is a Delta table that also publishes Iceberg metadata;
/// read it as Delta because the Delta log is the source of truth.
static const std::unordered_set<std::string> READABLE_DELTA_FORMATS = {"DELTA", "DELTA_UNIFORM_ICEBERG"};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we need also "ICEBERG" here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the idea is that this shows which formats should be read as Delta instead of Iceberg. I'll change the comment / naming to make it clear.


Poco::JSON::Object request_body;
request_body.set("table_id", table_id);
request_body.set("operation", "READ");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why for read only?

@asya-ch asya-ch Sep 21, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It copies the behavior in the V1 catalog.

We'll need to change it to READ_WRITE for inserts to work, but this PR is already big, so I would prefer to handle in a separate PR.

(Will add clarifying comment.)

auto catalog = std::make_shared<RestCatalog>(
warehouse,
iceberg_rest_url,
/* catalog_credential= */ "",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't we need to get those values from the settings?

@asya-ch asya-ch Sep 21, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UnityV2Catalog already takes these values and uses them to create the auth_header.

I'll add a clarifying comment.

@@ -0,0 +1,642 @@
#!/usr/bin/env python3

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also add a test that we can

  1. create iceberg table
  2. write something into this table

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and for delta too

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add it for Delta. It doesn't yet support CREATE / INSERT for Iceberg, will add test to show it fails with NOT_IMPLEMENTED.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it hard to support? I think it could be confusing that we can write into delta and can't write into iceberg

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I added support. I ran manual tests and added them to the summary.

Unfortunately, difficult to add to the integration test since the OSS catalog doesn't support the POST endpoints.

@asya-ch
asya-ch enabled auto-merge September 23, 2026 16:45
@asya-ch
asya-ch added this pull request to the merge queue Sep 24, 2026
Merged via the queue into master with commit bc7b375 Sep 24, 2026
176 checks passed
@asya-ch
asya-ch deleted the asya/unity_v2 branch September 24, 2026 03:13
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 24, 2026
zvonand added a commit to Altinity/ClickHouse that referenced this pull request Oct 24, 2026
@clickhouse-gh clickhouse-gh Bot added comp-datalake-catalogs Data lake catalogs: the DataLakeCatalog database engine and its catalog clients - Iceberg REST, A... and removed comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-datalake-catalogs Data lake catalogs: the DataLakeCatalog database engine and its catalog clients - Iceberg REST, A... pr-experimental Experimental Feature pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants