Repository: AfterShip/clickhouse-sql-parser
Pull request #45 (2024-02-09 07:42:52)

Implement visitor for AST 
resolve https://github.com/AfterShip/clickhouse-sql-parser/issues/8

zfy0701: there are several ways to implement visitor pattern, this is my preference but I'm happy to implement this as your team feels right
git-hulk: @zfy0701 Thanks for your great contribution.

The current visitor pattern looks good to me. I will take another pass before merging.
coveralls: ## Pull Request Test Coverage Report for [Build 7846240644](https://coveralls.io/builds/65610906)


* **-1188** of **2242**   **(47.01%)**  changed or added relevant lines in **2** files are covered.
* No unchanged relevant lines lost coverage.
* Overall coverage decreased (**-2.8%**) to **56.416%**

---

|  Changes Missing Coverage | Covered Lines | Changed/Added Lines | % |
| :-----|--------------|--------|---: |
| [parser/ast_visitor.go](https://coveralls.io/builds/65610906/source?filename=parser%2Fast_visitor.go#L157) | 314 | 712 | 44.1%
| [parser/ast.go](https://coveralls.io/builds/65610906/source?filename=parser%2Fast.go#L44) | 740 | 1530 | 48.37%
<!-- | **Total:** | **1054** | **2242** | **47.01%** | -->


|  Totals | [![Coverage Status](https://coveralls.io/builds/65610906/badge)](https://coveralls.io/builds/65610906) |
| :-- | --: |
| Change from base [Build 7794018411](https://coveralls.io/builds/65518744): |  -2.8% |
| Covered Lines: | 5430 |
| Relevant Lines: | 9625 |

---
##### 💛  - [Coveralls](https://coveralls.io)

zfy0701: done

Patch:
diff --git a/parser/ast.go b/parser/ast.go
index 04b3675..93493d0 100644
--- a/parser/ast.go
+++ b/parser/ast.go
@@ -16,6 +16,7 @@ type Expr interface {
 	Pos() Pos
 	End() Pos
 	String(level int) string
+	Accept(visitor ASTVisitor) error
 }
 
 type DDL interface {
@@ -40,6 +41,12 @@ func (o *OperationExpr) String(int) string {
 	return strings.ToUpper(string(o.Kind))
 }
 
+func (o *OperationExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(o)
+	defer visitor.leave(o)
+	return visitor.VisitOperationExpr(o)
+}
+
 type TernaryExpr struct {
 	Condition Expr
 	TrueExpr  Expr
@@ -64,6 +71,21 @@ func (t *TernaryExpr) String(level int) string {
 	return builder.String()
 }
 
+func (t *TernaryExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(t)
+	defer visitor.leave(t)
+	if err := t.TrueExpr.Accept(visitor); err != nil {
+		return err
+	}
+	if err := t.FalseExpr.Accept(visitor); err != nil {
+		return err
+	}
+	if err := t.Condition.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitTernaryExpr(t)
+}
+
 type BinaryExpr struct {
 	LeftExpr  Expr
 	Operation TokenKind
@@ -95,6 +117,18 @@ func (p *BinaryExpr) String(level int) string {
 	return builder.String()
 }
 
+func (p *BinaryExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(p)
+	defer visitor.leave(p)
+	if err := p.LeftExpr.Accept(visitor); err != nil {
+		return err
+	}
+	if err := p.RightExpr.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitBinaryExpr(p)
+}
+
 type AlterTableExpr interface {
 	Expr
 	AlterType() string
@@ -138,6 +172,23 @@ func (a *AlterTable) String(level int) string {
 	return builder.String()
 }
 
+func (a *AlterTable) Accept(visitor ASTVisitor) error {
+	visitor.enter(a)
+	defer visitor.leave(a)
+	if a.OnCluster != nil {
+		if err := a.OnCluster.Accept(visitor); err != nil {
+			return err
+		}
+	}
+
+	for _, expr := range a.AlterExprs {
+		if err := expr.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitAlterTable(a)
+}
+
 type AlterTableAttachPartition struct {
 	AttachPos Pos
 
@@ -171,6 +222,20 @@ func (a *AlterTableAttachPartition) String(level int) string {
 	return builder.String()
 }
 
+func (a *AlterTableAttachPartition) Accept(visitor ASTVisitor) error {
+	visitor.enter(a)
+	defer visitor.leave(a)
+	if err := a.Partition.Accept(visitor); err != nil {
+		return err
+	}
+	if a.From != nil {
+		if err := a.From.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitAlterTableAttachPartition(a)
+}
+
 type AlterTableDetachPartition struct {
 	DetachPos Pos
 	Partition *PartitionExpr
@@ -200,6 +265,20 @@ func (a *AlterTableDetachPartition) String(level int) string {
 	return builder.String()
 }
 
+func (a *AlterTableDetachPartition) Accept(visitor ASTVisitor) error {
+	visitor.enter(a)
+	defer visitor.leave(a)
+	if err := a.Partition.Accept(visitor); err != nil {
+		return err
+	}
+	if a.Settings != nil {
+		if err := a.Settings.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitAlterTableDetachPartition(a)
+}
+
 type AlterTableDropPartition struct {
 	DropPos   Pos
 	Partition *PartitionExpr
@@ -224,6 +303,15 @@ func (a *AlterTableDropPartition) String(level int) string {
 	return builder.String()
 }
 
+func (a *AlterTableDropPartition) Accept(visitor ASTVisitor) error {
+	visitor.enter(a)
+	defer visitor.leave(a)
+	if err := a.Partition.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitAlterTableDropPartition(a)
+}
+
 type AlterTableFreezePartition struct {
 	FreezePos    Pos
 	StatementEnd Pos
@@ -252,6 +340,17 @@ func (a *AlterTableFreezePartition) String(level int) string {
 	return builder.String()
 }
 
+func (a *AlterTableFreezePartition) Accept(visitor ASTVisitor) error {
+	visitor.enter(a)
+	defer visitor.leave(a)
+	if a.Partition != nil {
+		if err := a.Partition.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitAlterTableFreezePartition(a)
+}
+
 type AlterTableAddColumn struct {
 	AddPos       Pos
 	StatementEnd Pos
@@ -287,6 +386,20 @@ func (a *AlterTableAddColumn) String(level int) string {
 	return builder.String()
 }
 
+func (a *AlterTableAddColumn) Accept(visitor ASTVisitor) error {
+	visitor.enter(a)
+	defer visitor.leave(a)
+	if err := a.Column.Accept(visitor); err != nil {
+		return err
+	}
+	if a.After != nil {
+		if err := a.After.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitAlterTableAddColumn(a)
+}
+
 type AlterTableAddIndex struct {
 	AddPos       Pos
 	StatementEnd Pos
@@ -322,6 +435,20 @@ func (a *AlterTableAddIndex) String(level int) string {
 	return builder.String()
 }
 
+func (a *AlterTableAddIndex) Accept(visitor ASTVisitor) error {
+	visitor.enter(a)
+	defer visitor.leave(a)
+	if err := a.Index.Accept(visitor); err != nil {
+		return err
+	}
+	if a.After != nil {
+		if err := a.After.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitAlterTableAddIndex(a)
+}
+
 type AlterTableDropColumn struct {
 	DropPos    Pos
 	ColumnName *NestedIdentifier
@@ -350,6 +477,15 @@ func (a *AlterTableDropColumn) String(level int) string {
 	return builder.String()
 }
 
+func (a *AlterTableDropColumn) Accept(visitor ASTVisitor) error {
+	visitor.enter(a)
+	defer visitor.leave(a)
+	if err := a.ColumnName.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitAlterTableDropColumn(a)
+}
+
 type AlterTableDropIndex struct {
 	DropPos   Pos
 	IndexName *NestedIdentifier
@@ -378,6 +514,15 @@ func (a *AlterTableDropIndex) String(level int) string {
 	return builder.String()
 }
 
+func (a *AlterTableDropIndex) Accept(visitor ASTVisitor) error {
+	visitor.enter(a)
+	defer visitor.leave(a)
+	if err := a.IndexName.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitAlterTableDropIndex(a)
+}
+
 type AlterTableRemoveTTL struct {
 	RemovePos    Pos
 	StatementEnd Pos
@@ -399,6 +544,12 @@ func (a *AlterTableRemoveTTL) String(level int) string {
 	return "REMOVE TTL"
 }
 
+func (a *AlterTableRemoveTTL) Accept(visitor ASTVisitor) error {
+	visitor.enter(a)
+	defer visitor.leave(a)
+	return visitor.VisitAlterTableRemoveTTL(a)
+}
+
 type AlterTableClearColumn struct {
 	ClearPos     Pos
 	StatementEnd Pos
@@ -436,6 +587,20 @@ func (a *AlterTableClearColumn) String(level int) string {
 	return builder.String()
 }
 
+func (a *AlterTableClearColumn) Accept(visitor ASTVisitor) error {
+	visitor.enter(a)
+	defer visitor.leave(a)
+	if err := a.ColumnName.Accept(visitor); err != nil {
+		return err
+	}
+	if a.PartitionExpr != nil {
+		if err := a.PartitionExpr.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitAlterTableClearColumn(a)
+}
+
 type AlterTableClearIndex struct {
 	ClearPos     Pos
 	StatementEnd Pos
@@ -473,6 +638,20 @@ func (a *AlterTableClearIndex) String(level int) string {
 	return builder.String()
 }
 
+func (a *AlterTableClearIndex) Accept(visitor ASTVisitor) error {
+	visitor.enter(a)
+	defer visitor.leave(a)
+	if err := a.IndexName.Accept(visitor); err != nil {
+		return err
+	}
+	if a.PartitionExpr != nil {
+		if err := a.PartitionExpr.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitAlterTableClearIndex(a)
+}
+
 type AlterTableRenameColumn struct {
 	RenamePos Pos
 
@@ -505,6 +684,18 @@ func (a *AlterTableRenameColumn) String(level int) string {
 	return builder.String()
 }
 
+func (a *AlterTableRenameColumn) Accept(visitor ASTVisitor) error {
+	visitor.enter(a)
+	defer visitor.leave(a)
+	if err := a.OldColumnName.Accept(visitor); err != nil {
+		return err
+	}
+	if err := a.NewColumnName.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitAlterTableRenameColumn(a)
+}
+
 type AlterTableModifyTTL struct {
 	ModifyPos    Pos
 	StatementEnd Pos
@@ -531,6 +722,15 @@ func (a *AlterTableModifyTTL) String(level int) string {
 	return builder.String()
 }
 
+func (a *AlterTableModifyTTL) Accept(visitor ASTVisitor) error {
+	visitor.enter(a)
+	defer visitor.leave(a)
+	if err := a.TTL.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitAlterTableModifyTTL(a)
+}
+
 type AlterTableModifyColumn struct {
 	ModifyPos    Pos
 	StatementEnd Pos
@@ -565,6 +765,20 @@ func (a *AlterTableModifyColumn) String(level int) string {
 	return builder.String()
 }
 
+func (a *AlterTableModifyColumn) Accept(visitor ASTVisitor) error {
+	visitor.enter(a)
+	defer visitor.leave(a)
+	if err := a.Column.Accept(visitor); err != nil {
+		return err
+	}
+	if a.RemovePropertyType != nil {
+		if err := a.RemovePropertyType.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitAlterTableModifyColumn(a)
+}
+
 type AlterTableReplacePartition struct {
 	ReplacePos Pos
 	Partition  *PartitionExpr
@@ -592,6 +806,18 @@ func (a *AlterTableReplacePartition) String(level int) string {
 	return builder.String()
 }
 
+func (a *AlterTableReplacePartition) Accept(visitor ASTVisitor) error {
+	visitor.enter(a)
+	defer visitor.leave(a)
+	if err := a.Partition.Accept(visitor); err != nil {
+		return err
+	}
+	if err := a.Table.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitAlterTableReplacePartition(a)
+}
+
 type RemovePropertyType struct {
 	RemovePos Pos
 
@@ -613,6 +839,15 @@ func (a *RemovePropertyType) String(level int) string {
 	return builder.String()
 }
 
+func (a *RemovePropertyType) Accept(visitor ASTVisitor) error {
+	visitor.enter(a)
+	defer visitor.leave(a)
+	if err := a.PropertyType.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitRemovePropertyType(a)
+}
+
 type TableIndex struct {
 	IndexPos Pos
 
@@ -644,6 +879,24 @@ func (a *TableIndex) String(level int) string {
 	return builder.String()
 }
 
+func (a *TableIndex) Accept(visitor ASTVisitor) error {
+	visitor.enter(a)
+	defer visitor.leave(a)
+	if err := a.Name.Accept(visitor); err != nil {
+		return err
+	}
+	if err := a.ColumnExpr.Accept(visitor); err != nil {
+		return err
+	}
+	if err := a.ColumnType.Accept(visitor); err != nil {
+		return err
+	}
+	if err := a.Granularity.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitTableIndex(a)
+}
+
 type Ident struct {
 	Name     string
 	Unquoted bool
@@ -666,6 +919,12 @@ func (i *Ident) String(int) string {
 	return i.Name
 }
 
+func (i *Ident) Accept(visitor ASTVisitor) error {
+	visitor.enter(i)
+	defer visitor.leave(i)
+	return visitor.VisitIdent(i)
+}
+
 type UUID struct {
 	Value *StringLiteral
 }
@@ -682,6 +941,12 @@ func (u *UUID) String(level int) string {
 	return "UUID " + u.Value.String(level)
 }
 
+func (u *UUID) Accept(visitor ASTVisitor) error {
+	visitor.enter(u)
+	defer visitor.leave(u)
+	return visitor.VisitUUID(u)
+}
+
 type CreateDatabase struct {
 	CreatePos    Pos // position of CREATE keyword
 	StatementEnd Pos
@@ -721,6 +986,22 @@ func (c *CreateDatabase) String(level int) string {
 	return builder.String()
 }
 
+func (c *CreateDatabase) Accept(visitor ASTVisitor) error {
+	visitor.enter(c)
+	defer visitor.leave(c)
+	if c.OnCluster != nil {
+		if err := c.OnCluster.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if c.Engine != nil {
+		if err := c.Engine.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitCreateDatabase(c)
+}
+
 type CreateTable struct {
 	CreatePos    Pos // position of CREATE|ATTACH keyword
 	StatementEnd Pos
@@ -778,6 +1059,37 @@ func (c *CreateTable) String(level int) string {
 	return builder.String()
 }
 
+func (c *CreateTable) Accept(visitor ASTVisitor) error {
+	visitor.enter(c)
+	defer visitor.leave(c)
+	if c.UUID != nil {
+		if err := c.UUID.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if c.OnCluster != nil {
+		if err := c.OnCluster.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if c.TableSchema != nil {
+		if err := c.TableSchema.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if c.Engine != nil {
+		if err := c.Engine.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if c.SubQuery != nil {
+		if err := c.SubQuery.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitCreateTable(c)
+}
+
 type CreateMaterializedView struct {
 	CreatePos    Pos // position of CREATE|ATTACH keyword
 	StatementEnd Pos
@@ -836,6 +1148,45 @@ func (c *CreateMaterializedView) String(level int) string {
 	return builder.String()
 }
 
+func (c *CreateMaterializedView) Accept(visitor ASTVisitor) error {
+	visitor.enter(c)
+	defer visitor.leave(c)
+	if err := c.Name.Accept(visitor); err != nil {
+		return err
+	}
+	if c.UUID != nil {
+		if err := c.UUID.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if c.OnCluster != nil {
+		if err := c.OnCluster.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if c.TableSchema != nil {
+		if err := c.TableSchema.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if c.Engine != nil {
+		if err := c.Engine.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if c.Destination != nil {
+		if err := c.Destination.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if c.SubQuery != nil {
+		if err := c.SubQuery.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitCreateMaterializedView(c)
+}
+
 type CreateView struct {
 	CreatePos    Pos // position of CREATE|ATTACH keyword
 	StatementEnd Pos
@@ -887,6 +1238,35 @@ func (c *CreateView) String(level int) string {
 	return builder.String()
 }
 
+func (c *CreateView) Accept(visitor ASTVisitor) error {
+	visitor.enter(c)
+	defer visitor.leave(c)
+	if err := c.Name.Accept(visitor); err != nil {
+		return err
+	}
+	if c.UUID != nil {
+		if err := c.UUID.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if c.OnCluster != nil {
+		if err := c.OnCluster.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if c.TableSchema != nil {
+		if err := c.TableSchema.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if c.SubQuery != nil {
+		if err := c.SubQuery.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitCreateView(c)
+}
+
 type CreateFunction struct {
 	CreatePos    Pos
 	IfNotExists  bool
@@ -926,6 +1306,26 @@ func (c *CreateFunction) String(level int) string {
 	return builder.String()
 }
 
+func (c *CreateFunction) Accept(visitor ASTVisitor) error {
+	visitor.enter(c)
+	defer visitor.leave(c)
+	if err := c.FunctionName.Accept(visitor); err != nil {
+		return err
+	}
+	if c.OnCluster != nil {
+		if err := c.OnCluster.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if err := c.Params.Accept(visitor); err != nil {
+		return err
+	}
+	if err := c.Expr.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitCreateFunction(c)
+}
+
 type RoleName struct {
 	Name      Expr
 	Scope     *StringLiteral
@@ -960,6 +1360,25 @@ func (r *RoleName) String(level int) string {
 	return builder.String()
 }
 
+func (r *RoleName) Accept(visitor ASTVisitor) error {
+	visitor.enter(r)
+	defer visitor.leave(r)
+	if err := r.Name.Accept(visitor); err != nil {
+		return err
+	}
+	if r.Scope != nil {
+		if err := r.Scope.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if r.OnCluster != nil {
+		if err := r.OnCluster.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitRoleName(r)
+}
+
 type SettingPair struct {
 	Name  *Ident
 	Value Expr
@@ -983,6 +1402,20 @@ func (s *SettingPair) String(level int) string {
 	return builder.String()
 }
 
+func (s *SettingPair) Accept(visitor ASTVisitor) error {
+	visitor.enter(s)
+	defer visitor.leave(s)
+	if err := s.Name.Accept(visitor); err != nil {
+		return err
+	}
+	if s.Value != nil {
+		if err := s.Value.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitSettingPair(s)
+}
+
 type RoleSetting struct {
 	SettingPairs []*SettingPair
 	Modifier     *Ident
@@ -1017,6 +1450,22 @@ func (r *RoleSetting) String(level int) string {
 	return builder.String()
 }
 
+func (r *RoleSetting) Accept(visitor ASTVisitor) error {
+	visitor.enter(r)
+	defer visitor.leave(r)
+	for _, settingPair := range r.SettingPairs {
+		if err := settingPair.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if r.Modifier != nil {
+		if err := r.Modifier.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitRoleSetting(r)
+}
+
 type CreateRole struct {
 	CreatePos         Pos
 	StatementEnd      Pos
@@ -1071,6 +1520,27 @@ func (c *CreateRole) String(level int) string {
 	return builder.String()
 }
 
+func (c *CreateRole) Accept(visitor ASTVisitor) error {
+	visitor.enter(c)
+	defer visitor.leave(c)
+	for _, roleName := range c.RoleNames {
+		if err := roleName.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if c.AccessStorageType != nil {
+		if err := c.AccessStorageType.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	for _, setting := range c.Settings {
+		if err := setting.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitCreateRole(c)
+}
+
 type AlterRole struct {
 	AlterPos        Pos
 	StatementEnd    Pos
@@ -1115,6 +1585,22 @@ func (a *AlterRole) String(level int) string {
 	return builder.String()
 }
 
+func (a *AlterRole) Accept(visitor ASTVisitor) error {
+	visitor.enter(a)
+	defer visitor.leave(a)
+	for _, roleRenamePair := range a.RoleRenamePairs {
+		if err := roleRenamePair.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	for _, setting := range a.Settings {
+		if err := setting.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitAlterRole(a)
+}
+
 type RoleRenamePair struct {
 	RoleName     *RoleName
 	NewName      Expr
@@ -1139,6 +1625,20 @@ func (r *RoleRenamePair) String(level int) string {
 	return builder.String()
 }
 
+func (r *RoleRenamePair) Accept(visitor ASTVisitor) error {
+	visitor.enter(r)
+	defer visitor.leave(r)
+	if err := r.RoleName.Accept(visitor); err != nil {
+		return err
+	}
+	if r.NewName != nil {
+		if err := r.NewName.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitRoleRenamePair(r)
+}
+
 type DestinationExpr struct {
 	ToPos           Pos
 	TableIdentifier *TableIdentifier
@@ -1159,6 +1659,15 @@ func (d *DestinationExpr) String(level int) string {
 	return builder.String()
 }
 
+func (d *DestinationExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(d)
+	defer visitor.leave(d)
+	if err := d.TableIdentifier.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitDestinationExpr(d)
+}
+
 type ConstraintExpr struct {
 	ConstraintPos Pos
 	Constraint    *Ident
@@ -1181,6 +1690,18 @@ func (c *ConstraintExpr) String(level int) string {
 	return builder.String()
 }
 
+func (c *ConstraintExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(c)
+	defer visitor.leave(c)
+	if err := c.Constraint.Accept(visitor); err != nil {
+		return err
+	}
+	if err := c.Expr.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitConstraintExpr(c)
+}
+
 type NullLiteral struct {
 	NullPos Pos
 }
@@ -1197,6 +1718,12 @@ func (n *NullLiteral) String(int) string {
 	return "NULL"
 }
 
+func (n *NullLiteral) Accept(visitor ASTVisitor) error {
+	visitor.enter(n)
+	defer visitor.leave(n)
+	return visitor.VisitNullLiteral(n)
+}
+
 type NotNullLiteral struct {
 	NotPos      Pos
 	NullLiteral *NullLiteral
@@ -1214,6 +1741,15 @@ func (n *NotNullLiteral) String(int) string {
 	return "NOT NULL"
 }
 
+func (n *NotNullLiteral) Accept(visitor ASTVisitor) error {
+	visitor.enter(n)
+	defer visitor.leave(n)
+	if err := n.NullLiteral.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitNotNullLiteral(n)
+}
+
 type NestedIdentifier struct {
 	Ident    *Ident
 	DotIdent *Ident
@@ -1237,6 +1773,20 @@ func (n *NestedIdentifier) String(int) string {
 	return n.Ident.String(0)
 }
 
+func (n *NestedIdentifier) Accept(visitor ASTVisitor) error {
+	visitor.enter(n)
+	defer visitor.leave(n)
+	if err := n.Ident.Accept(visitor); err != nil {
+		return err
+	}
+	if n.DotIdent != nil {
+		if err := n.DotIdent.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitNestedIdentifier(n)
+}
+
 type ColumnIdentifier struct {
 	Database *Ident
 	Table    *Ident
@@ -1267,6 +1817,25 @@ func (c *ColumnIdentifier) String(int) string {
 	}
 }
 
+func (c *ColumnIdentifier) Accept(visitor ASTVisitor) error {
+	visitor.enter(c)
+	defer visitor.leave(c)
+	if c.Database != nil {
+		if err := c.Database.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if c.Table != nil {
+		if err := c.Table.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if err := c.Column.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitColumnIdentifier(c)
+}
+
 type TableIdentifier struct {
 	Database *Ident
 	Table    *Ident
@@ -1290,6 +1859,20 @@ func (t *TableIdentifier) String(int) string {
 	return t.Table.String(0)
 }
 
+func (t *TableIdentifier) Accept(visitor ASTVisitor) error {
+	visitor.enter(t)
+	defer visitor.leave(t)
+	if t.Database != nil {
+		if err := t.Database.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if err := t.Table.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitTableIdentifier(t)
+}
+
 type TableSchemaExpr struct {
 	SchemaPos     Pos
 	SchemaEnd     Pos
@@ -1331,6 +1914,27 @@ func (t *TableSchemaExpr) String(level int) string {
 	return builder.String()
 }
 
+func (t *TableSchemaExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(t)
+	defer visitor.leave(t)
+	for _, column := range t.Columns {
+		if err := column.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if t.AliasTable != nil {
+		if err := t.AliasTable.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if t.TableFunction != nil {
+		if err := t.TableFunction.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitTableSchemaExpr(t)
+}
+
 type TableArgListExpr struct {
 	LeftParenPos  Pos
 	RightParenPos Pos
@@ -1358,7 +1962,18 @@ func (t *TableArgListExpr) String(level int) string {
 	return builder.String()
 }
 
-type TableFunctionExpr struct {
+func (t *TableArgListExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(t)
+	defer visitor.leave(t)
+	for _, arg := range t.Args {
+		if err := arg.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitTableArgListExpr(t)
+}
+
+type TableFunctionExpr struct {
 	Name *Ident
 	Args *TableArgListExpr
 }
@@ -1378,6 +1993,18 @@ func (t *TableFunctionExpr) String(level int) string {
 	return builder.String()
 }
 
+func (t *TableFunctionExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(t)
+	defer visitor.leave(t)
+	if err := t.Name.Accept(visitor); err != nil {
+		return err
+	}
+	if err := t.Args.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitTableFunctionExpr(t)
+}
+
 type OnClusterExpr struct {
 	OnPos Pos
 	Expr  Expr
@@ -1398,6 +2025,15 @@ func (o *OnClusterExpr) String(level int) string {
 	return builder.String()
 }
 
+func (o *OnClusterExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(o)
+	defer visitor.leave(o)
+	if err := o.Expr.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitOnClusterExpr(o)
+}
+
 type DefaultExpr struct {
 	DefaultPos Pos
 	Expr       Expr
@@ -1418,6 +2054,15 @@ func (d *DefaultExpr) String(level int) string {
 	return builder.String()
 }
 
+func (d *DefaultExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(d)
+	defer visitor.leave(d)
+	if err := d.Expr.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitDefaultExpr(d)
+}
+
 type PartitionExpr struct {
 	PartitionPos Pos
 	Expr         Expr
@@ -1449,6 +2094,22 @@ func (p *PartitionExpr) String(level int) string {
 	return builder.String()
 }
 
+func (p *PartitionExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(p)
+	defer visitor.leave(p)
+	if p.Expr != nil {
+		if err := p.Expr.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if p.ID != nil {
+		if err := p.ID.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitPartitionExpr(p)
+}
+
 type PartitionByExpr struct {
 	PartitionPos Pos
 	Expr         Expr
@@ -1469,6 +2130,15 @@ func (p *PartitionByExpr) String(level int) string {
 	return builder.String()
 }
 
+func (p *PartitionByExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(p)
+	defer visitor.leave(p)
+	if err := p.Expr.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitPartitionByExpr(p)
+}
+
 type PrimaryKeyExpr struct {
 	PrimaryPos Pos
 	Expr       Expr
@@ -1489,6 +2159,15 @@ func (p *PrimaryKeyExpr) String(level int) string {
 	return builder.String()
 }
 
+func (p *PrimaryKeyExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(p)
+	defer visitor.leave(p)
+	if err := p.Expr.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitPrimaryKeyExpr(p)
+}
+
 type SampleByExpr struct {
 	SamplePos Pos
 	Expr      Expr
@@ -1509,6 +2188,15 @@ func (s *SampleByExpr) String(level int) string {
 	return builder.String()
 }
 
+func (s *SampleByExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(s)
+	defer visitor.leave(s)
+	if err := s.Expr.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitSampleByExpr(s)
+}
+
 type TTLExpr struct {
 	TTLPos Pos
 	Expr   Expr
@@ -1528,6 +2216,15 @@ func (t *TTLExpr) String(level int) string {
 	return builder.String()
 }
 
+func (t *TTLExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(t)
+	defer visitor.leave(t)
+	if err := t.Expr.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitTTLExpr(t)
+}
+
 type TTLExprList struct {
 	TTLPos  Pos
 	ListEnd Pos
@@ -1554,6 +2251,17 @@ func (t *TTLExprList) String(level int) string {
 	return builder.String()
 }
 
+func (t *TTLExprList) Accept(visitor ASTVisitor) error {
+	visitor.enter(t)
+	defer visitor.leave(t)
+	for _, item := range t.Items {
+		if err := item.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitTTLExprList(t)
+}
+
 type OrderByExpr struct {
 	OrderPos  Pos
 	Expr      Expr
@@ -1578,6 +2286,15 @@ func (o *OrderByExpr) String(level int) string {
 	return builder.String()
 }
 
+func (o *OrderByExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(o)
+	defer visitor.leave(o)
+	if err := o.Expr.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitOrderByExpr(o)
+}
+
 type OrderByListExpr struct {
 	OrderPos Pos
 	ListEnd  Pos
@@ -1605,6 +2322,17 @@ func (o *OrderByListExpr) String(level int) string {
 	return builder.String()
 }
 
+func (o *OrderByListExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(o)
+	defer visitor.leave(o)
+	for _, item := range o.Items {
+		if err := item.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitOrderByListExpr(o)
+}
+
 type SettingsExpr struct {
 	SettingsPos Pos
 	Name        *Ident
@@ -1627,6 +2355,18 @@ func (s *SettingsExpr) String(level int) string {
 	return builder.String()
 }
 
+func (s *SettingsExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(s)
+	defer visitor.leave(s)
+	if err := s.Name.Accept(visitor); err != nil {
+		return err
+	}
+	if err := s.Expr.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitSettingsExpr(s)
+}
+
 type SettingsExprList struct {
 	SettingsPos Pos
 	ListEnd     Pos
@@ -1653,6 +2393,17 @@ func (s *SettingsExprList) String(level int) string {
 	return builder.String()
 }
 
+func (s *SettingsExprList) Accept(visitor ASTVisitor) error {
+	visitor.enter(s)
+	defer visitor.leave(s)
+	for _, item := range s.Items {
+		if err := item.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitSettingsExprList(s)
+}
+
 type ParamExprList struct {
 	LeftParenPos  Pos
 	RightParenPos Pos
@@ -1681,6 +2432,20 @@ func (f *ParamExprList) String(level int) string {
 	return builder.String()
 }
 
+func (f *ParamExprList) Accept(visitor ASTVisitor) error {
+	visitor.enter(f)
+	defer visitor.leave(f)
+	if err := f.Items.Accept(visitor); err != nil {
+		return err
+	}
+	if f.ColumnArgList != nil {
+		if err := f.ColumnArgList.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitParamExprList(f)
+}
+
 type ArrayParamList struct {
 	LeftBracketPos  Pos
 	RightBracketPos Pos
@@ -1708,6 +2473,15 @@ func (a *ArrayParamList) String(level int) string {
 	return builder.String()
 }
 
+func (a *ArrayParamList) Accept(visitor ASTVisitor) error {
+	visitor.enter(a)
+	defer visitor.leave(a)
+	if err := a.Items.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitArrayParamList(a)
+}
+
 type ObjectParams struct {
 	Object Expr
 	Params *ArrayParamList
@@ -1728,6 +2502,18 @@ func (o *ObjectParams) String(level int) string {
 	return builder.String()
 }
 
+func (o *ObjectParams) Accept(visitor ASTVisitor) error {
+	visitor.enter(o)
+	defer visitor.leave(o)
+	if err := o.Object.Accept(visitor); err != nil {
+		return err
+	}
+	if err := o.Params.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitObjectParams(o)
+}
+
 type FunctionExpr struct {
 	Name   *Ident
 	Params *ParamExprList
@@ -1748,6 +2534,18 @@ func (f *FunctionExpr) String(level int) string {
 	return builder.String()
 }
 
+func (f *FunctionExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(f)
+	defer visitor.leave(f)
+	if err := f.Name.Accept(visitor); err != nil {
+		return err
+	}
+	if err := f.Params.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitFunctionExpr(f)
+}
+
 type WindowFunctionExpr struct {
 	Function *FunctionExpr
 	OverPos  Pos
@@ -1770,6 +2568,18 @@ func (w *WindowFunctionExpr) String(level int) string {
 	return builder.String()
 }
 
+func (w *WindowFunctionExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(w)
+	defer visitor.leave(w)
+	if err := w.Function.Accept(visitor); err != nil {
+		return err
+	}
+	if err := w.OverExpr.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitWindowFunctionExpr(w)
+}
+
 type Column struct {
 	NamePos   Pos
 	ColumnEnd Pos
@@ -1826,6 +2636,50 @@ func (c *Column) String(level int) string {
 	return builder.String()
 }
 
+func (c *Column) Accept(visitor ASTVisitor) error {
+	visitor.enter(c)
+	defer visitor.leave(c)
+	if err := c.Name.Accept(visitor); err != nil {
+		return err
+	}
+	if c.Type != nil {
+		if err := c.Type.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if c.NotNull != nil {
+		if err := c.NotNull.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if c.Nullable != nil {
+		if err := c.Nullable.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if c.Property != nil {
+		if err := c.Property.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if c.Codec != nil {
+		if err := c.Codec.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if c.TTL != nil {
+		if err := c.TTL.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if c.Comment != nil {
+		if err := c.Comment.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitColumn(c)
+}
+
 type ScalarTypeExpr struct {
 	Name *Ident
 }
@@ -1842,6 +2696,15 @@ func (s *ScalarTypeExpr) String(level int) string {
 	return s.Name.String(level + 1)
 }
 
+func (s *ScalarTypeExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(s)
+	defer visitor.leave(s)
+	if err := s.Name.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitScalarTypeExpr(s)
+}
+
 type PropertyTypeExpr struct {
 	Name *Ident
 }
@@ -1858,6 +2721,15 @@ func (c *PropertyTypeExpr) String(level int) string {
 	return c.Name.String(level + 1)
 }
 
+func (c *PropertyTypeExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(c)
+	defer visitor.leave(c)
+	if err := c.Name.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitPropertyTypeExpr(c)
+}
+
 type TypeWithParamsExpr struct {
 	LeftParenPos  Pos
 	RightParenPos Pos
@@ -1887,6 +2759,20 @@ func (s *TypeWithParamsExpr) String(level int) string {
 	return builder.String()
 }
 
+func (s *TypeWithParamsExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(s)
+	defer visitor.leave(s)
+	if err := s.Name.Accept(visitor); err != nil {
+		return err
+	}
+	for _, param := range s.Params {
+		if err := param.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitTypeWithParamsExpr(s)
+}
+
 type ComplexTypeExpr struct {
 	LeftParenPos  Pos
 	RightParenPos Pos
@@ -1916,6 +2802,20 @@ func (c *ComplexTypeExpr) String(level int) string {
 	return builder.String()
 }
 
+func (c *ComplexTypeExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(c)
+	defer visitor.leave(c)
+	if err := c.Name.Accept(visitor); err != nil {
+		return err
+	}
+	for _, param := range c.Params {
+		if err := param.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitComplexTypeExpr(c)
+}
+
 type NestedTypeExpr struct {
 	LeftParenPos  Pos
 	RightParenPos Pos
@@ -1948,6 +2848,20 @@ func (n *NestedTypeExpr) String(level int) string {
 	return builder.String()
 }
 
+func (n *NestedTypeExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(n)
+	defer visitor.leave(n)
+	if err := n.Name.Accept(visitor); err != nil {
+		return err
+	}
+	for _, column := range n.Columns {
+		if err := column.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitNestedTypeExpr(n)
+}
+
 type CompressionCodec struct {
 	CodecPos      Pos
 	RightParenPos Pos
@@ -1976,6 +2890,20 @@ func (c *CompressionCodec) String(level int) string {
 	return builder.String()
 }
 
+func (c *CompressionCodec) Accept(visitor ASTVisitor) error {
+	visitor.enter(c)
+	defer visitor.leave(c)
+	if err := c.Name.Accept(visitor); err != nil {
+		return err
+	}
+	if c.Level != nil {
+		if err := c.Level.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitCompressionCodec(c)
+}
+
 type Literal interface {
 	Expr
 }
@@ -1999,6 +2927,12 @@ func (n *NumberLiteral) String(int) string {
 	return n.Literal
 }
 
+func (n *NumberLiteral) Accept(visitor ASTVisitor) error {
+	visitor.enter(n)
+	defer visitor.leave(n)
+	return visitor.VisitNumberLiteral(n)
+}
+
 type StringLiteral struct {
 	LiteralPos Pos
 	LiteralEnd Pos
@@ -2017,6 +2951,12 @@ func (s *StringLiteral) String(int) string {
 	return "'" + s.Literal + "'"
 }
 
+func (s *StringLiteral) Accept(visitor ASTVisitor) error {
+	visitor.enter(s)
+	defer visitor.leave(s)
+	return visitor.VisitStringLiteral(s)
+}
+
 type RatioExpr struct {
 	Numerator *NumberLiteral
 	// numberLiteral (SLASH numberLiteral)?
@@ -2044,6 +2984,20 @@ func (r *RatioExpr) String(int) string {
 	return builder.String()
 }
 
+func (r *RatioExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(r)
+	defer visitor.leave(r)
+	if err := r.Numerator.Accept(visitor); err != nil {
+		return err
+	}
+	if r.Denominator != nil {
+		if err := r.Denominator.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitRatioExpr(r)
+}
+
 type EnumValueExpr struct {
 	Name  *StringLiteral
 	Value *NumberLiteral
@@ -2065,6 +3019,18 @@ func (e *EnumValueExpr) String(level int) string {
 	return builder.String()
 }
 
+func (e *EnumValueExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(e)
+	defer visitor.leave(e)
+	if err := e.Name.Accept(visitor); err != nil {
+		return err
+	}
+	if err := e.Value.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitEnumValueExpr(e)
+}
+
 type EnumValueExprList struct {
 	ListPos Pos
 	ListEnd Pos
@@ -2090,6 +3056,17 @@ func (e *EnumValueExprList) String(level int) string {
 	return builder.String()
 }
 
+func (e *EnumValueExprList) Accept(visitor ASTVisitor) error {
+	visitor.enter(e)
+	defer visitor.leave(e)
+	for i := range e.Enums {
+		if err := e.Enums[i].Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitEnumValueExprList(e)
+}
+
 type IntervalExpr struct {
 	IntervalPos Pos
 	Expr        Expr
@@ -2113,6 +3090,18 @@ func (i *IntervalExpr) String(level int) string {
 	return builder.String()
 }
 
+func (i *IntervalExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(i)
+	defer visitor.leave(i)
+	if err := i.Expr.Accept(visitor); err != nil {
+		return err
+	}
+	if err := i.Unit.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitIntervalExpr(i)
+}
+
 type EngineExpr struct {
 	EnginePos        Pos
 	EngineEnd        Pos
@@ -2170,6 +3159,47 @@ func (e *EngineExpr) String(level int) string {
 	return builder.String()
 }
 
+func (e *EngineExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(e)
+	defer visitor.leave(e)
+	if e.Params != nil {
+		if err := e.Params.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if e.PrimaryKey != nil {
+		if err := e.PrimaryKey.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if e.PartitionBy != nil {
+		if err := e.PartitionBy.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if e.SampleBy != nil {
+		if err := e.SampleBy.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if e.TTLExprList != nil {
+		if err := e.TTLExprList.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if e.SettingsExprList != nil {
+		if err := e.SettingsExprList.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if e.OrderByListExpr != nil {
+		if err := e.OrderByListExpr.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitEngineExpr(e)
+}
+
 type ColumnTypeExpr struct {
 	Name *Ident
 }
@@ -2186,6 +3216,15 @@ func (c *ColumnTypeExpr) String(level int) string {
 	return c.Name.String(level)
 }
 
+func (c *ColumnTypeExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(c)
+	defer visitor.leave(c)
+	if err := c.Name.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitColumnTypeExpr(c)
+}
+
 type ColumnArgList struct {
 	Distinct      bool
 	LeftParenPos  Pos
@@ -2214,6 +3253,17 @@ func (c *ColumnArgList) String(level int) string {
 	return builder.String()
 }
 
+func (c *ColumnArgList) Accept(visitor ASTVisitor) error {
+	visitor.enter(c)
+	defer visitor.leave(c)
+	for _, item := range c.Items {
+		if err := item.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitColumnArgList(c)
+}
+
 type ColumnExprList struct {
 	ListPos     Pos
 	ListEnd     Pos
@@ -2243,6 +3293,17 @@ func (c *ColumnExprList) String(level int) string {
 	return builder.String()
 }
 
+func (c *ColumnExprList) Accept(visitor ASTVisitor) error {
+	visitor.enter(c)
+	defer visitor.leave(c)
+	for _, item := range c.Items {
+		if err := item.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitColumnExprList(c)
+}
+
 type WhenExpr struct {
 	WhenPos Pos
 	ThenPos Pos
@@ -2279,6 +3340,23 @@ func (w *WhenExpr) String(level int) string {
 	return builder.String()
 }
 
+func (w *WhenExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(w)
+	defer visitor.leave(w)
+	if err := w.When.Accept(visitor); err != nil {
+		return err
+	}
+	if err := w.Then.Accept(visitor); err != nil {
+		return err
+	}
+	if w.Else != nil {
+		if err := w.Else.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitWhenExpr(w)
+}
+
 type CaseExpr struct {
 	CasePos Pos
 	EndPos  Pos
@@ -2315,6 +3393,25 @@ func (c *CaseExpr) String(level int) string {
 	return builder.String()
 }
 
+func (c *CaseExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(c)
+	defer visitor.leave(c)
+	if err := c.Expr.Accept(visitor); err != nil {
+		return err
+	}
+	for _, when := range c.Whens {
+		if err := when.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if c.Else != nil {
+		if err := c.Else.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitCaseExpr(c)
+}
+
 type CastExpr struct {
 	CastPos Pos
 	Expr    Expr
@@ -2343,6 +3440,18 @@ func (c *CastExpr) String(level int) string {
 	return builder.String()
 }
 
+func (c *CastExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(c)
+	defer visitor.leave(c)
+	if err := c.Expr.Accept(visitor); err != nil {
+		return err
+	}
+	if err := c.AsType.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitCastExpr(c)
+}
+
 type WithExpr struct {
 	WithPos Pos
 	EndPos  Pos
@@ -2369,6 +3478,17 @@ func (w *WithExpr) String(level int) string {
 	return builder.String()
 }
 
+func (w *WithExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(w)
+	defer visitor.leave(w)
+	for _, cte := range w.CTEs {
+		if err := cte.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitWithExpr(w)
+}
+
 type TopExpr struct {
 	TopPos   Pos
 	TopEnd   Pos
@@ -2394,6 +3514,15 @@ func (t *TopExpr) String(int) string {
 	return builder.String()
 }
 
+func (t *TopExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(t)
+	defer visitor.leave(t)
+	if err := t.Number.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitTopExpr(t)
+}
+
 type CreateLiveView struct {
 	CreatePos    Pos
 	StatementEnd Pos
@@ -2454,6 +3583,45 @@ func (c *CreateLiveView) String(level int) string {
 	return builder.String()
 }
 
+func (c *CreateLiveView) Accept(visitor ASTVisitor) error {
+	visitor.enter(c)
+	defer visitor.leave(c)
+	if err := c.Name.Accept(visitor); err != nil {
+		return err
+	}
+	if c.UUID != nil {
+		if err := c.UUID.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if c.OnCluster != nil {
+		if err := c.OnCluster.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if c.Destination != nil {
+		if err := c.Destination.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if c.TableSchema != nil {
+		if err := c.TableSchema.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if c.WithTimeout != nil {
+		if err := c.WithTimeout.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if c.SubQuery != nil {
+		if err := c.SubQuery.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitCreateLiveView(c)
+}
+
 type WithTimeoutExpr struct {
 	WithTimeoutPos Pos
 	Expr           Expr
@@ -2475,6 +3643,15 @@ func (w *WithTimeoutExpr) String(int) string {
 	return builder.String()
 }
 
+func (w *WithTimeoutExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(w)
+	defer visitor.leave(w)
+	if err := w.Number.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitWithTimeoutExpr(w)
+}
+
 type TableExpr struct {
 	TablePos Pos
 	TableEnd Pos
@@ -2504,6 +3681,20 @@ func (t *TableExpr) String(level int) string {
 	return builder.String()
 }
 
+func (t *TableExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(t)
+	defer visitor.leave(t)
+	if err := t.Expr.Accept(visitor); err != nil {
+		return err
+	}
+	if t.Alias != nil {
+		if err := t.Alias.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitTableExpr(t)
+}
+
 type OnExpr struct {
 	OnPos Pos
 	On    *ColumnExprList
@@ -2524,6 +3715,15 @@ func (o *OnExpr) String(level int) string {
 	return builder.String()
 }
 
+func (o *OnExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(o)
+	defer visitor.leave(o)
+	if err := o.On.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitOnExpr(o)
+}
+
 type UsingExpr struct {
 	UsingPos Pos
 	Using    *ColumnExprList
@@ -2544,6 +3744,15 @@ func (u *UsingExpr) String(level int) string {
 	return builder.String()
 }
 
+func (u *UsingExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(u)
+	defer visitor.leave(u)
+	if err := u.Using.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitUsingExpr(u)
+}
+
 type JoinExpr struct {
 	JoinPos     Pos
 	Left        Expr
@@ -2579,6 +3788,28 @@ func (j *JoinExpr) String(level int) string {
 	return builder.String()
 }
 
+func (j *JoinExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(j)
+	defer visitor.leave(j)
+	if err := j.Left.Accept(visitor); err != nil {
+		return err
+	}
+	if err := j.Right.Accept(visitor); err != nil {
+		return err
+	}
+	if j.SampleRatio != nil {
+		if err := j.SampleRatio.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if j.Constraints != nil {
+		if err := j.Constraints.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitJoinExpr(j)
+}
+
 type JoinConstraintExpr struct {
 	ConstraintPos Pos
 	On            *ColumnExprList
@@ -2608,11 +3839,27 @@ func (j *JoinConstraintExpr) String(level int) string {
 	return builder.String()
 }
 
-type FromExpr struct {
-	FromPos Pos
-	Expr    Expr
-}
-
+func (j *JoinConstraintExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(j)
+	defer visitor.leave(j)
+	if j.On != nil {
+		if err := j.On.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if j.Using != nil {
+		if err := j.Using.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitJoinConstraintExpr(j)
+}
+
+type FromExpr struct {
+	FromPos Pos
+	Expr    Expr
+}
+
 func (f *FromExpr) Pos() Pos {
 	return f.FromPos
 }
@@ -2629,6 +3876,15 @@ func (f *FromExpr) String(level int) string {
 	return builder.String()
 }
 
+func (f *FromExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(f)
+	defer visitor.leave(f)
+	if err := f.Expr.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitFromExpr(f)
+}
+
 type IsNullExpr struct {
 	IsPos Pos
 	Expr  Expr
@@ -2649,6 +3905,15 @@ func (n *IsNullExpr) String(level int) string {
 	return builder.String()
 }
 
+func (n *IsNullExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(n)
+	defer visitor.leave(n)
+	if err := n.Expr.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitIsNullExpr(n)
+}
+
 type IsNotNullExpr struct {
 	IsPos Pos
 	Expr  Expr
@@ -2669,6 +3934,15 @@ func (n *IsNotNullExpr) String(level int) string {
 	return builder.String()
 }
 
+func (n *IsNotNullExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(n)
+	defer visitor.leave(n)
+	if err := n.Expr.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitIsNotNullExpr(n)
+}
+
 type AliasExpr struct {
 	Expr     Expr
 	AliasPos Pos
@@ -2697,6 +3971,18 @@ func (a *AliasExpr) String(level int) string {
 	return builder.String()
 }
 
+func (a *AliasExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(a)
+	defer visitor.leave(a)
+	if err := a.Expr.Accept(visitor); err != nil {
+		return err
+	}
+	if err := a.Alias.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitAliasExpr(a)
+}
+
 type WhereExpr struct {
 	WherePos Pos
 	Expr     Expr
@@ -2718,6 +4004,15 @@ func (w *WhereExpr) String(level int) string {
 	return builder.String()
 }
 
+func (w *WhereExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(w)
+	defer visitor.leave(w)
+	if err := w.Expr.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitWhereExpr(w)
+}
+
 type PrewhereExpr struct {
 	PrewherePos Pos
 	Expr        Expr
@@ -2735,6 +4030,15 @@ func (w *PrewhereExpr) String(level int) string {
 	return "PREWHERE " + w.Expr.String(level+1)
 }
 
+func (w *PrewhereExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(w)
+	defer visitor.leave(w)
+	if err := w.Expr.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitPrewhereExpr(w)
+}
+
 type GroupByExpr struct {
 	GroupByPos    Pos
 	AggregateType string
@@ -2775,6 +4079,15 @@ func (g *GroupByExpr) String(level int) string {
 	return builder.String()
 }
 
+func (g *GroupByExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(g)
+	defer visitor.leave(g)
+	if err := g.Expr.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitGroupByExpr(g)
+}
+
 type HavingExpr struct {
 	HavingPos Pos
 	Expr      Expr
@@ -2792,6 +4105,15 @@ func (h *HavingExpr) String(level int) string {
 	return "HAVING " + h.Expr.String(level)
 }
 
+func (h *HavingExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(h)
+	defer visitor.leave(h)
+	if err := h.Expr.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitHavingExpr(h)
+}
+
 type LimitExpr struct {
 	LimitPos Pos
 	Limit    Expr
@@ -2820,6 +4142,20 @@ func (l *LimitExpr) String(level int) string {
 	return builder.String()
 }
 
+func (l *LimitExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(l)
+	defer visitor.leave(l)
+	if err := l.Limit.Accept(visitor); err != nil {
+		return err
+	}
+	if l.Offset != nil {
+		if err := l.Offset.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitLimitExpr(l)
+}
+
 type LimitByExpr struct {
 	Limit  *LimitExpr
 	ByExpr *ColumnExprList
@@ -2854,6 +4190,22 @@ func (l *LimitByExpr) String(level int) string {
 	return builder.String()
 }
 
+func (l *LimitByExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(l)
+	defer visitor.leave(l)
+	if l.Limit != nil {
+		if err := l.Limit.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if l.ByExpr != nil {
+		if err := l.ByExpr.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitLimitByExpr(l)
+}
+
 type WindowConditionExpr struct {
 	LeftParenPos  Pos
 	RightParenPos Pos
@@ -2889,6 +4241,27 @@ func (w *WindowConditionExpr) String(level int) string {
 	return builder.String()
 }
 
+func (w *WindowConditionExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(w)
+	defer visitor.leave(w)
+	if w.PartitionBy != nil {
+		if err := w.PartitionBy.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if w.OrderBy != nil {
+		if err := w.OrderBy.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if w.Frame != nil {
+		if err := w.Frame.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitWindowConditionExpr(w)
+}
+
 type WindowExpr struct {
 	*WindowConditionExpr
 
@@ -2914,6 +4287,22 @@ func (w *WindowExpr) String(level int) string {
 	return builder.String()
 }
 
+func (w *WindowExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(w)
+	defer visitor.leave(w)
+	if w.WindowConditionExpr != nil {
+		if err := w.WindowConditionExpr.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if w.Name != nil {
+		if err := w.Name.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitWindowExpr(w)
+}
+
 type WindowFrameExpr struct {
 	FramePos Pos
 	Type     string
@@ -2936,6 +4325,15 @@ func (f *WindowFrameExpr) String(level int) string {
 	return builder.String()
 }
 
+func (f *WindowFrameExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(f)
+	defer visitor.leave(f)
+	if err := f.Extend.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitWindowFrameExpr(f)
+}
+
 type WindowFrameExtendExpr struct {
 	Expr Expr
 }
@@ -2952,6 +4350,15 @@ func (f *WindowFrameExtendExpr) String(int) string {
 	return f.Expr.String(0)
 }
 
+func (f *WindowFrameExtendExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(f)
+	defer visitor.leave(f)
+	if err := f.Expr.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitWindowFrameExtendExpr(f)
+}
+
 type WindowFrameRangeExpr struct {
 	BetweenPos  Pos
 	BetweenExpr Expr
@@ -2976,6 +4383,18 @@ func (f *WindowFrameRangeExpr) String(level int) string {
 	return builder.String()
 }
 
+func (f *WindowFrameRangeExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(f)
+	defer visitor.leave(f)
+	if err := f.BetweenExpr.Accept(visitor); err != nil {
+		return err
+	}
+	if err := f.AndExpr.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitWindowFrameRangeExpr(f)
+}
+
 type WindowFrameCurrentRow struct {
 	CurrentPos Pos
 	RowEnd     Pos
@@ -2993,6 +4412,12 @@ func (f *WindowFrameCurrentRow) String(int) string {
 	return "CURRENT ROW"
 }
 
+func (f *WindowFrameCurrentRow) Accept(visitor ASTVisitor) error {
+	visitor.enter(f)
+	defer visitor.leave(f)
+	return visitor.VisitWindowFrameCurrentRow(f)
+}
+
 type WindowFrameUnbounded struct {
 	UnboundedPos Pos
 	UnboundedEnd Pos
@@ -3011,6 +4436,12 @@ func (f *WindowFrameUnbounded) String(int) string {
 	return f.Direction + " UNBOUNDED"
 }
 
+func (f *WindowFrameUnbounded) Accept(visitor ASTVisitor) error {
+	visitor.enter(f)
+	defer visitor.leave(f)
+	return visitor.VisitWindowFrameUnbounded(f)
+}
+
 type WindowFrameNumber struct {
 	Number       *NumberLiteral
 	UnboundedEnd Pos
@@ -3033,6 +4464,15 @@ func (f *WindowFrameNumber) String(level int) string {
 	return builder.String()
 }
 
+func (f *WindowFrameNumber) Accept(visitor ASTVisitor) error {
+	visitor.enter(f)
+	defer visitor.leave(f)
+	if err := f.Number.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitWindowFrameNumber(f)
+}
+
 type ArrayJoinExpr struct {
 	ArrayPos Pos
 	Type     string
@@ -3051,6 +4491,15 @@ func (a *ArrayJoinExpr) String(level int) string {
 	return a.Type + " ARRAY JOIN " + a.Expr.String(level)
 }
 
+func (a *ArrayJoinExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(a)
+	defer visitor.leave(a)
+	if err := a.Expr.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitArrayJoinExpr(a)
+}
+
 type SelectQuery struct {
 	SelectPos     Pos
 	StatementEnd  Pos
@@ -3169,6 +4618,97 @@ func (s *SelectQuery) String(level int) string { // nolint: funlen
 	return builder.String()
 }
 
+func (s *SelectQuery) Accept(visitor ASTVisitor) error {
+	visitor.enter(s)
+	defer visitor.leave(s)
+	if s.With != nil {
+		if err := s.With.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if s.Top != nil {
+		if err := s.Top.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if s.SelectColumns != nil {
+		if err := s.SelectColumns.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if s.From != nil {
+		if err := s.From.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if s.ArrayJoin != nil {
+		if err := s.ArrayJoin.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if s.Window != nil {
+		if err := s.Window.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if s.Prewhere != nil {
+		if err := s.Prewhere.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if s.Where != nil {
+		if err := s.Where.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if s.GroupBy != nil {
+		if err := s.GroupBy.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if s.Having != nil {
+		if err := s.Having.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if s.OrderBy != nil {
+		if err := s.OrderBy.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if s.LimitBy != nil {
+		if err := s.LimitBy.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if s.Limit != nil {
+		if err := s.Limit.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if s.Settings != nil {
+		if err := s.Settings.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if s.UnionAll != nil {
+		if err := s.UnionAll.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if s.UnionDistinct != nil {
+		if err := s.UnionDistinct.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if s.Except != nil {
+		if err := s.Except.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitSelectQuery(s)
+}
+
 type SubQueryExpr struct {
 	AsPos  Pos
 	Select *SelectQuery
@@ -3191,6 +4731,17 @@ func (s *SubQueryExpr) String(level int) string {
 	return builder.String()
 }
 
+func (s *SubQueryExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(s)
+	defer visitor.leave(s)
+	if s.Select != nil {
+		if err := s.Select.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitSubQueryExpr(s)
+}
+
 type NotExpr struct {
 	NotPos Pos
 	Expr   Expr
@@ -3208,6 +4759,15 @@ func (n *NotExpr) String(level int) string {
 	return "NOT " + n.Expr.String(level+1)
 }
 
+func (n *NotExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(n)
+	defer visitor.leave(n)
+	if err := n.Expr.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitNotExpr(n)
+}
+
 type NegateExpr struct {
 	NegatePos Pos
 	Expr      Expr
@@ -3225,6 +4785,15 @@ func (n *NegateExpr) String(level int) string {
 	return "-" + n.Expr.String(level+1)
 }
 
+func (n *NegateExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(n)
+	defer visitor.leave(n)
+	if err := n.Expr.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitNegateExpr(n)
+}
+
 type GlobalInExpr struct {
 	GlobalPos Pos
 	Expr      Expr
@@ -3242,6 +4811,15 @@ func (g *GlobalInExpr) String(level int) string {
 	return "GLOBAL " + g.Expr.String(level+1)
 }
 
+func (g *GlobalInExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(g)
+	defer visitor.leave(g)
+	if err := g.Expr.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitGlobalInExpr(g)
+}
+
 type ExtractExpr struct {
 	ExtractPos Pos
 	Interval   *Ident
@@ -3267,6 +4845,15 @@ func (e *ExtractExpr) String(level int) string {
 	return builder.String()
 }
 
+func (e *ExtractExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(e)
+	defer visitor.leave(e)
+	if err := e.FromExpr.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitExtractExpr(e)
+}
+
 type DropDatabase struct {
 	DropPos      Pos
 	StatementEnd Pos
@@ -3301,6 +4888,20 @@ func (d *DropDatabase) String(level int) string {
 	return builder.String()
 }
 
+func (d *DropDatabase) Accept(visitor ASTVisitor) error {
+	visitor.enter(d)
+	defer visitor.leave(d)
+	if err := d.Name.Accept(visitor); err != nil {
+		return err
+	}
+	if d.OnCluster != nil {
+		if err := d.OnCluster.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitDropDatabase(d)
+}
+
 type DropStmt struct {
 	DropPos      Pos
 	StatementEnd Pos
@@ -3346,6 +4947,21 @@ func (d *DropStmt) String(level int) string {
 	return builder.String()
 }
 
+func (d *DropStmt) Accept(visitor ASTVisitor) error {
+	visitor.enter(d)
+	defer visitor.leave(d)
+	if err := d.Name.Accept(visitor); err != nil {
+		return err
+	}
+	if d.OnCluster != nil {
+		if err := d.OnCluster.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitDropStmt(d)
+
+}
+
 type DropUserOrRole struct {
 	DropPos      Pos
 	Target       string
@@ -3390,6 +5006,22 @@ func (d *DropUserOrRole) String(level int) string {
 	return builder.String()
 }
 
+func (d *DropUserOrRole) Accept(visitor ASTVisitor) error {
+	visitor.enter(d)
+	defer visitor.leave(d)
+	for _, name := range d.Names {
+		if err := name.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if d.From != nil {
+		if err := d.From.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitDropUserOrRole(d)
+}
+
 type UseExpr struct {
 	UsePos       Pos
 	StatementEnd Pos
@@ -3408,6 +5040,15 @@ func (u *UseExpr) String(level int) string {
 	return "USE " + u.Database.String(level+1)
 }
 
+func (u *UseExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(u)
+	defer visitor.leave(u)
+	if err := u.Database.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitUseExpr(u)
+}
+
 type CTEExpr struct {
 	CTEPos Pos
 	Expr   Expr
@@ -3436,6 +5077,18 @@ func (c *CTEExpr) String(level int) string {
 	return builder.String()
 }
 
+func (c *CTEExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(c)
+	defer visitor.leave(c)
+	if err := c.Expr.Accept(visitor); err != nil {
+		return err
+	}
+	if err := c.Alias.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitCTEExpr(c)
+}
+
 type SetExpr struct {
 	SetPos   Pos
 	Settings *SettingsExprList
@@ -3461,6 +5114,15 @@ func (s *SetExpr) String(level int) string {
 	return builder.String()
 }
 
+func (s *SetExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(s)
+	defer visitor.leave(s)
+	if err := s.Settings.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitSetExpr(s)
+}
+
 type FormatExpr struct {
 	FormatPos Pos
 	Format    *Ident
@@ -3478,6 +5140,15 @@ func (f *FormatExpr) String(level int) string {
 	return "FORMAT " + f.Format.String(level)
 }
 
+func (f *FormatExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(f)
+	defer visitor.leave(f)
+	if err := f.Format.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitFormatExpr(f)
+}
+
 type OptimizeExpr struct {
 	OptimizePos  Pos
 	StatementEnd Pos
@@ -3517,6 +5188,30 @@ func (o *OptimizeExpr) String(level int) string {
 	return builder.String()
 }
 
+func (o *OptimizeExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(o)
+	defer visitor.leave(o)
+	if err := o.Table.Accept(visitor); err != nil {
+		return err
+	}
+	if o.OnCluster != nil {
+		if err := o.OnCluster.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if o.Partition != nil {
+		if err := o.Partition.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if o.Deduplicate != nil {
+		if err := o.Deduplicate.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitOptimizeExpr(o)
+}
+
 type DeduplicateExpr struct {
 	DeduplicatePos Pos
 	By             *ColumnExprList
@@ -3550,6 +5245,22 @@ func (d *DeduplicateExpr) String(level int) string {
 	return builder.String()
 }
 
+func (d *DeduplicateExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(d)
+	defer visitor.leave(d)
+	if d.By != nil {
+		if err := d.By.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if d.Except != nil {
+		if err := d.Except.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitDeduplicateExpr(d)
+}
+
 type SystemExpr struct {
 	SystemPos Pos
 	Expr      Expr
@@ -3567,6 +5278,15 @@ func (s *SystemExpr) String(level int) string {
 	return "SYSTEM " + s.Expr.String(level)
 }
 
+func (s *SystemExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(s)
+	defer visitor.leave(s)
+	if err := s.Expr.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitSystemExpr(s)
+}
+
 type SystemFlushExpr struct {
 	FlushPos     Pos
 	StatementEnd Pos
@@ -3593,6 +5313,17 @@ func (s *SystemFlushExpr) String(level int) string {
 	return builder.String()
 }
 
+func (s *SystemFlushExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(s)
+	defer visitor.leave(s)
+	if s.Distributed != nil {
+		if err := s.Distributed.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitSystemFlushExpr(s)
+}
+
 type SystemReloadExpr struct {
 	ReloadPos    Pos
 	StatementEnd Pos
@@ -3619,6 +5350,17 @@ func (s *SystemReloadExpr) String(level int) string {
 	return builder.String()
 }
 
+func (s *SystemReloadExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(s)
+	defer visitor.leave(s)
+	if s.Dictionary != nil {
+		if err := s.Dictionary.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitSystemReloadExpr(s)
+}
+
 type SystemSyncExpr struct {
 	SyncPos Pos
 	Cluster *TableIdentifier
@@ -3639,6 +5381,15 @@ func (s *SystemSyncExpr) String(level int) string {
 	return builder.String()
 }
 
+func (s *SystemSyncExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(s)
+	defer visitor.leave(s)
+	if err := s.Cluster.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitSystemSyncExpr(s)
+}
+
 type SystemCtrlExpr struct {
 	CtrlPos      Pos
 	StatementEnd Pos
@@ -3667,6 +5418,17 @@ func (s *SystemCtrlExpr) String(level int) string {
 	return builder.String()
 }
 
+func (s *SystemCtrlExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(s)
+	defer visitor.leave(s)
+	if s.Cluster != nil {
+		if err := s.Cluster.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitSystemCtrlExpr(s)
+}
+
 type SystemDropExpr struct {
 	DropPos      Pos
 	StatementEnd Pos
@@ -3685,6 +5447,12 @@ func (s *SystemDropExpr) String(level int) string {
 	return "DROP " + s.Type
 }
 
+func (s *SystemDropExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(s)
+	defer visitor.leave(s)
+	return visitor.VisitSystemDropExpr(s)
+}
+
 type TruncateTable struct {
 	TruncatePos  Pos
 	StatementEnd Pos
@@ -3724,6 +5492,20 @@ func (t *TruncateTable) String(level int) string {
 	return builder.String()
 }
 
+func (t *TruncateTable) Accept(visitor ASTVisitor) error {
+	visitor.enter(t)
+	defer visitor.leave(t)
+	if err := t.Name.Accept(visitor); err != nil {
+		return err
+	}
+	if t.OnCluster != nil {
+		if err := t.OnCluster.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitTruncateTable(t)
+}
+
 type SampleRatioExpr struct {
 	SamplePos Pos
 	Ratio     *RatioExpr
@@ -3752,6 +5534,20 @@ func (s *SampleRatioExpr) String(level int) string {
 	return builder.String()
 }
 
+func (s *SampleRatioExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(s)
+	defer visitor.leave(s)
+	if err := s.Ratio.Accept(visitor); err != nil {
+		return err
+	}
+	if s.Offset != nil {
+		if err := s.Offset.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitSampleRatioExpr(s)
+}
+
 type DeleteFromExpr struct {
 	DeletePos Pos
 	Table     *TableIdentifier
@@ -3783,6 +5579,25 @@ func (d *DeleteFromExpr) String(level int) string {
 	return builder.String()
 }
 
+func (d *DeleteFromExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(d)
+	defer visitor.leave(d)
+	if err := d.Table.Accept(visitor); err != nil {
+		return err
+	}
+	if d.OnCluster != nil {
+		if err := d.OnCluster.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if d.WhereExpr != nil {
+		if err := d.WhereExpr.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitDeleteFromExpr(d)
+}
+
 type ColumnNamesExpr struct {
 	LeftParenPos  Pos
 	RightParenPos Pos
@@ -3810,6 +5625,17 @@ func (c *ColumnNamesExpr) String(level int) string {
 	return builder.String()
 }
 
+func (c *ColumnNamesExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(c)
+	defer visitor.leave(c)
+	for i := range c.ColumnNames {
+		if err := c.ColumnNames[i].Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitColumnNamesExpr(c)
+}
+
 type ValuesExpr struct {
 	LeftParenPos  Pos
 	RightParenPos Pos
@@ -3837,6 +5663,17 @@ func (v *ValuesExpr) String(level int) string {
 	return builder.String()
 }
 
+func (v *ValuesExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(v)
+	defer visitor.leave(v)
+	for _, value := range v.Values {
+		if err := value.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitValuesExpr(v)
+}
+
 type InsertExpr struct {
 	InsertPos   Pos
 	Format      *FormatExpr
@@ -3886,6 +5723,35 @@ func (i *InsertExpr) String(level int) string {
 	return builder.String()
 }
 
+func (i *InsertExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(i)
+	defer visitor.leave(i)
+	if i.Format != nil {
+		if err := i.Format.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if err := i.Table.Accept(visitor); err != nil {
+		return err
+	}
+	if i.ColumnNames != nil {
+		if err := i.ColumnNames.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	for _, value := range i.Values {
+		if err := value.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if i.SelectExpr != nil {
+		if err := i.SelectExpr.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitInsertExpr(i)
+}
+
 type CheckExpr struct {
 	CheckPos  Pos
 	Table     *TableIdentifier
@@ -3911,6 +5777,20 @@ func (c *CheckExpr) String(level int) string {
 	return builder.String()
 }
 
+func (c *CheckExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(c)
+	defer visitor.leave(c)
+	if err := c.Table.Accept(visitor); err != nil {
+		return err
+	}
+	if c.Partition != nil {
+		if err := c.Partition.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitCheckExpr(c)
+}
+
 type UnaryExpr struct {
 	UnaryPos Pos
 	Kind     TokenKind
@@ -3929,6 +5809,15 @@ func (n *UnaryExpr) String(level int) string {
 	return "-" + n.Expr.String(level+1)
 }
 
+func (n *UnaryExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(n)
+	defer visitor.leave(n)
+	if err := n.Expr.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitUnaryExpr(n)
+}
+
 type RenameStmt struct {
 	RenamePos    Pos
 	StatementEnd Pos
@@ -3968,6 +5857,25 @@ func (r *RenameStmt) String(level int) string {
 	return builder.String()
 }
 
+func (r *RenameStmt) Accept(visitor ASTVisitor) error {
+	visitor.enter(r)
+	defer visitor.leave(r)
+	for _, pair := range r.TargetPairList {
+		if err := pair.Old.Accept(visitor); err != nil {
+			return err
+		}
+		if err := pair.New.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if r.OnCluster != nil {
+		if err := r.OnCluster.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitRenameStmt(r)
+}
+
 type TargetPair struct {
 	Old *TableIdentifier
 	New *TableIdentifier
@@ -4008,6 +5916,15 @@ func (e *ExplainExpr) String(level int) string {
 	return builder.String()
 }
 
+func (e *ExplainExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(e)
+	defer visitor.leave(e)
+	if err := e.Statement.Accept(visitor); err != nil {
+		return err
+	}
+	return visitor.VisitExplainExpr(e)
+}
+
 type PrivilegeExpr struct {
 	PrivilegePos Pos
 	PrivilegeEnd Pos
@@ -4037,6 +5954,17 @@ func (p *PrivilegeExpr) String(level int) string {
 	return builder.String()
 }
 
+func (p *PrivilegeExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(p)
+	defer visitor.leave(p)
+	if p.Params != nil {
+		if err := p.Params.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitPrivilegeExpr(p)
+}
+
 type GrantPrivilegeExpr struct {
 	GrantPos     Pos
 	StatementEnd Pos
@@ -4087,3 +6015,27 @@ func (g *GrantPrivilegeExpr) String(level int) string {
 
 	return builder.String()
 }
+
+func (g *GrantPrivilegeExpr) Accept(visitor ASTVisitor) error {
+	visitor.enter(g)
+	defer visitor.leave(g)
+	if g.OnCluster != nil {
+		if err := g.OnCluster.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	for _, privilege := range g.Privileges {
+		if err := privilege.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	if err := g.On.Accept(visitor); err != nil {
+		return err
+	}
+	for _, role := range g.To {
+		if err := role.Accept(visitor); err != nil {
+			return err
+		}
+	}
+	return visitor.VisitGrantPrivilegeExpr(g)
+}
diff --git a/parser/ast_visitor.go b/parser/ast_visitor.go
new file mode 100644
index 0000000..c8a67e9
--- /dev/null
+++ b/parser/ast_visitor.go
@@ -0,0 +1,1153 @@
+package parser
+
+type ASTVisitor interface {
+	VisitOperationExpr(expr *OperationExpr) error
+	VisitTernaryExpr(expr *TernaryExpr) error
+	VisitBinaryExpr(expr *BinaryExpr) error
+	VisitAlterTable(expr *AlterTable) error
+	VisitAlterTableAttachPartition(expr *AlterTableAttachPartition) error
+	VisitAlterTableDetachPartition(expr *AlterTableDetachPartition) error
+	VisitAlterTableDropPartition(expr *AlterTableDropPartition) error
+	VisitAlterTableFreezePartition(expr *AlterTableFreezePartition) error
+	VisitAlterTableAddColumn(expr *AlterTableAddColumn) error
+	VisitAlterTableAddIndex(expr *AlterTableAddIndex) error
+	VisitAlterTableDropColumn(expr *AlterTableDropColumn) error
+	VisitAlterTableDropIndex(expr *AlterTableDropIndex) error
+	VisitAlterTableRemoveTTL(expr *AlterTableRemoveTTL) error
+	VisitAlterTableClearColumn(expr *AlterTableClearColumn) error
+	VisitAlterTableClearIndex(expr *AlterTableClearIndex) error
+	VisitAlterTableRenameColumn(expr *AlterTableRenameColumn) error
+	VisitAlterTableModifyTTL(expr *AlterTableModifyTTL) error
+	VisitAlterTableModifyColumn(expr *AlterTableModifyColumn) error
+	VisitAlterTableReplacePartition(expr *AlterTableReplacePartition) error
+	VisitRemovePropertyType(expr *RemovePropertyType) error
+	VisitTableIndex(expr *TableIndex) error
+	VisitIdent(expr *Ident) error
+	VisitUUID(expr *UUID) error
+	VisitCreateDatabase(expr *CreateDatabase) error
+	VisitCreateTable(expr *CreateTable) error
+	VisitCreateMaterializedView(expr *CreateMaterializedView) error
+	VisitCreateView(expr *CreateView) error
+	VisitCreateFunction(expr *CreateFunction) error
+	VisitRoleName(expr *RoleName) error
+	VisitSettingPair(expr *SettingPair) error
+	VisitRoleSetting(expr *RoleSetting) error
+	VisitCreateRole(expr *CreateRole) error
+	VisitAlterRole(expr *AlterRole) error
+	VisitRoleRenamePair(expr *RoleRenamePair) error
+	VisitDestinationExpr(expr *DestinationExpr) error
+	VisitConstraintExpr(expr *ConstraintExpr) error
+	VisitNullLiteral(expr *NullLiteral) error
+	VisitNotNullLiteral(expr *NotNullLiteral) error
+	VisitNestedIdentifier(expr *NestedIdentifier) error
+	VisitColumnIdentifier(expr *ColumnIdentifier) error
+	VisitTableIdentifier(expr *TableIdentifier) error
+	VisitTableSchemaExpr(expr *TableSchemaExpr) error
+	VisitTableArgListExpr(expr *TableArgListExpr) error
+	VisitTableFunctionExpr(expr *TableFunctionExpr) error
+	VisitOnClusterExpr(expr *OnClusterExpr) error
+	VisitDefaultExpr(expr *DefaultExpr) error
+	VisitPartitionExpr(expr *PartitionExpr) error
+	VisitPartitionByExpr(expr *PartitionByExpr) error
+	VisitPrimaryKeyExpr(expr *PrimaryKeyExpr) error
+	VisitSampleByExpr(expr *SampleByExpr) error
+	VisitTTLExpr(expr *TTLExpr) error
+	VisitTTLExprList(expr *TTLExprList) error
+	VisitOrderByExpr(expr *OrderByExpr) error
+	VisitOrderByListExpr(expr *OrderByListExpr) error
+	VisitSettingsExpr(expr *SettingsExpr) error
+	VisitSettingsExprList(expr *SettingsExprList) error
+	VisitParamExprList(expr *ParamExprList) error
+	VisitArrayParamList(expr *ArrayParamList) error
+	VisitObjectParams(expr *ObjectParams) error
+	VisitFunctionExpr(expr *FunctionExpr) error
+	VisitWindowFunctionExpr(expr *WindowFunctionExpr) error
+	VisitColumn(expr *Column) error
+	VisitScalarTypeExpr(expr *ScalarTypeExpr) error
+	VisitPropertyTypeExpr(expr *PropertyTypeExpr) error
+	VisitTypeWithParamsExpr(expr *TypeWithParamsExpr) error
+	VisitComplexTypeExpr(expr *ComplexTypeExpr) error
+	VisitNestedTypeExpr(expr *NestedTypeExpr) error
+	VisitCompressionCodec(expr *CompressionCodec) error
+	VisitNumberLiteral(expr *NumberLiteral) error
+	VisitStringLiteral(expr *StringLiteral) error
+	VisitRatioExpr(expr *RatioExpr) error
+	VisitEnumValueExpr(expr *EnumValueExpr) error
+	VisitEnumValueExprList(expr *EnumValueExprList) error
+	VisitIntervalExpr(expr *IntervalExpr) error
+	VisitEngineExpr(expr *EngineExpr) error
+	VisitColumnTypeExpr(expr *ColumnTypeExpr) error
+	VisitColumnArgList(expr *ColumnArgList) error
+	VisitColumnExprList(expr *ColumnExprList) error
+	VisitWhenExpr(expr *WhenExpr) error
+	VisitCaseExpr(expr *CaseExpr) error
+	VisitCastExpr(expr *CastExpr) error
+	VisitWithExpr(expr *WithExpr) error
+	VisitTopExpr(expr *TopExpr) error
+	VisitCreateLiveView(expr *CreateLiveView) error
+	VisitWithTimeoutExpr(expr *WithTimeoutExpr) error
+	VisitTableExpr(expr *TableExpr) error
+	VisitOnExpr(expr *OnExpr) error
+	VisitUsingExpr(expr *UsingExpr) error
+	VisitJoinExpr(expr *JoinExpr) error
+	VisitJoinConstraintExpr(expr *JoinConstraintExpr) error
+	VisitFromExpr(expr *FromExpr) error
+	VisitIsNullExpr(expr *IsNullExpr) error
+	VisitIsNotNullExpr(expr *IsNotNullExpr) error
+	VisitAliasExpr(expr *AliasExpr) error
+	VisitWhereExpr(expr *WhereExpr) error
+	VisitPrewhereExpr(expr *PrewhereExpr) error
+	VisitGroupByExpr(expr *GroupByExpr) error
+	VisitHavingExpr(expr *HavingExpr) error
+	VisitLimitExpr(expr *LimitExpr) error
+	VisitLimitByExpr(expr *LimitByExpr) error
+	VisitWindowConditionExpr(expr *WindowConditionExpr) error
+	VisitWindowExpr(expr *WindowExpr) error
+	VisitWindowFrameExpr(expr *WindowFrameExpr) error
+	VisitWindowFrameExtendExpr(expr *WindowFrameExtendExpr) error
+	VisitWindowFrameRangeExpr(expr *WindowFrameRangeExpr) error
+	VisitWindowFrameCurrentRow(expr *WindowFrameCurrentRow) error
+	VisitWindowFrameUnbounded(expr *WindowFrameUnbounded) error
+	VisitWindowFrameNumber(expr *WindowFrameNumber) error
+	VisitArrayJoinExpr(expr *ArrayJoinExpr) error
+	VisitSelectQuery(expr *SelectQuery) error
+	VisitSubQueryExpr(expr *SubQueryExpr) error
+	VisitNotExpr(expr *NotExpr) error
+	VisitNegateExpr(expr *NegateExpr) error
+	VisitGlobalInExpr(expr *GlobalInExpr) error
+	VisitExtractExpr(expr *ExtractExpr) error
+	VisitDropDatabase(expr *DropDatabase) error
+	VisitDropStmt(expr *DropStmt) error
+	VisitDropUserOrRole(expr *DropUserOrRole) error
+	VisitUseExpr(expr *UseExpr) error
+	VisitCTEExpr(expr *CTEExpr) error
+	VisitSetExpr(expr *SetExpr) error
+	VisitFormatExpr(expr *FormatExpr) error
+	VisitOptimizeExpr(expr *OptimizeExpr) error
+	VisitDeduplicateExpr(expr *DeduplicateExpr) error
+	VisitSystemExpr(expr *SystemExpr) error
+	VisitSystemFlushExpr(expr *SystemFlushExpr) error
+	VisitSystemReloadExpr(expr *SystemReloadExpr) error
+	VisitSystemSyncExpr(expr *SystemSyncExpr) error
+	VisitSystemCtrlExpr(expr *SystemCtrlExpr) error
+	VisitSystemDropExpr(expr *SystemDropExpr) error
+	VisitTruncateTable(expr *TruncateTable) error
+	VisitSampleRatioExpr(expr *SampleRatioExpr) error
+	VisitDeleteFromExpr(expr *DeleteFromExpr) error
+	VisitColumnNamesExpr(expr *ColumnNamesExpr) error
+	VisitValuesExpr(expr *ValuesExpr) error
+	VisitInsertExpr(expr *InsertExpr) error
+	VisitCheckExpr(expr *CheckExpr) error
+	VisitUnaryExpr(expr *UnaryExpr) error
+	VisitRenameStmt(expr *RenameStmt) error
+	VisitExplainExpr(expr *ExplainExpr) error
+	VisitPrivilegeExpr(expr *PrivilegeExpr) error
+	VisitGrantPrivilegeExpr(expr *GrantPrivilegeExpr) error
+
+	enter(expr Expr)
+	leave(expr Expr)
+}
+
+type VisitFunc func(expr Expr) error
+
+type DefaultASTVisitor struct {
+	Visit VisitFunc
+}
+
+func (v *DefaultASTVisitor) VisitOperationExpr(expr *OperationExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitTernaryExpr(expr *TernaryExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitBinaryExpr(expr *BinaryExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitAlterTable(expr *AlterTable) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitAlterTableAttachPartition(expr *AlterTableAttachPartition) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitAlterTableDetachPartition(expr *AlterTableDetachPartition) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitAlterTableDropPartition(expr *AlterTableDropPartition) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitAlterTableFreezePartition(expr *AlterTableFreezePartition) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitAlterTableAddColumn(expr *AlterTableAddColumn) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitAlterTableAddIndex(expr *AlterTableAddIndex) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitAlterTableDropColumn(expr *AlterTableDropColumn) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitAlterTableDropIndex(expr *AlterTableDropIndex) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitAlterTableRemoveTTL(expr *AlterTableRemoveTTL) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitAlterTableClearColumn(expr *AlterTableClearColumn) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitAlterTableClearIndex(expr *AlterTableClearIndex) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitAlterTableRenameColumn(expr *AlterTableRenameColumn) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitAlterTableModifyTTL(expr *AlterTableModifyTTL) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitAlterTableModifyColumn(expr *AlterTableModifyColumn) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitAlterTableReplacePartition(expr *AlterTableReplacePartition) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitRemovePropertyType(expr *RemovePropertyType) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitTableIndex(expr *TableIndex) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitIdent(expr *Ident) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitUUID(expr *UUID) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitCreateDatabase(expr *CreateDatabase) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitCreateTable(expr *CreateTable) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitCreateMaterializedView(expr *CreateMaterializedView) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitCreateView(expr *CreateView) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitCreateFunction(expr *CreateFunction) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitRoleName(expr *RoleName) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitSettingPair(expr *SettingPair) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitRoleSetting(expr *RoleSetting) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitCreateRole(expr *CreateRole) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitAlterRole(expr *AlterRole) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitRoleRenamePair(expr *RoleRenamePair) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitDestinationExpr(expr *DestinationExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitConstraintExpr(expr *ConstraintExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitNullLiteral(expr *NullLiteral) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitNotNullLiteral(expr *NotNullLiteral) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitNestedIdentifier(expr *NestedIdentifier) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitColumnIdentifier(expr *ColumnIdentifier) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitTableIdentifier(expr *TableIdentifier) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitTableSchemaExpr(expr *TableSchemaExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitTableArgListExpr(expr *TableArgListExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitTableFunctionExpr(expr *TableFunctionExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitOnClusterExpr(expr *OnClusterExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitDefaultExpr(expr *DefaultExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitPartitionExpr(expr *PartitionExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitPartitionByExpr(expr *PartitionByExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitPrimaryKeyExpr(expr *PrimaryKeyExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitSampleByExpr(expr *SampleByExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitTTLExpr(expr *TTLExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitTTLExprList(expr *TTLExprList) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitOrderByExpr(expr *OrderByExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitOrderByListExpr(expr *OrderByListExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitSettingsExpr(expr *SettingsExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitSettingsExprList(expr *SettingsExprList) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitParamExprList(expr *ParamExprList) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitArrayParamList(expr *ArrayParamList) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitObjectParams(expr *ObjectParams) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitFunctionExpr(expr *FunctionExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitWindowFunctionExpr(expr *WindowFunctionExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitColumn(expr *Column) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitScalarTypeExpr(expr *ScalarTypeExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitPropertyTypeExpr(expr *PropertyTypeExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitTypeWithParamsExpr(expr *TypeWithParamsExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitComplexTypeExpr(expr *ComplexTypeExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitNestedTypeExpr(expr *NestedTypeExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitCompressionCodec(expr *CompressionCodec) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitNumberLiteral(expr *NumberLiteral) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitStringLiteral(expr *StringLiteral) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitRatioExpr(expr *RatioExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitEnumValueExpr(expr *EnumValueExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitEnumValueExprList(expr *EnumValueExprList) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitIntervalExpr(expr *IntervalExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitEngineExpr(expr *EngineExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitColumnTypeExpr(expr *ColumnTypeExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitColumnArgList(expr *ColumnArgList) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitColumnExprList(expr *ColumnExprList) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitWhenExpr(expr *WhenExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitCaseExpr(expr *CaseExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitCastExpr(expr *CastExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitWithExpr(expr *WithExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitTopExpr(expr *TopExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitCreateLiveView(expr *CreateLiveView) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitWithTimeoutExpr(expr *WithTimeoutExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitTableExpr(expr *TableExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitOnExpr(expr *OnExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitUsingExpr(expr *UsingExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitJoinExpr(expr *JoinExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitJoinConstraintExpr(expr *JoinConstraintExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitFromExpr(expr *FromExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitIsNullExpr(expr *IsNullExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitIsNotNullExpr(expr *IsNotNullExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitAliasExpr(expr *AliasExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitWhereExpr(expr *WhereExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitPrewhereExpr(expr *PrewhereExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitGroupByExpr(expr *GroupByExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitHavingExpr(expr *HavingExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitLimitExpr(expr *LimitExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitLimitByExpr(expr *LimitByExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitWindowConditionExpr(expr *WindowConditionExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitWindowExpr(expr *WindowExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitWindowFrameExpr(expr *WindowFrameExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitWindowFrameExtendExpr(expr *WindowFrameExtendExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitWindowFrameRangeExpr(expr *WindowFrameRangeExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitWindowFrameCurrentRow(expr *WindowFrameCurrentRow) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitWindowFrameUnbounded(expr *WindowFrameUnbounded) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitWindowFrameNumber(expr *WindowFrameNumber) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitArrayJoinExpr(expr *ArrayJoinExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitSelectQuery(expr *SelectQuery) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitSubQueryExpr(expr *SubQueryExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitNotExpr(expr *NotExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitNegateExpr(expr *NegateExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitGlobalInExpr(expr *GlobalInExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitExtractExpr(expr *ExtractExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitDropDatabase(expr *DropDatabase) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitDropStmt(expr *DropStmt) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitDropUserOrRole(expr *DropUserOrRole) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitUseExpr(expr *UseExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitCTEExpr(expr *CTEExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitSetExpr(expr *SetExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitFormatExpr(expr *FormatExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitOptimizeExpr(expr *OptimizeExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitDeduplicateExpr(expr *DeduplicateExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitSystemExpr(expr *SystemExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitSystemFlushExpr(expr *SystemFlushExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitSystemReloadExpr(expr *SystemReloadExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitSystemSyncExpr(expr *SystemSyncExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitSystemCtrlExpr(expr *SystemCtrlExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitSystemDropExpr(expr *SystemDropExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitTruncateTable(expr *TruncateTable) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitSampleRatioExpr(expr *SampleRatioExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitDeleteFromExpr(expr *DeleteFromExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitColumnNamesExpr(expr *ColumnNamesExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitValuesExpr(expr *ValuesExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitInsertExpr(expr *InsertExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitCheckExpr(expr *CheckExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitUnaryExpr(expr *UnaryExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitRenameStmt(expr *RenameStmt) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitExplainExpr(expr *ExplainExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitPrivilegeExpr(expr *PrivilegeExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) VisitGrantPrivilegeExpr(expr *GrantPrivilegeExpr) error {
+	if v.Visit != nil {
+		return v.Visit(expr)
+	}
+	return nil
+}
+
+func (v *DefaultASTVisitor) enter(expr Expr) {}
+
+func (v *DefaultASTVisitor) leave(expr Expr) {}


Test patch:
diff --git a/parser/visitor_test.go b/parser/visitor_test.go
new file mode 100644
index 0000000..009dd09
--- /dev/null
+++ b/parser/visitor_test.go
@@ -0,0 +1,131 @@
+package parser
+
+import (
+	"os"
+	"path/filepath"
+	"strings"
+	"testing"
+
+	"fmt"
+	"github.com/sebdah/goldie/v2"
+	"github.com/stretchr/testify/require"
+)
+
+func TestVisitor_Identical(t *testing.T) {
+	visitor := DefaultASTVisitor{}
+
+	for _, dir := range []string{"./testdata/dml", "./testdata/ddl", "./testdata/query", "./testdata/basic"} {
+		outputDir := dir + "/format"
+
+		entries, err := os.ReadDir(dir)
+		require.NoError(t, err)
+		for _, entry := range entries {
+			if !strings.HasSuffix(entry.Name(), ".sql") {
+				continue
+			}
+			t.Run(entry.Name(), func(t *testing.T) {
+				fileBytes, err := os.ReadFile(filepath.Join(dir, entry.Name()))
+				require.NoError(t, err)
+				parser := Parser{
+					lexer: NewLexer(string(fileBytes)),
+				}
+				stmts, err := parser.ParseStatements()
+				require.NoError(t, err)
+				var builder strings.Builder
+				builder.WriteString("-- Origin SQL:\n")
+				builder.Write(fileBytes)
+				builder.WriteString("\n\n-- Format SQL:\n")
+				for _, stmt := range stmts {
+					err := stmt.Accept(&visitor)
+					require.NoError(t, err)
+
+					builder.WriteString(stmt.String(0))
+					builder.WriteByte(';')
+					builder.WriteByte('\n')
+				}
+				g := goldie.New(t,
+					goldie.WithNameSuffix(""),
+					goldie.WithDiffEngine(goldie.ColoredDiff),
+					goldie.WithFixtureDir(outputDir))
+				g.Assert(t, entry.Name(), []byte(builder.String()))
+			})
+		}
+	}
+}
+
+type simpleRewriteVisitor struct {
+	DefaultASTVisitor
+}
+
+func (v *simpleRewriteVisitor) VisitTableIdentifier(expr *TableIdentifier) error {
+	if expr.Table.Name == "group_by_all" {
+		expr.Table.Name = "hack"
+	}
+	return nil
+}
+
+func (v *simpleRewriteVisitor) VisitOrderByExpr(expr *OrderByExpr) error {
+	expr.Direction = OrderDirectionDesc
+	return nil
+}
+
+func TestVisitor_SimpleRewrite(t *testing.T) {
+	visitor := simpleRewriteVisitor{}
+
+	sql := `SELECT a, COUNT(b) FROM group_by_all GROUP BY CUBE(a) WITH CUBE WITH TOTALS ORDER BY a;`
+	parser := NewParser(sql)
+	stmts, err := parser.ParseStatements()
+	require.NoError(t, err)
+
+	require.Equal(t, 1, len(stmts))
+	stmt := stmts[0]
+
+	err = stmt.Accept(&visitor)
+	require.NoError(t, err)
+	newSql := stmt.String(0)
+
+	require.NotSame(t, sql, newSql)
+	require.True(t, strings.Contains(newSql, "hack"))
+	require.True(t, strings.Contains(newSql, string(OrderDirectionDesc)))
+}
+
+type nestedRewriteVisitor struct {
+	DefaultASTVisitor
+	stack []Expr
+}
+
+func (v *nestedRewriteVisitor) VisitTableIdentifier(expr *TableIdentifier) error {
+	expr.Table.Name = fmt.Sprintf("table%d", len(v.stack))
+	return nil
+}
+
+func (v *nestedRewriteVisitor) enter(expr Expr) {
+	if s, ok := expr.(*SelectQuery); ok {
+		v.stack = append(v.stack, s)
+	}
+}
+
+func (v *nestedRewriteVisitor) leave(expr Expr) {
+	if _, ok := expr.(*SelectQuery); ok {
+		v.stack = v.stack[1:]
+	}
+}
+
+func TestVisitor_NestRewrite(t *testing.T) {
+	visitor := nestedRewriteVisitor{}
+
+	sql := `SELECT replica_name FROM system.ha_replicas UNION DISTINCT SELECT replica_name FROM system.ha_unique_replicas format JSON`
+	parser := NewParser(sql)
+	stmts, err := parser.ParseStatements()
+	require.NoError(t, err)
+
+	require.Equal(t, 1, len(stmts))
+	stmt := stmts[0]
+
+	err = stmt.Accept(&visitor)
+	require.NoError(t, err)
+	newSql := stmt.String(0)
+
+	require.NotSame(t, sql, newSql)
+	require.Less(t, strings.Index(newSql, "table1"), strings.Index(newSql, "table2"))
+}