Fix Accept/Walk field-level drift and InsertStmt End() panic#284
Merged
Conversation
The two traversal engines each encode every node's children by hand, and the existing drift test only asserts that both engines know the same node TYPES - it cannot see a child FIELD one engine traverses and the other forgot. A new static test compares, per node type, the fields referenced by Accept against the fields referenced by Walk's case, and it immediately found ten drifted fields: Accept was missing (Walk visited them): - AlterTableDropPartition.Settings - CreateDatabase.Name, CreateDatabase.Comment - CreateTable.Comment - IntervalFrom.Interval - ProjectionOrderByClause.Columns - SelectQuery.DistinctOn - UUID.Value Walk was missing (Accept visited them): - InsertStmt.Values (INSERT ... VALUES rows were never walked) - SelectQuery.Except - WhenClause.Else Also: - InsertStmt.End() panicked on `INSERT INTO t FORMAT CSV`: with the data arriving out of band there are no Values and no SelectExpr, and the method indexed Values[len-1] unguarded. It now falls back to Format, ColumnNames, then Table. - InsertStmt.Accept visited Format before Table, violating source order; it now matches Walk (Table, ColumnNames, Format, Values, SelectExpr). - DestinationClause.Accept did not visit its own TableSchema; CreateMaterializedView.Accept compensated by reaching into its child, so any other DestinationClause holder silently skipped the schema and the visit happened outside the destination's Enter/Leave bracket. The clause now owns its child, and its End() includes the schema. No golden fixture changed. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
# Conflicts: # parser/walk.go
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
The two traversal engines (
Accept/ASTVisitorandWalk) each encode every node's children by hand. The existing drift test (#276) asserts both engines know the same node types — it cannot see a child field that one engine traverses and the other forgot.This PR adds a static field-level drift test (
TestTraversalEnginesVisitSameFields) that compares, per node type, the fields referenced byAcceptagainst the fields referenced byWalk's case arm. It immediately found ten drifted fields:Accept was missing (Walk visited them):
AlterTableDropPartition.Settings,CreateDatabase.Name,CreateDatabase.Comment,CreateTable.Comment,IntervalFrom.Interval,ProjectionOrderByClause.Columns,SelectQuery.DistinctOn,UUID.ValueWalk was missing (Accept visited them):
InsertStmt.Values(INSERT ... VALUES rows were never walked!),SelectQuery.Except,WhenClause.ElseAlso fixed
InsertStmt.End()panicked onINSERT INTO t FORMAT CSV— the most common ClickHouse insert form (data arrives out of band, soValuesis empty andSelectExprnil, and the method indexedValues[len-1]unguarded). It now falls back Format → ColumnNames → Table.InsertStmt.AcceptvisitedFormatbeforeTable, violating source order; it now matches Walk's order.DestinationClause.Acceptdidn't visit its ownTableSchema;CreateMaterializedView.Acceptcompensated by reaching into its child — so any otherDestinationClauseholder silently skipped the schema, and the visit happened outside the destination's Enter/Leave bracket. The clause now owns its child (and itsEnd()includes the schema).Tests
TestTraversalEnginesVisitSameFields— the new static guard; this class of bug can't silently recur.TestInsertStmtEndWithoutValues,TestWalkVisitsInsertValues,TestDestinationTableSchemaVisitedOnce— behavioral regressions.No golden fixture changed.
Note: the
SelectQuery.Exceptwalk fix overlaps with #279 (which addsExcept+Intersectthere for the INTERSECT feature) — whichever merges second has a one-line trivial conflict inwalk.go.🤖 Generated with Claude Code