Skip to content

Fix bad cast exception when inserting into Iceberg table partitioned by year/month/day on Date column - #100404

Merged
alexey-milovidov merged 23 commits into
masterfrom
fix-iceberg-date-partition-year
May 1, 2026
Merged

alexey-milovidov merged 23 commits into
masterfrom
fix-iceberg-date-partition-year

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Mar 23, 2026 •

Copy link
Copy Markdown
Member

ChunkPartitioner::partitionChunk was passing DataTypeString as the result type when executing partition transform functions. For functions like toYearNumSinceEpoch (used for the Iceberg year transform), this caused DateTimeTransformImpl to create a ColumnString via result_type->createColumn() and then assert_cast it to ColumnVector<UInt16>, triggering a logical error.

The fix uses the pre-computed result_data_types (the actual return type of each transform function) instead of a hardcoded DataTypeString.

Closes #86337

Changelog category (leave one):

  • Bug Fix

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fix logical error exception when inserting into an Iceberg table with a Date column partitioned by year, month, or day transforms.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.5.1.213

…by year/month/day on Date column

`ChunkPartitioner::partitionChunk` was passing `DataTypeString` as the
result type when executing partition transform functions. For functions
like `toYearNumSinceEpoch` (used for the Iceberg `year` transform), this
caused `DateTimeTransformImpl` to create a `ColumnString` via
`result_type->createColumn()` and then `assert_cast` it to
`ColumnVector<UInt16>`, triggering a logical error.

The fix uses the pre-computed `result_data_types` (the actual return type
of each transform function) instead of a hardcoded `DataTypeString`.

Closes #86337

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Mar 23, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [d525a2f]

Summary: ✅


AI Review

Summary

This PR fixes an Iceberg insert exception by executing partition transform functions with their real return types instead of forcing DataTypeString, and adds regression coverage for both ClickHouse-created and Spark-created tables partitioned by date transforms. I did not find correctness, safety, performance, or compatibility issues in the patch.

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 pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! labels Mar 23, 2026
@alexey-milovidov alexey-milovidov added pr-bugfix Pull request with bugfix, not backported by default and removed pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-critical-bugfix labels Mar 23, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member Author

The Stress test (arm_msan) failure is fixed by #101239, which should be merged first. After it is merged, please update the branch to include the fix.

@clickhouse-gh

clickhouse-gh Bot commented May 1, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

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

Changed lines: 50.00% (7/14) · Uncovered code

Full report · Diff report

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Nice.

@alexey-milovidov alexey-milovidov self-assigned this May 1, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue May 1, 2026
Merged via the queue into master with commit e1165c5 May 1, 2026
165 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-iceberg-date-partition-year branch May 1, 2026 05:07
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label May 1, 2026
@clickgapai

Copy link
Copy Markdown
Contributor

Hi — this PR may need backporting to 26.3 (LTS), 26.2, 26.1, but no backport label was found.

Affected code: ChunkPartitioner::partitionChunk and getAvroType — introduced in 26.1.

Why: ChunkPartitioner.cpp was added recently (post-25.8). git log -S 'ChunkPartitioner::partitionChunk' shows the file was introduced for Iceberg INSERT support in late 2025. The bad-cast LOGICAL_ERROR on Date+year/month/day partitioning is user-visible, makes the documented allow_insert_into_iceberg path unusable for a common partition layout, and the fix is small and self-contained — appropriate for backport to all stable branches that include ChunkPartitioner.

Other supported branches (25.8) predate 26.1 and do not contain this code.

If this should be backported, consider adding pr-must-backport or a version-specific label (e.g. v26.3-must-backport). Ignore this if backporting is not applicable.

zvonand added a commit to Altinity/ClickHouse that referenced this pull request May 12, 2026
Antalya 26.3 Backport of ClickHouse#100404 - Fix bad cast exception when inserting into Iceberg table partitioned by year/month/day on Date column
il9ue pushed a commit to il9ue/ClickHouse that referenced this pull request May 20, 2026
…-partition-year

Fix bad cast exception when inserting into Iceberg table partitioned by year/month/day on Date column
@robot-ch-test-poll2 robot-ch-test-poll2 added pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR labels Sep 7, 2026
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.

Logical error: 'Bad cast from type DB::IColumn* to DB::ColumnVector<unsigned short>*' with Iceberg Date column

5 participants