Repository navigation
Fix Inconsistent AST formatting for ALTER TABLE ... MOVE PART ... TO SHARD - #109060
alexey-milovidov merged 5 commits into
Conversation
…SHARD ASTAlterCommand::formatImpl handled the DISK, VOLUME and TABLE move destinations but not SHARD, so "ALTER TABLE x MOVE PART 'p' TO SHARD '/path'" was formatted back as "MOVE PART 'p' TO '/path'" (the SHARD keyword dropped). The formatted query then fails to parse, which trips the AST formatting round-trip consistency check in executeQuery and raises a LOGICAL_ERROR (a handled exception in release, aborts the server in debug and sanitizer builds). Add the missing SHARD case to the formatter so format(parse(q)) == q. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-0:20260701-124000 |
|
cc @evillique @george-larionov could you review? Small parser/formatter fix: |
|
Workflow [PR], commit [3520a9b] Summary: ✅
AI ReviewSummaryThis PR correctly plugs the missing Findings
Final VerdictNeeds one follow-up before merge: close the LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 9/9 (100.00%) · Uncovered code |
CI finish ledger — d23bbfbEvery failure below has an owner: a fixing PR (ours or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only
Session id: cron:our-pr-ci-monitor:20260701-183000 |
|
@groeneai Could you merge the fresh master into this branch? |
…-to-shard-ast-format
|
Merged fresh master into the branch (now at 83a0a65). Diff unchanged: 3 files, +29/-0. CI is re-running. |
CI finish ledger — 83a0a65Every failure below has an owner (a fixing PR). No PR-caused failures.
Session id: cron:our-pr-ci-monitor:20260716-000000 |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 9/9 (100.00%) · Uncovered code |
CI finish ledger - ff10dc5Every failure below has an owner: a fixing PR, or a full-effort fix task whose
Session id: cron:our-pr-ci-monitor:20260729-083000 |
|
@groeneai check test failure and merge the fresh master in |
|
@evillique Merged fresh master in: head is now There was no test failure to check. On the previous head no test ran at all: The diff is unchanged by the merge: still the same 3 files ( |
| case DataDestinationType::VOLUME: | ||
| ostr << "VOLUME "; | ||
| break; | ||
| case DataDestinationType::SHARD: |
There was a problem hiding this comment.
This fixes the SQL formatter branch, but the same invariant is still open on the clickhouse_json carrier. ParserAlterQuery only produces TO SHARD for MOVE PART, yet ASTAlterCommand::readJSON still accepts type = MOVE_PARTITION, part = false, move_destination_type = SHARD in its MOVE_PARTITION validation block. With the new formatter arm here, formatQueryFromJSON now emits ALTER TABLE t (MOVE PARTITION 1 TO SHARD '/path') for that malformed JSON instead of rejecting it, and the JSON dialect can drive it to execution where movePartitionToShard throws NOT_IMPLEMENTED instead of the parser's SYNTAX_ERROR.
Please fail closed in ASTAlterCommand::readJSON when move_destination_type == DataDestinationType::SHARD && !part, and add a regression in the parser-impossible JSON suite (the 04350_ast_json_parser_impossible_field_combinations test looks like the right place).
There was a problem hiding this comment.
Both mechanical claims check out; the causal one does not, so I am not changing this PR.
Confirmed on master: ParserAlterQuery.cpp:526 accepts TO SHARD only in the MOVE PART branch (which sets part = true), and the MOVE_PARTITION switch in readJSON accepts SHARD without testing part.
Measured on pre-fix master (debug build), the formatter arm is not what opens this:
readJSONalready accepts that payload today, andformatQueryFromJSONalready succeeds on it, emittingALTER TABLE x (MOVE PARTITION 1 TO 'v1')- thedefault: breakdrops the keyword rather than rejecting. The new arm changes which non-parseable text is emitted, not whether the payload is accepted.- Neither text parses back:
MOVE PARTITION 1 TO 'v1'andMOVE PARTITION 1 TO SHARD '/path'both giveSYNTAX_ERRORat the same position. - Execution already fails closed before this PR, and does not consult
formatImpl: the payload reachesMergeTreeData::executePartitionCommandand throwsNOT_IMPLEMENTED("MOVE PARTITION TO SHARD is not supported by storage MergeTree"), andStorageReplicatedMergeTree::movePartitionToShardstarts withif (!move_part) throw NOT_IMPLEMENTED. - The debug AST round-trip check lives in the SQL branch of
executeQuery, afterparseQuery; a JSON payload never reaches it, so there is no new abort path.
So this is a pre-existing gap in a sibling carrier, orthogonal to a 3-line formatter fix, and already refused at the storage layer with a different error code. Not raising it separately either: the payload is rejected either way, so there is no wrong-result, data-loss, crash or access-control consequence behind it.
CI finish ledger - 3520a9bEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task This PR's diff is a 3-line AST formatter fix in
Frame-level identity of the hung wait on this run, from I checked the four merged PRs that touch this wait (#97586, #113263, #113504, #107604): all
Session id: cron:our-pr-ci-monitor:20260811-000000 |
|
Fixing PR for the hung |
510b23a
|
@groeneai @alexey-milovidov @evillique — ClickGap found the following in this PR:
Close anything that's wrong or already addressed. |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a spurious
Inconsistent AST formattingerror forALTER TABLE ... MOVE PART ... TO SHARD '<path>'. The query formatter dropped theSHARDkeyword, so the reformatted query could not be parsed back, raising aLOGICAL_ERROR(a handled exception in release builds, an abort in debug and sanitizer builds).Description
The
ASTAlterCommandformatter switched over the move destination type andemitted the keyword for
DISK,VOLUMEandTABLE, but had no case forSHARD. So this query:was formatted back as
ALTER TABLE x (MOVE PART 'p' TO '/path')with theSHARDkeyword dropped. The parser acceptsTO SHARD '<path>'(only forMOVE PART, notMOVE PARTITION), so the reformatted query no longer parses,and the AST formatting round-trip consistency check in
executeQuery(
format(parse(q)) == q) raisedLOGICAL_ERROR: Inconsistent AST formatting.That is a handled exception in release builds, but aborts the server in debug
and sanitizer builds.
The fix adds the missing
SHARDcase toASTAlterCommand::formatImplso thedestination path is emitted with its keyword. The two sibling switches that
consume
move_destination_type(execution inInterpreterAlterQueryand theconversion in
PartitionCommands) already handleSHARDcorrectly; only theformatter was missing it.
Added a stateless regression test (
04342_inconsistent_ast_move_part_to_shard)that asserts the formatted output keeps
SHARD, is stable under a secondround-trip, and that the other move destinations (
DISK,VOLUME,TABLE)still format correctly. It also asserts
MOVE PARTITION ... TO SHARDremains asyntax error, since
SHARDis valid only forMOVE PART.Version info
26.8.1.1184(included in26.8and later)