Skip to content

Fix Accept/Walk field-level drift and InsertStmt End() panic#284

Merged
git-hulk merged 2 commits into
masterfrom
fix/traversal-drift
Jul 5, 2026
Merged

Fix Accept/Walk field-level drift and InsertStmt End() panic#284
git-hulk merged 2 commits into
masterfrom
fix/traversal-drift

Conversation

@git-hulk

@git-hulk git-hulk commented Jul 5, 2026

Copy link
Copy Markdown
Member

Summary

The two traversal engines (Accept/ASTVisitor and Walk) 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 by Accept against the fields referenced by Walk'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.Value

Walk was missing (Accept visited them):
InsertStmt.Values (INSERT ... VALUES rows were never walked!), SelectQuery.Except, WhenClause.Else

Also fixed

  • InsertStmt.End() panicked on INSERT INTO t FORMAT CSV — the most common ClickHouse insert form (data arrives out of band, so Values is empty and SelectExpr nil, and the method indexed Values[len-1] unguarded). It now falls back Format → ColumnNames → Table.
  • InsertStmt.Accept visited Format before Table, violating source order; it now matches Walk's order.
  • DestinationClause.Accept didn't 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).

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.Except walk fix overlaps with #279 (which adds Except+Intersect there for the INTERSECT feature) — whichever merges second has a one-line trivial conflict in walk.go.

🤖 Generated with Claude Code

git-hulk and others added 2 commits July 5, 2026 11:05
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>
@git-hulk
git-hulk merged commit a156969 into master Jul 5, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant