Skip to content

Support VARCHAR(n) and CHAR(n) column types in DeltaLake table schemas - #101973

Merged
alexey-milovidov merged 8 commits into
ClickHouse:masterfrom
flaviomalavazi:fixing-varchar-unitycatalog-support
May 7, 2026
Merged

alexey-milovidov merged 8 commits into
ClickHouse:masterfrom
flaviomalavazi:fixing-varchar-unitycatalog-support

Conversation

@flaviomalavazi

@flaviomalavazi flaviomalavazi commented Apr 7, 2026 •

Copy link
Copy Markdown
Contributor

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.

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.5.1.405
  • Backported to: 26.4.5.48

## 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]>
@CLAassistant

CLAassistant commented Apr 7, 2026 •

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ alexey-milovidov
❌ flaviomalavazi
You have signed the CLA already but the status is still pending? Let us recheck it.

@clickhouse-gh

clickhouse-gh Bot commented Apr 7, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [65be55d]

Summary: ✅


AI Review

Summary

This PR fixes Delta Lake schema parsing for logical SQL types from Unity Catalog (varchar(n) / char(n)) by mapping them to String in DeltaLakeMetadata::getSimpleTypeByName, and adds regression coverage in unit and integration tests (including a hand-crafted Delta log case that reproduces the original exception path). I did not find correctness, safety, or performance issues that require changes.

ClickHouse Rules
Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ✅
SettingsChangesHistory.cpp ➖
PR metadata quality ✅
Safe rollout ✅
Compilation time ✅
No large/binary files ✅
Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Apr 7, 2026
flaviomalavazi and others added 3 commits April 7, 2026 16:34
…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]>
@alexey-milovidov

Copy link
Copy Markdown
Member

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

@flaviomalavazi

Copy link
Copy Markdown
Contributor Author

@alexey-milovidov, any additional actions required from me?

@alexey-milovidov

alexey-milovidov commented Apr 29, 2026 •

Copy link
Copy Markdown
Member

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.

alexey-milovidov and others added 2 commits April 29, 2026 13:44
`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]>
@clickhouse-gh

clickhouse-gh Bot commented May 6, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.10% 84.10% +0.00%
Functions 91.10% 91.10% +0.00%
Branches 76.60% 76.60% +0.00%

Changed lines: 91.67% (11/12) · Uncovered code

Full report · Diff report

@flaviomalavazi

Copy link
Copy Markdown
Contributor Author

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.

@alexey-milovidov, we now have green CI! 😄

@alexey-milovidov alexey-milovidov self-assigned this May 7, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue May 7, 2026
Merged via the queue into ClickHouse:master with commit 0a0d0f8 May 7, 2026
325 of 326 checks passed
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label May 7, 2026
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label May 9, 2026
robot-ch-test-poll2 added a commit that referenced this pull request May 9, 2026
Cherry pick #101973 to 26.4: Support VARCHAR(n) and CHAR(n) column types in DeltaLake table schemas
robot-clickhouse added a commit that referenced this pull request May 9, 2026
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label May 9, 2026
alexey-milovidov added a commit that referenced this pull request Jun 17, 2026
Backport #101973 to 26.4: Support VARCHAR(n) and CHAR(n) column types in DeltaLake table schemas
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…1973

Backport ClickHouse#101973 to 26.4: Support VARCHAR(n) and CHAR(n) column types in DeltaLake table schemas
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v26.4-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants