Fix logical error in ALTER TABLE DROP PART with non-literal AST#99489
Merged
alexey-milovidov merged 2 commits intomasterfrom Mar 16, 2026
Merged
Fix logical error in ALTER TABLE DROP PART with non-literal AST#99489alexey-milovidov merged 2 commits intomasterfrom
alexey-milovidov merged 2 commits intomasterfrom
Conversation
The AST fuzzer found that when a query parameter with a non-String type
(e.g. `{partition:Date}`) is used in `ALTER TABLE ... DROP PART`, the
server replaces it with `_CAST(value, 'Type')` which is an `ASTFunction`,
not an `ASTLiteral`. The code then called `as<ASTLiteral &>()` which
threw a logical error (abort in debug/ASan builds) instead of a proper
user-facing exception.
Replace all unsafe `as<ASTLiteral &>()` reference casts in part name
extraction with a safe pointer cast that throws `BAD_ARGUMENTS` on
type mismatch. This affects 8 locations across `MergeTreeData.cpp` and
`StorageReplicatedMergeTree.cpp`.
https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=bb7e748bbc81a5f9181f4fdb5f80aa1c6180c0a7&name_0=MasterCI&name_1=AST%20fuzzer%20%28arm_asan%29
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
|
Workflow [PR], commit [a4ec8db] Summary: ✅ AI ReviewSummaryThis PR fixes a real correctness issue where ClickHouse Rules
Final Verdict
|
- Add `SET param_partition` so the query parameter substitution happens (previously got `UNKNOWN_QUERY_PARAMETER` instead of `BAD_ARGUMENTS`) - Rename test from 04039 to 04040 to avoid conflict with existing tests Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
LLVM Coverage Report
PR changed lines: PR changed-lines coverage: 82.35% (42/51, 0 noise lines excluded) |
Member
Author
alexey-milovidov
left a comment
There was a problem hiding this comment.
That's a good one!
zlareb1
added a commit
to zlareb1/ClickHouse
that referenced
this pull request
Mar 17, 2026
…eter (PR ClickHouse#99489) PR ClickHouse#99489 introduced `getPartNameFromAST` to replace direct `as<ASTLiteral&>()` casts. The PR's own test (`04040`) covers `DROP PART`; the `dropDetached` code path at `MergeTreeData.cpp:7706` was equally affected but not tested. A query parameter `{partition:Date}` is replaced by `_CAST(...)` — an `ASTFunction` — so the old code threw `LOGICAL_ERROR` (bad cast). The fix throws `BAD_ARGUMENTS` with a helpful message. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 task
github-merge-queue bot
pushed a commit
that referenced
this pull request
Mar 19, 2026
…non-literal Add test for DROP DETACHED PART with non-String typed query parameter (PR #99489)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ALTER TABLE ... DROP PARTreceives a non-literal AST node — e.g. via a typed query parameter like{partition:Date}which the server substitutes with_CAST(value, 'Type')as<ASTLiteral &>()reference casts in part name extraction with safe pointer casts that throwBAD_ARGUMENTSMergeTreeData.cpp(6 locations) andStorageReplicatedMergeTree.cpp(2 locations)Closes #99401
CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=bb7e748bbc81a5f9181f4fdb5f80aa1c6180c0a7&name_0=MasterCI&name_1=AST%20fuzzer%20%28arm_asan%29
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix logical error in
ALTER TABLE ... DROP PARTwhen a typed query parameter is used for the part name.🤖 Generated with Claude Code