Repository navigation
Support VARCHAR(n) and CHAR(n) column types in DeltaLake table schemas - #101973
alexey-milovidov merged 8 commits into
Conversation
## Root cause
The Unity Catalog REST API returns column schema as `type_json`, which contains
the logical SQL type name from Databricks (e.g. `varchar(256)`) rather than the
physical Delta Lake type (`string`). The physical Delta Log stores `"type":"string"`
with a `__CHAR_VARCHAR_TYPE_STRING` metadata annotation for varchar/char columns
— this is why direct `deltaLake()` table function calls work with both kernel and
non-kernel paths. The Unity Catalog engine reads the `type_json` REST API field
and passes `"varchar(256)"` to `DeltaLakeMetadata::getSimpleTypeByName`, which
had no handler for it and threw:
Unsupported DeltaLake type: varchar(256)
## Fix
Added `varchar(n)` and `char(n)` to the type map in `getSimpleTypeByName`, mapping
both to `DataTypeString`. The length constraint is a SQL-layer annotation only;
the underlying Parquet data is plain byte arrays, identical to `string` columns.
This is the correct call site because `UnityCatalog.cpp` feeds `type_json` into
`DeltaLakeMetadata::getFieldType` → `getSimpleTypeByName`. The fix also acts as
defense-in-depth for any future path that might pass logical SQL type names.
## Tests
Two unit tests in `gtest_delta_kernel.cpp` directly call `getSimpleTypeByName`
with `"varchar(256)"` and `"char(1)"` and assert `TypeIndex::String`.
Integration test `test_varchar_char_types` in `test_storage_delta/test.py` creates
a Delta table with `VARCHAR(256)` and `CHAR(10)` columns via the DeltaTable builder
and verifies ClickHouse reads them as `Nullable(String)` via the table function —
tested for both kernel and non-kernel paths. Note: Delta Lake 3.3.0 + Spark 3.5.5
(used by the test runner) stores the physical `"string"` type in the Delta Log for
varchar/char DDL, so the integration test exercises the working `"string"` code path.
The unit tests are the precise regression guards for the `"varchar(256)"` path
triggered by the Unity Catalog REST API.
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
|
|
|
Workflow [PR], commit [65be55d] Summary: ✅ AI ReviewSummaryThis PR fixes Delta Lake schema parsing for logical SQL types from Unity Catalog ( ClickHouse Rules
Final Verdict
|
…tidy build The `readability-duplicate-include` clang-tidy check flagged `<DataTypes/DataTypeString.h>` as duplicated: it was included once inside the `#if USE_DELTA_KERNEL_RS` guard and again inside the `#if USE_PARQUET` guard. Move the include to the top of the file (outside all guards) so both sections share it without repetition. CI report: ClickHouse#101973 Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
The `Bugfix validation (integration tests)` job requires a test that fails
on the unfixed master binary. The previous test in `test_storage_delta/test.py`
used Spark's `DeltaTable.create` with `VARCHAR(256)` columns, but Spark
normalizes the type to `"string"` in the physical Delta Log before writing —
so ClickHouse's `getSimpleTypeByName` was never called with `"varchar(256)"`,
and the test passed on the old binary without the fix.
The actual bug is triggered by the Unity Catalog REST API path: UC returns
the column schema via the `type_json` field using SQL type names (e.g.
`"varchar(256)"`), which is fed into `DeltaLakeMetadata::getSimpleTypeByName`
via `UnityCatalog.cpp`. This new test in `test_database_delta/test.py` creates
a Delta table with `VARCHAR(256)` and `CHAR(10)` columns via Spark connected to
a real Unity Catalog server, then reads it through ClickHouse's `DataLakeCatalog`
engine — the exact code path that threw:
DB::Exception: Unsupported DeltaLake type: varchar(256)
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Spark/Delta Lake marks all columns nullable by default unless explicitly declared `NOT NULL`. Unity Catalog's REST API returns the `id INT` column with `nullable=true`, so ClickHouse correctly resolves it as `Nullable(Int32)`. The assertion `"id\tInt32"` was wrong — changed to `"id\tNullable(Int32)"`. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
|
The MSan stress test failure (MemorySanitizer: use-of-uninitialized-value, STID 4179-5154 or 4148-3044) is a known pre-existing issue unrelated to this PR. Fix: #102158 |
|
@alexey-milovidov, any additional actions required from me? |
|
I see a lot of failed tests, and I would like to know the reasons, because it is absolutely impossible to merge anything with failed tests. Let me investigate. |
`test_varchar_char_types` and `test_varchar_char_types_via_unity_catalog` go through Spark / Delta, which normalises VARCHAR/CHAR DDL down to the physical `string` type before writing the Delta log, so neither test exercises the broken code path on master. As a result the bugfix validation job reports "Failed to reproduce the bug" - the new tests pass even on the unpatched binary. The actual bug - `Unsupported DeltaLake type: varchar(256)` - lives in `DeltaLakeMetadata::getSimpleTypeByName`, on the non-kernel schema parsing path. Real-world emitters (notably the Unity Catalog REST API in `type_json`) sometimes serialise the column type as the raw SQL type name rather than the physical Delta type. Add `test_varchar_char_types_in_delta_log` which constructs the Delta log by hand with `"type": "varchar(256)"` and `"type": "char(10)"`, matching what those emitters produce. The test fails on master with the exact pre-fix exception and passes with the patched code, so the bugfix validation framework can now confirm the fix actually addresses a reproducible bug. CI: ClickHouse#101973 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
LLVM Coverage Report
Changed lines: 91.67% (11/12) · Uncovered code |
@alexey-milovidov, we now have green CI! 😄 |
0a0d0f8
Cherry pick #101973 to 26.4: Support VARCHAR(n) and CHAR(n) column types in DeltaLake table schemas
… in DeltaLake table schemas
Backport #101973 to 26.4: Support VARCHAR(n) and CHAR(n) column types in DeltaLake table schemas
…lumn types in DeltaLake table schemas
…1973 Backport ClickHouse#101973 to 26.4: Support VARCHAR(n) and CHAR(n) column types in DeltaLake table schemas
Root cause
The Unity Catalog REST API returns column schema as
type_json, which contains the logical SQL type name from Databricks (e.g.varchar(256)) rather than the physical Delta Lake type (string). The physical Delta Log stores"type":"string"with a__CHAR_VARCHAR_TYPE_STRINGmetadata annotation for varchar/char columns — this is why directdeltaLake()table function calls work with both kernel and non-kernel paths. The Unity Catalog engine reads thetype_jsonREST API field and passes"varchar(256)"toDeltaLakeMetadata::getSimpleTypeByName, which had no handler for it and threw:Fix
Added
varchar(n)andchar(n)to the type map ingetSimpleTypeByName, mapping both toDataTypeString. The length constraint is a SQL-layer annotation only; the underlying Parquet data is plain byte arrays, identical tostringcolumns. This is the correct call site becauseUnityCatalog.cppfeedstype_jsonintoDeltaLakeMetadata::getFieldType→getSimpleTypeByName. The fix also acts as defense-in-depth for any future path that might pass logical SQL type names.Tests
Two unit tests in
gtest_delta_kernel.cppdirectly callgetSimpleTypeByNamewith"varchar(256)"and"char(1)"and assertTypeIndex::String.Integration test
test_varchar_char_typesintest_storage_delta/test.pycreates a Delta table withVARCHAR(256)andCHAR(10)columns via the DeltaTable builder and verifies ClickHouse reads them asNullable(String)via the table function — tested for both kernel and non-kernel paths. Note: Delta Lake 3.3.0 + Spark 3.5.5 (used by the test runner) stores the physical"string"type in the Delta Log for varchar/char DDL, so the integration test exercises the working"string"code path. The unit tests are the precise regression guards for the"varchar(256)"path triggered by the Unity Catalog REST API.Changelog category (leave one):
Changelog entry:
Fixed an exception
Unsupported DeltaLake type: varchar(n)when reading Delta Lake tables whose schema contains varchar(n) or char(n) column types. These types are now mapped to String, consistent with how the Delta Lake protocol stores them as plain byte arrays in Parquet....
Documentation entry for user-facing changes
Version info
26.5.1.40526.4.5.48