Skip to content

Fix bad cast exception when filtering _table virtual column in merge table function - #98291

Merged
alexey-milovidov merged 5 commits into
masterfrom
fix-merge-table-virtual-column-bad-cast
Mar 1, 2026
Merged

alexey-milovidov merged 5 commits into
masterfrom
fix-merge-table-virtual-column-bad-cast

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Feb 28, 2026 •

Copy link
Copy Markdown
Member

Linked issues

The _database and _table virtual columns in StorageMerge are defined as LowCardinality(String), but getSelectedTables constructed the filter sample block and columns using plain String type. When the query analyzer generated a filter expression expecting LowCardinality(String) (e.g. with tuple IN), executing that filter against plain String columns caused a LOGICAL_ERROR: Bad cast from type DB::ColumnString to DB::ColumnLowCardinality.

Fix by using LowCardinality(String) in the sample block and filter lambda, matching the actual virtual column definitions.

https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=98251&sha=73e60a55c201e3724f9c35da27ac9c7a182e99d8&name_0=PR&name_1=AST%20fuzzer%20%28amd_ubsan%29
#98251

Changelog category (leave one):

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

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

Fix bad cast exception when filtering _table virtual column in merge table function.

Version info

  • Merged into: 26.3.1.179

…ge()` table function

The `_database` and `_table` virtual columns in `StorageMerge` are defined
as `LowCardinality(String)`, but `getSelectedTables` constructed the filter
sample block and columns using plain `String` type. When the query analyzer
generated a filter expression expecting `LowCardinality(String)` (e.g. with
tuple IN), executing that filter against plain `String` columns caused a
`LOGICAL_ERROR: Bad cast from type DB::ColumnString to DB::ColumnLowCardinality`.

Fix by using `LowCardinality(String)` in the sample block and filter lambda,
matching the actual virtual column definitions.

https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=98251&sha=73e60a55c201e3724f9c35da27ac9c7a182e99d8&name_0=PR&name_1=AST%20fuzzer%20%28amd_ubsan%29

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Feb 28, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [dd88c40]

Summary: ✅

@ClickHouse ClickHouse deleted a comment from CLAassistant Feb 28, 2026
@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Feb 28, 2026
@alexey-milovidov
alexey-milovidov force-pushed the fix-merge-table-virtual-column-bad-cast branch from ac4d053 to abe0697 Compare February 28, 2026 02:41
alexey-milovidov and others added 4 commits February 28, 2026 03:43
…ple IN query

The query `('test_local_1', 'test_local_2') IN (_table)` is semantically
invalid (checking if a tuple is in a string column). Previously it caused
a `LOGICAL_ERROR` (bad cast), now it correctly returns a user-facing error.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@alexey-milovidov alexey-milovidov self-assigned this Mar 1, 2026

@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.

Good fix.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Mar 1, 2026
Merged via the queue into master with commit 71fbfaa Mar 1, 2026
144 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-merge-table-virtual-column-bad-cast branch March 1, 2026 02:08
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Mar 1, 2026
alexey-milovidov added a commit that referenced this pull request Mar 1, 2026
…umn-bad-cast

Fix bad cast exception when filtering `_table` virtual column in `merge` table function
@watson-ch

watson-ch Bot commented May 22, 2026

Copy link
Copy Markdown

Backport labels have been automatically added based on https://github.com/ClickHouse/clickhouse-core-incidents/issues/667

Labels added:

  • v25.8-must-backport
  • v25.10-must-backport
  • v25.12-must-backport
  • v26.2-must-backport

These labels ensure backport PRs are properly created for each affected release version. The release automation will create backport PRs as needed based on these labels.

@robot-clickhouse robot-clickhouse added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label May 22, 2026
robot-ch-test-poll2 added a commit that referenced this pull request May 22, 2026
Cherry pick #98291 to 25.8: Fix bad cast exception when filtering `_table` virtual column in `merge` table function
robot-clickhouse added a commit that referenced this pull request May 22, 2026
…e` virtual column in `merge` table function
@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 22, 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 v25.12-must-backport v26.2-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants