Skip to content

Reject parser-impossible MOVE destinations in ASTAlterCommand::readJSON - #114429

Merged
evillique merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-readjson-move-destination-part-form
Aug 12, 2026
Merged

evillique merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-readjson-move-destination-part-form

Conversation

@groeneai

@groeneai groeneai commented Aug 12, 2026 •

Copy link
Copy Markdown
Collaborator

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):

Fixed a LOGICAL_ERROR (Bad cast from type DB::ASTLiteral to DB::ASTPartition) and unparseable formatted SQL when an ALTER TABLE ... MOVE command deserialized from a JSON AST (dialect = clickhouse_json) paired the PART form with TO TABLE, or the PARTITION form with TO SHARD. Such payloads are now rejected with BAD_ARGUMENTS.

Description

ParserAlterQuery accepts TO SHARD only in the MOVE PART branch and TO TABLE only in the MOVE PARTITION branch, so the destination is tied to the part flag. The MOVE_PARTITION validation in ASTAlterCommand::readJSON switched on move_destination_type without consulting part, so both crossed pairs were admitted at the JSON boundary.

part = true with TABLE reached MergeTreeData::getPartitionIDFromQuery, which downcasts the partition slot with as<ASTPartition &>(). Against the part-name ASTLiteral that raised Code: 49 ... Bad cast from type DB::ASTLiteral to DB::ASTPartition as a LOGICAL_ERROR, aborting debug and sanitizer builds. part = false with SHARD formatted MOVE PARTITION 1 TO SHARD 'v', which the SQL parser rejects, so formatQueryFromJSON output and the query text propagated to system.query_log and to Keeper for ON CLUSTER DDL could not be parsed back.

Both shapes now fail closed with BAD_ARGUMENTS, matching the other parser-impossible combinations already validated in the same function. The four parser-produced pairings (PART with DISK/VOLUME/SHARD, PARTITION with DISK/VOLUME/TABLE) are unaffected and still round-trip.

Pre-existing, not a regression: on the parent commit the same payloads were already accepted, and merely formatted different unparseable text.

Regression rows were added to the existing 04350_ast_json_parser_impossible_field_combinations test. Reverting the source change turns both new rows red; restoring it makes the suite pass.

Closes: #114425

Version info

  • Merged into: 26.8.1.1268 (included in 26.8 and later)

ParserAlterQuery accepts TO SHARD only in the MOVE PART branch and TO TABLE
only in the MOVE PARTITION branch, but the MOVE_PARTITION validation in
readJSON checked move_destination_type without consulting the part flag. With
dialect = clickhouse_json both crossed pairs were therefore admitted.

part = true with TABLE reached MergeTreeData::getPartitionIDFromQuery, which
downcasts the partition slot with as<ASTPartition &>(); against the part-name
ASTLiteral that raised

  Code: 49. DB::Exception: Bad cast from type DB::ASTLiteral to DB::ASTPartition

as a LOGICAL_ERROR, aborting debug and sanitizer builds. part = false with
SHARD formatted MOVE PARTITION 1 TO SHARD 'v', which the SQL parser rejects,
so formatQueryFromJSON output and the query text propagated to system.query_log
and to Keeper for ON CLUSTER DDL could not be parsed back.

Both shapes now fail closed with BAD_ARGUMENTS at the deserialization boundary,
like the other parser-impossible combinations validated in the same function.
The four parser-produced pairings are unaffected and still round-trip.

Verified by reverting the source change and confirming both new test rows go
red, then restoring it and confirming the suite passes.
@clickhouse-gh

clickhouse-gh Bot commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [d88abd4]

Summary: ✅


AI Review

Summary

This PR closes the clickhouse_json AST gap where MOVE destinations were validated independently from the part form: TO SHARD is now rejected for MOVE PARTITION, and TO TABLE is now rejected for MOVE PART, directly in ASTAlterCommand::readJSON. The change matches the parser grammar, prevents the downstream ASTLiteral/ASTPartition mismatch described in the issue, and the added regression rows exercise both valid round-trips and both crossed-pair rejections. I did not find a remaining correctness, compatibility, or test-coverage problem in the touched paths.

Final Verdict

✅ Approved

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.70% 86.70% +0.00%
Functions 92.00% 92.00% +0.00%
Branches 79.00% 79.00% +0.00%

Changed lines: Changed C/C++ lines covered: 17/22 (77.27%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Aug 12, 2026
@PedroTadim PedroTadim self-assigned this Aug 12, 2026
@PedroTadim PedroTadim added the can be tested Allows running workflows for external contributors label Aug 12, 2026
@PedroTadim PedroTadim assigned evillique and unassigned PedroTadim Aug 12, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - d88abd4

CI has fully finished on this head with no failures to own. The praktika report is OK at
the top level with 176 leaves, 157 passed and 0 dropped; the 19 skipped jobs all carry a
config reason ("not labeled with 'pr-performance'", "reused from cache", "no integration
tests updates", "not affected by the changed files"), so the matrix was not truncated.
Fast test, Style check, Bugfix validation (functional amd64 + aarch64, unit), every
Stress test arm, every AST fuzzer and BuzzHouse arm all passed.

Check / test Reason Owner / fixing PR
(none) - -

Three CIDB rows for this commit are not failures of this run: Config Workflow / Pre Hooks
and Finish Workflow / Post Hooks at 07:41 and 07:47 UTC belong to workflow attempt 1,
which stopped at the can_be_tested gate before the can be tested label was applied and
was superseded by the successful attempt 2 (Config Workflow OK at 09:01, Finish Workflow
OK at 13:28). Build (arm_release) / Post Hooks is recorded on a check whose own status is
success, and it appears on 780 unrelated pull requests in the last 7 days.

Session id: cron:our-pr-ci-monitor:20260812-140000

@evillique
evillique added this pull request to the merge queue Aug 12, 2026
Merged via the queue into ClickHouse:master with commit 5abf3cd Aug 12, 2026
353 of 356 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

readJSON accepts MOVE PART TO TABLE; execution hits Bad cast to ASTPartition

4 participants