Skip to content

Cherry pick #101973 to 26.4: Support VARCHAR(n) and CHAR(n) column types in DeltaLake table schemas - #104500

Merged
robot-ch-test-poll2 merged 10 commits into
backport/26.4/101973from
cherrypick/26.4/101973
May 9, 2026
Merged

robot-ch-test-poll2 merged 10 commits into
backport/26.4/101973from
cherrypick/26.4/101973

Conversation

@robot-ch-test-poll2

Copy link
Copy Markdown
Contributor

Original pull-request #101973

Do not merge this PR manually

This pull-request is a first step of an automated backporting.
It contains changes similar to calling git cherry-pick locally.
If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.

The check results does not matter at this step - you can safely ignore them.

Troubleshooting

If the conflicts were resolved in a wrong way

If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

flaviomalavazi and others added 10 commits April 7, 2026 13:51
## 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]>
…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: #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]>
`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: #101973

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…talog-support

Support VARCHAR(n) and CHAR(n) column types in DeltaLake table schemas
@robot-ch-test-poll2 robot-ch-test-poll2 added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default labels May 9, 2026
@robot-ch-test-poll2
robot-ch-test-poll2 merged commit b33eb00 into backport/26.4/101973 May 9, 2026
@robot-ch-test-poll2
robot-ch-test-poll2 deleted the cherrypick/26.4/101973 branch May 9, 2026 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants