From d9a9d95d65bc7b8b3f19318cdeec1933daaad116 Mon Sep 17 00:00:00 2001 From: Andres Taylor Date: Tue, 28 Jan 2025 11:58:39 +0100 Subject: [PATCH 01/13] wip --- go/tools/asthelpergen/ast_path_gen.go | 76 ++++++++++++++++++++ go/tools/asthelpergen/asthelpergen.go | 6 +- go/tools/asthelpergen/clone_gen.go | 2 + go/tools/asthelpergen/copy_on_rewrite_gen.go | 2 + go/tools/asthelpergen/equals_gen.go | 6 +- go/tools/asthelpergen/rewrite_gen.go | 2 + go/tools/asthelpergen/visit_gen.go | 5 +- go/vt/sqlparser/ast_path.go | 18 +++++ 8 files changed, 111 insertions(+), 6 deletions(-) create mode 100644 go/tools/asthelpergen/ast_path_gen.go create mode 100644 go/vt/sqlparser/ast_path.go diff --git a/go/tools/asthelpergen/ast_path_gen.go b/go/tools/asthelpergen/ast_path_gen.go new file mode 100644 index 00000000000..98c9433a35f --- /dev/null +++ b/go/tools/asthelpergen/ast_path_gen.go @@ -0,0 +1,76 @@ +package asthelpergen + +import ( + "github.com/dave/jennifer/jen" + "go/types" +) + +type ( + pathGen struct { + file *jen.File + steps []step + } + step struct { + name string + typ types.Type + } +) + +var _ generator = (*pathGen)(nil) + +func newPathGen(pkgname string) *pathGen { + file := jen.NewFile(pkgname) + file.HeaderComment(licenseFileHeader) + file.HeaderComment("Code generated by ASTHelperGen. DO NOT EDIT.") + + return &pathGen{ + file: file, + } +} + +func (p *pathGen) genFile() (string, *jen.File) { + return "ast_path.go", p.file +} + +func (p *pathGen) interfaceMethod(t types.Type, iface *types.Interface, spi generatorSPI) error { + // don't think we need to do anything here + return nil +} + +func (p *pathGen) structMethod(t types.Type, strct *types.Struct, spi generatorSPI) error { + typeString := types.TypeString(t, noQualifier) + for i := range strct.NumFields() { + field := strct.Field(i) + if types.Implements(field.Type(), spi.iface()) { + + continue + } + slice, isSlice := field.Type().(*types.Slice) + if isSlice && types.Implements(slice.Elem(), spi.iface()) { + spi.addType(slice.Elem()) + output = append(output, jen.For(jen.Id("_, el := range in."+field.Name())).Block( + visitChild(slice.Elem(), jen.Id("el")), + )) + } + } + + return nil +} + +func (p *pathGen) ptrToStructMethod(t types.Type, strct *types.Struct, spi generatorSPI) error { + return nil +} + +func (p *pathGen) ptrToBasicMethod(t types.Type, basic *types.Basic, spi generatorSPI) error { + return nil +} + +func (p *pathGen) sliceMethod(t types.Type, slice *types.Slice, spi generatorSPI) error { + return nil +} + +func (p *pathGen) basicMethod(t types.Type, basic *types.Basic, spi generatorSPI) error { + return nil +} + +func (*pathGen) close(generatorSPI) error { return nil } diff --git a/go/tools/asthelpergen/asthelpergen.go b/go/tools/asthelpergen/asthelpergen.go index 3f59fdb3ece..1845d3b1893 100644 --- a/go/tools/asthelpergen/asthelpergen.go +++ b/go/tools/asthelpergen/asthelpergen.go @@ -32,7 +32,7 @@ import ( "vitess.io/vitess/go/tools/codegen" ) -const licenseFileHeader = `Copyright 2023 The Vitess Authors. +const licenseFileHeader = `Copyright 2025 The Vitess Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -51,7 +51,7 @@ type ( addType(t types.Type) scope() *types.Scope findImplementations(iff *types.Interface, impl func(types.Type) error) error - iface() *types.Interface + iface() *types.Interface // the root interface that all nodes are expected to implement } generator interface { genFile() (string, *jen.File) @@ -61,6 +61,7 @@ type ( ptrToBasicMethod(t types.Type, basic *types.Basic, spi generatorSPI) error sliceMethod(t types.Type, slice *types.Slice, spi generatorSPI) error basicMethod(t types.Type, basic *types.Basic, spi generatorSPI) error + close(spi generatorSPI) error } // astHelperGen finds implementations of the given interface, // and uses the supplied `generator`s to produce the output code @@ -218,6 +219,7 @@ func GenerateASTHelpers(options *Options) (map[string]*jen.File, error) { generator := newGenerator(loaded[0].Module, loaded[0].TypesSizes, nt, newEqualsGen(pName, &options.Equals), newCloneGen(pName, &options.Clone), + newPathGen(pName), newVisitGen(pName), newRewriterGen(pName, types.TypeString(nt, noQualifier), exprInterface), newCOWGen(pName, nt), diff --git a/go/tools/asthelpergen/clone_gen.go b/go/tools/asthelpergen/clone_gen.go index 10387a5dc25..6080e841e3a 100644 --- a/go/tools/asthelpergen/clone_gen.go +++ b/go/tools/asthelpergen/clone_gen.go @@ -110,6 +110,8 @@ func (c *cloneGen) basicMethod(t types.Type, basic *types.Basic, spi generatorSP return nil } +func (*cloneGen) close(generatorSPI) error { return nil } + func (c *cloneGen) copySliceElement(t types.Type, elType types.Type, spi generatorSPI) jen.Code { if !isNamed(t) && isBasic(elType) { // copy(res, n) diff --git a/go/tools/asthelpergen/copy_on_rewrite_gen.go b/go/tools/asthelpergen/copy_on_rewrite_gen.go index 1daa8d18981..851b4e53322 100644 --- a/go/tools/asthelpergen/copy_on_rewrite_gen.go +++ b/go/tools/asthelpergen/copy_on_rewrite_gen.go @@ -132,6 +132,8 @@ func (c *cowGen) basicMethod(t types.Type, basic *types.Basic, spi generatorSPI) return nil } +func (*cowGen) close(generatorSPI) error { return nil } + func ifNotNil(id string, stmts ...jen.Code) *jen.Statement { return jen.If(jen.Id(id).Op("!=").Nil()).Block(stmts...) } diff --git a/go/tools/asthelpergen/equals_gen.go b/go/tools/asthelpergen/equals_gen.go index e00c3ef596a..8f2c3e8de64 100644 --- a/go/tools/asthelpergen/equals_gen.go +++ b/go/tools/asthelpergen/equals_gen.go @@ -303,6 +303,6 @@ func (e *equalsGen) sliceMethod(t types.Type, slice *types.Slice, spi generatorS return nil } -func (e *equalsGen) basicMethod(types.Type, *types.Basic, generatorSPI) error { - return nil -} +func (*equalsGen) basicMethod(types.Type, *types.Basic, generatorSPI) error { return nil } + +func (*equalsGen) close(generatorSPI) error { return nil } diff --git a/go/tools/asthelpergen/rewrite_gen.go b/go/tools/asthelpergen/rewrite_gen.go index cc8b18a78e9..8975f347650 100644 --- a/go/tools/asthelpergen/rewrite_gen.go +++ b/go/tools/asthelpergen/rewrite_gen.go @@ -269,6 +269,8 @@ func (r *rewriteGen) basicMethod(t types.Type, _ *types.Basic, spi generatorSPI) return nil } +func (*rewriteGen) close(generatorSPI) error { return nil } + func (r *rewriteGen) rewriteFunc(t types.Type, stmts []jen.Code) { /* diff --git a/go/tools/asthelpergen/visit_gen.go b/go/tools/asthelpergen/visit_gen.go index 51d8651f090..aea6567ee0f 100644 --- a/go/tools/asthelpergen/visit_gen.go +++ b/go/tools/asthelpergen/visit_gen.go @@ -205,6 +205,8 @@ func (v *visitGen) basicMethod(t types.Type, basic *types.Basic, spi generatorSP return v.visitNoChildren(t, spi) } +func (*visitGen) close(generatorSPI) error { return nil } + func (v *visitGen) visitNoChildren(t types.Type, spi generatorSPI) error { stmts := []jen.Code{ jen.Id("_, err := f(in)"), @@ -220,7 +222,8 @@ func visitAllStructFields(strct *types.Struct, spi generatorSPI) []jen.Code { output := []jen.Code{ visitIn(), } - for i := 0; i < strct.NumFields(); i++ { + + for i := range strct.NumFields() { field := strct.Field(i) if types.Implements(field.Type(), spi.iface()) { spi.addType(field.Type()) diff --git a/go/vt/sqlparser/ast_path.go b/go/vt/sqlparser/ast_path.go new file mode 100644 index 00000000000..8c9e6df9d9c --- /dev/null +++ b/go/vt/sqlparser/ast_path.go @@ -0,0 +1,18 @@ +/* +Copyright 2023 The Vitess Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +// Code generated by ASTHelperGen. DO NOT EDIT. + +package sqlparser From ccf7e4a2dd41e63e3228b66ee8fbaa07171b1cce Mon Sep 17 00:00:00 2001 From: Andres Taylor Date: Tue, 28 Jan 2025 13:16:40 +0100 Subject: [PATCH 02/13] generate the step enum Signed-off-by: Andres Taylor --- go/tools/asthelpergen/ast_path_gen.go | 88 ++- go/tools/asthelpergen/asthelpergen.go | 1 - go/tools/asthelpergen/clone_gen.go | 2 - go/tools/asthelpergen/copy_on_rewrite_gen.go | 2 - go/tools/asthelpergen/equals_gen.go | 2 - go/tools/asthelpergen/rewrite_gen.go | 2 - go/tools/asthelpergen/visit_gen.go | 2 - go/vt/sqlparser/ast_clone.go | 2 +- go/vt/sqlparser/ast_copy_on_rewrite.go | 2 +- go/vt/sqlparser/ast_equals.go | 2 +- go/vt/sqlparser/ast_path.go | 622 +++++++++++++++++- go/vt/sqlparser/ast_rewrite.go | 2 +- go/vt/sqlparser/ast_visit.go | 2 +- .../planbuilder/operators/route_planning.go | 16 +- .../planbuilder/operators/sharded_routing.go | 16 +- go/vt/vtgate/semantics/semantic_table.go | 15 + 16 files changed, 728 insertions(+), 50 deletions(-) diff --git a/go/tools/asthelpergen/ast_path_gen.go b/go/tools/asthelpergen/ast_path_gen.go index 98c9433a35f..574455d4bcc 100644 --- a/go/tools/asthelpergen/ast_path_gen.go +++ b/go/tools/asthelpergen/ast_path_gen.go @@ -1,8 +1,9 @@ package asthelpergen import ( - "github.com/dave/jennifer/jen" "go/types" + + "github.com/dave/jennifer/jen" ) type ( @@ -11,8 +12,10 @@ type ( steps []step } step struct { - name string - typ types.Type + container string // the type of the container + name string // the name of the field + slice bool // whether the field is a slice + typ types.Type // the type of the field } ) @@ -29,43 +32,60 @@ func newPathGen(pkgname string) *pathGen { } func (p *pathGen) genFile() (string, *jen.File) { + p.close() return "ast_path.go", p.file } func (p *pathGen) interfaceMethod(t types.Type, iface *types.Interface, spi generatorSPI) error { - // don't think we need to do anything here return nil } func (p *pathGen) structMethod(t types.Type, strct *types.Struct, spi generatorSPI) error { - typeString := types.TypeString(t, noQualifier) + p.addStructFields(t, strct, spi) + return nil +} + +func (p *pathGen) ptrToStructMethod(t types.Type, strct *types.Struct, spi generatorSPI) error { + p.addStructFields(t, strct, spi) + return nil +} + +func (p *pathGen) addStructFields(t types.Type, strct *types.Struct, spi generatorSPI) { + typeString := printableTypeName(t) for i := range strct.NumFields() { field := strct.Field(i) if types.Implements(field.Type(), spi.iface()) { - + p.steps = append(p.steps, step{ + container: typeString, + name: field.Name(), + typ: field.Type(), + }) continue } slice, isSlice := field.Type().(*types.Slice) if isSlice && types.Implements(slice.Elem(), spi.iface()) { - spi.addType(slice.Elem()) - output = append(output, jen.For(jen.Id("_, el := range in."+field.Name())).Block( - visitChild(slice.Elem(), jen.Id("el")), - )) + p.steps = append(p.steps, step{ + container: typeString, + slice: true, + name: field.Name(), + typ: slice.Elem(), + }) } } - - return nil -} - -func (p *pathGen) ptrToStructMethod(t types.Type, strct *types.Struct, spi generatorSPI) error { - return nil } func (p *pathGen) ptrToBasicMethod(t types.Type, basic *types.Basic, spi generatorSPI) error { return nil } -func (p *pathGen) sliceMethod(t types.Type, slice *types.Slice, spi generatorSPI) error { +func (p *pathGen) sliceMethod(t types.Type, _ *types.Slice, _ generatorSPI) error { + p.steps = append(p.steps, step{ + container: printableTypeName(t), + name: "Offset", + slice: true, + typ: t, + }) + return nil } @@ -73,4 +93,36 @@ func (p *pathGen) basicMethod(t types.Type, basic *types.Basic, spi generatorSPI return nil } -func (*pathGen) close(generatorSPI) error { return nil } +func (p *pathGen) close() { + // Declare the ASTStep type with underlying type uint16 + astStepType := jen.Type().Id("ASTStep").Uint16() + + // Initialize a slice to hold the constant definitions + var constDefs []jen.Code + addStep := func(step string) { + if constDefs == nil { + // Use iota for the first constant + constDefs = append(constDefs, jen.Id(step).Id("ASTStep").Op("=").Id("iota")) + return + } + + constDefs = append(constDefs, jen.Id(step)) + } + for _, step := range p.steps { + stepName := step.container + step.name + if step.slice { + addStep(stepName + "8") + addStep(stepName + "64") + continue + } + + addStep(stepName) + } + + // Create the const block with all step constants + constBlock := jen.Const().Defs(constDefs...) + + // Add the type declaration and const block as separate statements to the file + p.file.Add(astStepType) + p.file.Add(constBlock) +} diff --git a/go/tools/asthelpergen/asthelpergen.go b/go/tools/asthelpergen/asthelpergen.go index 1845d3b1893..a81925c33a4 100644 --- a/go/tools/asthelpergen/asthelpergen.go +++ b/go/tools/asthelpergen/asthelpergen.go @@ -61,7 +61,6 @@ type ( ptrToBasicMethod(t types.Type, basic *types.Basic, spi generatorSPI) error sliceMethod(t types.Type, slice *types.Slice, spi generatorSPI) error basicMethod(t types.Type, basic *types.Basic, spi generatorSPI) error - close(spi generatorSPI) error } // astHelperGen finds implementations of the given interface, // and uses the supplied `generator`s to produce the output code diff --git a/go/tools/asthelpergen/clone_gen.go b/go/tools/asthelpergen/clone_gen.go index 6080e841e3a..10387a5dc25 100644 --- a/go/tools/asthelpergen/clone_gen.go +++ b/go/tools/asthelpergen/clone_gen.go @@ -110,8 +110,6 @@ func (c *cloneGen) basicMethod(t types.Type, basic *types.Basic, spi generatorSP return nil } -func (*cloneGen) close(generatorSPI) error { return nil } - func (c *cloneGen) copySliceElement(t types.Type, elType types.Type, spi generatorSPI) jen.Code { if !isNamed(t) && isBasic(elType) { // copy(res, n) diff --git a/go/tools/asthelpergen/copy_on_rewrite_gen.go b/go/tools/asthelpergen/copy_on_rewrite_gen.go index 851b4e53322..1daa8d18981 100644 --- a/go/tools/asthelpergen/copy_on_rewrite_gen.go +++ b/go/tools/asthelpergen/copy_on_rewrite_gen.go @@ -132,8 +132,6 @@ func (c *cowGen) basicMethod(t types.Type, basic *types.Basic, spi generatorSPI) return nil } -func (*cowGen) close(generatorSPI) error { return nil } - func ifNotNil(id string, stmts ...jen.Code) *jen.Statement { return jen.If(jen.Id(id).Op("!=").Nil()).Block(stmts...) } diff --git a/go/tools/asthelpergen/equals_gen.go b/go/tools/asthelpergen/equals_gen.go index 8f2c3e8de64..2c188a30d1d 100644 --- a/go/tools/asthelpergen/equals_gen.go +++ b/go/tools/asthelpergen/equals_gen.go @@ -304,5 +304,3 @@ func (e *equalsGen) sliceMethod(t types.Type, slice *types.Slice, spi generatorS } func (*equalsGen) basicMethod(types.Type, *types.Basic, generatorSPI) error { return nil } - -func (*equalsGen) close(generatorSPI) error { return nil } diff --git a/go/tools/asthelpergen/rewrite_gen.go b/go/tools/asthelpergen/rewrite_gen.go index 8975f347650..cc8b18a78e9 100644 --- a/go/tools/asthelpergen/rewrite_gen.go +++ b/go/tools/asthelpergen/rewrite_gen.go @@ -269,8 +269,6 @@ func (r *rewriteGen) basicMethod(t types.Type, _ *types.Basic, spi generatorSPI) return nil } -func (*rewriteGen) close(generatorSPI) error { return nil } - func (r *rewriteGen) rewriteFunc(t types.Type, stmts []jen.Code) { /* diff --git a/go/tools/asthelpergen/visit_gen.go b/go/tools/asthelpergen/visit_gen.go index aea6567ee0f..d82b3d8b661 100644 --- a/go/tools/asthelpergen/visit_gen.go +++ b/go/tools/asthelpergen/visit_gen.go @@ -205,8 +205,6 @@ func (v *visitGen) basicMethod(t types.Type, basic *types.Basic, spi generatorSP return v.visitNoChildren(t, spi) } -func (*visitGen) close(generatorSPI) error { return nil } - func (v *visitGen) visitNoChildren(t types.Type, spi generatorSPI) error { stmts := []jen.Code{ jen.Id("_, err := f(in)"), diff --git a/go/vt/sqlparser/ast_clone.go b/go/vt/sqlparser/ast_clone.go index 3c7f4fe5e6a..f61dd822cb1 100644 --- a/go/vt/sqlparser/ast_clone.go +++ b/go/vt/sqlparser/ast_clone.go @@ -1,5 +1,5 @@ /* -Copyright 2023 The Vitess Authors. +Copyright 2025 The Vitess Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/go/vt/sqlparser/ast_copy_on_rewrite.go b/go/vt/sqlparser/ast_copy_on_rewrite.go index f725dfc6803..fd7054a5164 100644 --- a/go/vt/sqlparser/ast_copy_on_rewrite.go +++ b/go/vt/sqlparser/ast_copy_on_rewrite.go @@ -1,5 +1,5 @@ /* -Copyright 2023 The Vitess Authors. +Copyright 2025 The Vitess Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/go/vt/sqlparser/ast_equals.go b/go/vt/sqlparser/ast_equals.go index 93f10376177..da4b5374a69 100644 --- a/go/vt/sqlparser/ast_equals.go +++ b/go/vt/sqlparser/ast_equals.go @@ -1,5 +1,5 @@ /* -Copyright 2023 The Vitess Authors. +Copyright 2025 The Vitess Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/go/vt/sqlparser/ast_path.go b/go/vt/sqlparser/ast_path.go index 8c9e6df9d9c..db7c7caf941 100644 --- a/go/vt/sqlparser/ast_path.go +++ b/go/vt/sqlparser/ast_path.go @@ -1,5 +1,5 @@ /* -Copyright 2023 The Vitess Authors. +Copyright 2025 The Vitess Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,3 +16,623 @@ limitations under the License. // Code generated by ASTHelperGen. DO NOT EDIT. package sqlparser + +type ASTStep uint16 + +const ( + RefOfAddColumnsColumns8 ASTStep = iota + RefOfAddColumnsColumns64 + RefOfAddColumnsAfter + RefOfAddConstraintDefinitionConstraintDefinition + RefOfAddIndexDefinitionIndexDefinition + RefOfAliasedExprExpr + RefOfAliasedExprAs + RefOfAliasedTableExprExpr + RefOfAliasedTableExprPartitions + RefOfAliasedTableExprAs + RefOfAliasedTableExprHints + RefOfAliasedTableExprColumns + RefOfAlterCheckName + RefOfAlterColumnColumn + RefOfAlterColumnDefaultVal + RefOfAlterDatabaseComments + RefOfAlterDatabaseDBName + RefOfAlterIndexName + RefOfAlterMigrationRatio + RefOfAlterTableTable + RefOfAlterTableAlterOptions8 + RefOfAlterTableAlterOptions64 + RefOfAlterTablePartitionSpec + RefOfAlterTablePartitionOption + RefOfAlterTableComments + RefOfAlterViewViewName + RefOfAlterViewDefiner + RefOfAlterViewColumns + RefOfAlterViewSelect + RefOfAlterViewComments + RefOfAlterVschemaTable + RefOfAlterVschemaVindexSpec + RefOfAlterVschemaVindexCols8 + RefOfAlterVschemaVindexCols64 + RefOfAlterVschemaAutoIncSpec + RefOfAnalyzeTable + RefOfAndExprLeft + RefOfAndExprRight + RefOfAnyValueArg + RefOfArgumentLessWindowExprOverClause + RefOfAssignmentExprLeft + RefOfAssignmentExprRight + RefOfAutoIncSpecColumn + RefOfAutoIncSpecSequence + RefOfAvgArg + RefOfAvgOverClause + RefOfBetweenExprLeft + RefOfBetweenExprFrom + RefOfBetweenExprTo + RefOfBinaryExprLeft + RefOfBinaryExprRight + RefOfBitAndArg + RefOfBitAndOverClause + RefOfBitOrArg + RefOfBitOrOverClause + RefOfBitXorArg + RefOfBitXorOverClause + RefOfCallProcName + RefOfCallProcParams + RefOfCaseExprExpr + RefOfCaseExprWhens8 + RefOfCaseExprWhens64 + RefOfCaseExprElse + RefOfCastExprExpr + RefOfCastExprType + RefOfChangeColumnOldColumn + RefOfChangeColumnNewColDefinition + RefOfChangeColumnAfter + RefOfCharExprExprs + RefOfCheckConstraintDefinitionExpr + RefOfColNameName + RefOfColNameQualifier + RefOfCollateExprExpr + RefOfColumnDefinitionName + RefOfColumnDefinitionType + ColumnsOffset8 + ColumnsOffset64 + RefOfCommonTableExprID + RefOfCommonTableExprColumns + RefOfCommonTableExprSubquery + RefOfComparisonExprLeft + RefOfComparisonExprRight + RefOfComparisonExprEscape + RefOfConstraintDefinitionName + RefOfConstraintDefinitionDetails + RefOfConvertExprExpr + RefOfConvertExprType + RefOfConvertUsingExprExpr + RefOfCountArgs + RefOfCountOverClause + RefOfCountStarOverClause + RefOfCreateDatabaseComments + RefOfCreateDatabaseDBName + RefOfCreateTableTable + RefOfCreateTableTableSpec + RefOfCreateTableOptLike + RefOfCreateTableComments + RefOfCreateViewViewName + RefOfCreateViewDefiner + RefOfCreateViewColumns + RefOfCreateViewSelect + RefOfCreateViewComments + RefOfCurTimeFuncExprName + RefOfDeallocateStmtComments + RefOfDeallocateStmtName + RefOfDeleteWith + RefOfDeleteComments + RefOfDeleteTableExprs8 + RefOfDeleteTableExprs64 + RefOfDeleteTargets + RefOfDeletePartitions + RefOfDeleteWhere + RefOfDeleteOrderBy + RefOfDeleteLimit + RefOfDerivedTableSelect + RefOfDropColumnName + RefOfDropDatabaseComments + RefOfDropDatabaseDBName + RefOfDropKeyName + RefOfDropTableFromTables + RefOfDropTableComments + RefOfDropViewFromTables + RefOfDropViewComments + RefOfExecuteStmtName + RefOfExecuteStmtComments + RefOfExecuteStmtArguments8 + RefOfExecuteStmtArguments64 + RefOfExistsExprSubquery + RefOfExplainStmtStatement + RefOfExplainStmtComments + RefOfExplainTabTable + ExprsOffset8 + ExprsOffset64 + RefOfExtractFuncExprExpr + RefOfExtractValueExprFragment + RefOfExtractValueExprXPathExpr + RefOfFirstOrLastValueExprExpr + RefOfFirstOrLastValueExprNullTreatmentClause + RefOfFirstOrLastValueExprOverClause + RefOfFlushTableNames + RefOfForeignKeyDefinitionSource + RefOfForeignKeyDefinitionIndexName + RefOfForeignKeyDefinitionReferenceDefinition + RefOfFrameClauseStart + RefOfFrameClauseEnd + RefOfFramePointExpr + RefOfFuncExprQualifier + RefOfFuncExprName + RefOfFuncExprExprs + RefOfGTIDFuncExprSet1 + RefOfGTIDFuncExprSet2 + RefOfGTIDFuncExprTimeout + RefOfGTIDFuncExprChannel + RefOfGeoHashFromLatLongExprLatitude + RefOfGeoHashFromLatLongExprLongitude + RefOfGeoHashFromLatLongExprMaxLength + RefOfGeoHashFromPointExprPoint + RefOfGeoHashFromPointExprMaxLength + RefOfGeoJSONFromGeomExprGeom + RefOfGeoJSONFromGeomExprMaxDecimalDigits + RefOfGeoJSONFromGeomExprBitmask + RefOfGeomCollPropertyFuncExprGeomColl + RefOfGeomCollPropertyFuncExprPropertyDefArg + RefOfGeomFormatExprGeom + RefOfGeomFormatExprAxisOrderOpt + RefOfGeomFromGeoHashExprGeoHash + RefOfGeomFromGeoHashExprSridOpt + RefOfGeomFromGeoJSONExprGeoJSON + RefOfGeomFromGeoJSONExprHigherDimHandlerOpt + RefOfGeomFromGeoJSONExprSrid + RefOfGeomFromTextExprWktText + RefOfGeomFromTextExprSrid + RefOfGeomFromTextExprAxisOrderOpt + RefOfGeomFromWKBExprWkbBlob + RefOfGeomFromWKBExprSrid + RefOfGeomFromWKBExprAxisOrderOpt + RefOfGeomPropertyFuncExprGeom + RefOfGroupByExprs8 + RefOfGroupByExprs64 + RefOfGroupConcatExprExprs + RefOfGroupConcatExprOrderBy + RefOfGroupConcatExprLimit + RefOfIndexDefinitionInfo + RefOfIndexHintIndexes8 + RefOfIndexHintIndexes64 + IndexHintsOffset8 + IndexHintsOffset64 + RefOfIndexInfoName + RefOfIndexInfoConstraintName + RefOfInsertComments + RefOfInsertTable + RefOfInsertPartitions + RefOfInsertColumns + RefOfInsertRows + RefOfInsertRowAlias + RefOfInsertOnDup + RefOfInsertExprStr + RefOfInsertExprPos + RefOfInsertExprLen + RefOfInsertExprNewStr + RefOfIntervalDateExprDate + RefOfIntervalDateExprInterval + RefOfIntervalFuncExprExpr + RefOfIntervalFuncExprExprs + RefOfIntroducerExprExpr + RefOfIsExprLeft + RefOfJSONArrayAggExpr + RefOfJSONArrayAggOverClause + RefOfJSONArrayExprParams + RefOfJSONAttributesExprJSONDoc + RefOfJSONAttributesExprPath + RefOfJSONContainsExprTarget + RefOfJSONContainsExprCandidate + RefOfJSONContainsExprPathList8 + RefOfJSONContainsExprPathList64 + RefOfJSONContainsPathExprJSONDoc + RefOfJSONContainsPathExprOneOrAll + RefOfJSONContainsPathExprPathList8 + RefOfJSONContainsPathExprPathList64 + RefOfJSONExtractExprJSONDoc + RefOfJSONExtractExprPathList8 + RefOfJSONExtractExprPathList64 + RefOfJSONKeysExprJSONDoc + RefOfJSONKeysExprPath + RefOfJSONObjectAggKey + RefOfJSONObjectAggValue + RefOfJSONObjectAggOverClause + RefOfJSONObjectExprParams8 + RefOfJSONObjectExprParams64 + RefOfJSONObjectParamKey + RefOfJSONObjectParamValue + RefOfJSONOverlapsExprJSONDoc1 + RefOfJSONOverlapsExprJSONDoc2 + RefOfJSONPrettyExprJSONVal + RefOfJSONQuoteExprStringArg + RefOfJSONRemoveExprJSONDoc + RefOfJSONRemoveExprPathList + RefOfJSONSchemaValidFuncExprSchema + RefOfJSONSchemaValidFuncExprDocument + RefOfJSONSchemaValidationReportFuncExprSchema + RefOfJSONSchemaValidationReportFuncExprDocument + RefOfJSONSearchExprJSONDoc + RefOfJSONSearchExprOneOrAll + RefOfJSONSearchExprSearchStr + RefOfJSONSearchExprEscapeChar + RefOfJSONSearchExprPathList8 + RefOfJSONSearchExprPathList64 + RefOfJSONStorageFreeExprJSONVal + RefOfJSONStorageSizeExprJSONVal + RefOfJSONTableExprExpr + RefOfJSONTableExprAlias + RefOfJSONTableExprFilter + RefOfJSONTableExprColumns8 + RefOfJSONTableExprColumns64 + RefOfJSONUnquoteExprJSONValue + RefOfJSONValueExprJSONDoc + RefOfJSONValueExprPath + RefOfJSONValueExprReturningType + RefOfJSONValueExprEmptyOnResponse + RefOfJSONValueExprErrorOnResponse + RefOfJSONValueMergeExprJSONDoc + RefOfJSONValueMergeExprJSONDocList + RefOfJSONValueModifierExprJSONDoc + RefOfJSONValueModifierExprParams8 + RefOfJSONValueModifierExprParams64 + RefOfJoinConditionOn + RefOfJoinConditionUsing + RefOfJoinTableExprLeftExpr + RefOfJoinTableExprRightExpr + RefOfJoinTableExprCondition + RefOfJtOnResponseExpr + RefOfLagLeadExprExpr + RefOfLagLeadExprN + RefOfLagLeadExprDefault + RefOfLagLeadExprOverClause + RefOfLagLeadExprNullTreatmentClause + RefOfLimitOffset + RefOfLimitRowcount + RefOfLineStringExprPointParams + RefOfLinestrPropertyFuncExprLinestring + RefOfLinestrPropertyFuncExprPropertyDefArg + RefOfLocateExprSubStr + RefOfLocateExprStr + RefOfLocateExprPos + RefOfLockingFuncName + RefOfLockingFuncTimeout + RefOfMatchExprColumns8 + RefOfMatchExprColumns64 + RefOfMatchExprExpr + RefOfMaxArg + RefOfMaxOverClause + RefOfMemberOfExprValue + RefOfMemberOfExprJSONArr + RefOfMinArg + RefOfMinOverClause + RefOfModifyColumnNewColDefinition + RefOfModifyColumnAfter + RefOfMultiLinestringExprLinestringParams + RefOfMultiPointExprPointParams + RefOfMultiPolygonExprPolygonParams + RefOfNTHValueExprExpr + RefOfNTHValueExprN + RefOfNTHValueExprOverClause + RefOfNTHValueExprFromFirstLastClause + RefOfNTHValueExprNullTreatmentClause + RefOfNamedWindowWindows + NamedWindowsOffset8 + NamedWindowsOffset64 + RefOfNextvalExpr + RefOfNotExprExpr + RefOfNtileExprN + RefOfNtileExprOverClause + RefOfOffsetOriginal + OnDupOffset8 + OnDupOffset64 + RefOfOptLikeLikeTable + RefOfOrExprLeft + RefOfOrExprRight + RefOfOrderExpr + OrderByOffset8 + OrderByOffset64 + RefOfOrderByOptionCols + RefOfOverClauseWindowName + RefOfOverClauseWindowSpec + RefOfParenTableExprExprs + RefOfPartitionDefinitionName + RefOfPartitionDefinitionOptions + RefOfPartitionDefinitionOptionsValueRange + RefOfPartitionDefinitionOptionsComment + RefOfPartitionDefinitionOptionsEngine + RefOfPartitionDefinitionOptionsDataDirectory + RefOfPartitionDefinitionOptionsIndexDirectory + RefOfPartitionDefinitionOptionsSubPartitionDefinitions + RefOfPartitionOptionColList + RefOfPartitionOptionExpr + RefOfPartitionOptionSubPartition + RefOfPartitionOptionDefinitions8 + RefOfPartitionOptionDefinitions64 + RefOfPartitionSpecNames + RefOfPartitionSpecNumber + RefOfPartitionSpecTableName + RefOfPartitionSpecDefinitions8 + RefOfPartitionSpecDefinitions64 + RefOfPartitionValueRangeRange + PartitionsOffset8 + PartitionsOffset64 + RefOfPerformanceSchemaFuncExprArgument + RefOfPointExprXCordinate + RefOfPointExprYCordinate + RefOfPointPropertyFuncExprPoint + RefOfPointPropertyFuncExprValueToSet + RefOfPolygonExprLinestringParams + RefOfPolygonPropertyFuncExprPolygon + RefOfPolygonPropertyFuncExprPropertyDefArg + RefOfPrepareStmtName + RefOfPrepareStmtStatement + RefOfPrepareStmtComments + RefOfReferenceDefinitionReferencedTable + RefOfReferenceDefinitionReferencedColumns + RefOfReferenceDefinitionMatch + RefOfReferenceDefinitionOnDelete + RefOfReferenceDefinitionOnUpdate + RefOfRegexpInstrExprExpr + RefOfRegexpInstrExprPattern + RefOfRegexpInstrExprPosition + RefOfRegexpInstrExprOccurrence + RefOfRegexpInstrExprReturnOption + RefOfRegexpInstrExprMatchType + RefOfRegexpLikeExprExpr + RefOfRegexpLikeExprPattern + RefOfRegexpLikeExprMatchType + RefOfRegexpReplaceExprExpr + RefOfRegexpReplaceExprPattern + RefOfRegexpReplaceExprRepl + RefOfRegexpReplaceExprOccurrence + RefOfRegexpReplaceExprPosition + RefOfRegexpReplaceExprMatchType + RefOfRegexpSubstrExprExpr + RefOfRegexpSubstrExprPattern + RefOfRegexpSubstrExprOccurrence + RefOfRegexpSubstrExprPosition + RefOfRegexpSubstrExprMatchType + RefOfReleaseName + RefOfRenameColumnOldName + RefOfRenameColumnNewName + RefOfRenameIndexOldName + RefOfRenameIndexNewName + RefOfRenameTableNameTable + RefOfRevertMigrationComments + RootNodeSQLNode + RefOfRowAliasTableName + RefOfRowAliasColumns + RefOfSRollbackName + RefOfSavepointName + RefOfSelectWith + RefOfSelectFrom8 + RefOfSelectFrom64 + RefOfSelectComments + RefOfSelectSelectExprs + RefOfSelectWhere + RefOfSelectGroupBy + RefOfSelectHaving + RefOfSelectWindows + RefOfSelectOrderBy + RefOfSelectLimit + RefOfSelectInto + SelectExprsOffset8 + SelectExprsOffset64 + RefOfSetComments + RefOfSetExprs + RefOfSetExprVar + RefOfSetExprExpr + SetExprsOffset8 + SetExprsOffset64 + RefOfShowInternal + RefOfShowBasicTbl + RefOfShowBasicDbName + RefOfShowBasicFilter + RefOfShowCreateOp + RefOfShowFilterFilter + RefOfShowMigrationLogsComments + RefOfStarExprTableName + RefOfStdArg + RefOfStdOverClause + RefOfStdDevArg + RefOfStdDevOverClause + RefOfStdPopArg + RefOfStdPopOverClause + RefOfStdSampArg + RefOfStdSampOverClause + RefOfStreamComments + RefOfStreamSelectExpr + RefOfStreamTable + RefOfSubPartitionColList + RefOfSubPartitionExpr + RefOfSubPartitionDefinitionName + RefOfSubPartitionDefinitionOptions + RefOfSubPartitionDefinitionOptionsComment + RefOfSubPartitionDefinitionOptionsEngine + RefOfSubPartitionDefinitionOptionsDataDirectory + RefOfSubPartitionDefinitionOptionsIndexDirectory + SubPartitionDefinitionsOffset8 + SubPartitionDefinitionsOffset64 + RefOfSubquerySelect + RefOfSubstrExprName + RefOfSubstrExprFrom + RefOfSubstrExprTo + RefOfSumArg + RefOfSumOverClause + TableExprsOffset8 + TableExprsOffset64 + TableNameName + TableNameQualifier + TableNamesOffset8 + TableNamesOffset64 + TableOptionsOffset8 + TableOptionsOffset64 + RefOfTableSpecColumns8 + RefOfTableSpecColumns64 + RefOfTableSpecIndexes8 + RefOfTableSpecIndexes64 + RefOfTableSpecConstraints8 + RefOfTableSpecConstraints64 + RefOfTableSpecOptions + RefOfTableSpecPartitionOption + RefOfTimestampDiffExprExpr1 + RefOfTimestampDiffExprExpr2 + RefOfTrimFuncExprTrimArg + RefOfTrimFuncExprStringArg + RefOfTruncateTableTable + RefOfUnaryExprExpr + RefOfUnionWith + RefOfUnionLeft + RefOfUnionRight + RefOfUnionOrderBy + RefOfUnionLimit + RefOfUnionInto + RefOfUpdateWith + RefOfUpdateComments + RefOfUpdateTableExprs8 + RefOfUpdateTableExprs64 + RefOfUpdateExprs + RefOfUpdateWhere + RefOfUpdateOrderBy + RefOfUpdateLimit + RefOfUpdateExprName + RefOfUpdateExprExpr + UpdateExprsOffset8 + UpdateExprsOffset64 + RefOfUpdateXMLExprTarget + RefOfUpdateXMLExprXPathExpr + RefOfUpdateXMLExprNewXML + RefOfUseDBName + RefOfVExplainStmtStatement + RefOfVExplainStmtComments + RefOfVStreamComments + RefOfVStreamSelectExpr + RefOfVStreamTable + RefOfVStreamWhere + RefOfVStreamLimit + ValTupleOffset8 + ValTupleOffset64 + ValuesOffset8 + ValuesOffset64 + RefOfValuesFuncExprName + RefOfValuesStatementWith + RefOfValuesStatementRows + RefOfValuesStatementListArg + RefOfValuesStatementComments + RefOfValuesStatementOrder + RefOfValuesStatementLimit + RefOfVarPopArg + RefOfVarPopOverClause + RefOfVarSampArg + RefOfVarSampOverClause + RefOfVariableName + RefOfVarianceArg + RefOfVarianceOverClause + VindexParamKey + RefOfVindexSpecName + RefOfVindexSpecType + RefOfVindexSpecParams8 + RefOfVindexSpecParams64 + RefOfWeightStringFuncExprExpr + RefOfWeightStringFuncExprAs + RefOfWhenCond + RefOfWhenVal + RefOfWhereExpr + RefOfWindowDefinitionName + RefOfWindowDefinitionWindowSpec + WindowDefinitionsOffset8 + WindowDefinitionsOffset64 + RefOfWindowSpecificationName + RefOfWindowSpecificationPartitionClause + RefOfWindowSpecificationOrderClause + RefOfWindowSpecificationFrameClause + RefOfWithCTEs8 + RefOfWithCTEs64 + RefOfXorExprLeft + RefOfXorExprRight + SliceOfRefOfColumnDefinitionOffset8 + SliceOfRefOfColumnDefinitionOffset64 + SliceOfDatabaseOptionOffset8 + SliceOfDatabaseOptionOffset64 + SliceOfAlterOptionOffset8 + SliceOfAlterOptionOffset64 + SliceOfIdentifierCIOffset8 + SliceOfIdentifierCIOffset64 + SliceOfTxAccessModeOffset8 + SliceOfTxAccessModeOffset64 + SliceOfRefOfWhenOffset8 + SliceOfRefOfWhenOffset64 + RefOfColumnTypeOptionsDefault + RefOfColumnTypeOptionsOnUpdate + RefOfColumnTypeOptionsAs + RefOfColumnTypeOptionsComment + RefOfColumnTypeOptionsReference + RefOfColumnTypeOptionsEngineAttribute + RefOfColumnTypeOptionsSecondaryEngineAttribute + RefOfColumnTypeOptionsSRID + SliceOfStringOffset8 + SliceOfStringOffset64 + SliceOfTableExprOffset8 + SliceOfTableExprOffset64 + SliceOfRefOfVariableOffset8 + SliceOfRefOfVariableOffset64 + SliceOfExprOffset8 + SliceOfExprOffset64 + SliceOfRefOfIndexColumnOffset8 + SliceOfRefOfIndexColumnOffset64 + SliceOfRefOfIndexOptionOffset8 + SliceOfRefOfIndexOptionOffset64 + SliceOfRefOfJSONObjectParamOffset8 + SliceOfRefOfJSONObjectParamOffset64 + SliceOfRefOfJtColumnDefinitionOffset8 + SliceOfRefOfJtColumnDefinitionOffset64 + RefOfJtOrdinalColDefName + RefOfJtPathColDefName + RefOfJtPathColDefType + RefOfJtPathColDefPath + RefOfJtPathColDefEmptyOnResponse + RefOfJtPathColDefErrorOnResponse + RefOfJtNestedPathColDefPath + RefOfJtNestedPathColDefColumns8 + RefOfJtNestedPathColDefColumns64 + TableAndLockTypesOffset8 + TableAndLockTypesOffset64 + SliceOfRefOfColNameOffset8 + SliceOfRefOfColNameOffset64 + CommentsOffset8 + CommentsOffset64 + SliceOfRefOfPartitionDefinitionOffset8 + SliceOfRefOfPartitionDefinitionOffset64 + SliceOfRefOfRenameTablePairOffset8 + SliceOfRefOfRenameTablePairOffset64 + RefOfRootNodeSQLNode + RefOfTableNameName + RefOfTableNameQualifier + RefOfTableOptionValue + RefOfTableOptionTables + SliceOfRefOfIndexDefinitionOffset8 + SliceOfRefOfIndexDefinitionOffset64 + SliceOfRefOfConstraintDefinitionOffset8 + SliceOfRefOfConstraintDefinitionOffset64 + RefOfVindexParamKey + SliceOfVindexParamOffset8 + SliceOfVindexParamOffset64 + SliceOfRefOfCommonTableExprOffset8 + SliceOfRefOfCommonTableExprOffset64 + RefOfIndexColumnColumn + RefOfIndexColumnExpression + RefOfIndexOptionValue + RefOfTableAndLockTypeTable + RefOfRenameTablePairFromTable + RefOfRenameTablePairToTable +) diff --git a/go/vt/sqlparser/ast_rewrite.go b/go/vt/sqlparser/ast_rewrite.go index 690b381b082..20883b914b5 100644 --- a/go/vt/sqlparser/ast_rewrite.go +++ b/go/vt/sqlparser/ast_rewrite.go @@ -1,5 +1,5 @@ /* -Copyright 2023 The Vitess Authors. +Copyright 2025 The Vitess Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/go/vt/sqlparser/ast_visit.go b/go/vt/sqlparser/ast_visit.go index a7fbbe02118..1e992895472 100644 --- a/go/vt/sqlparser/ast_visit.go +++ b/go/vt/sqlparser/ast_visit.go @@ -1,5 +1,5 @@ /* -Copyright 2023 The Vitess Authors. +Copyright 2025 The Vitess Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/go/vt/vtgate/planbuilder/operators/route_planning.go b/go/vt/vtgate/planbuilder/operators/route_planning.go index 90eb16e1562..b4c1ad4911e 100644 --- a/go/vt/vtgate/planbuilder/operators/route_planning.go +++ b/go/vt/vtgate/planbuilder/operators/route_planning.go @@ -375,14 +375,12 @@ func findColumnVindex(ctx *plancontext.PlanningContext, a Operator, exp sqlparse // can be solved by any table in our routeTree. If an equality expression can be solved, // we check if the equality expression and our table share the same vindex, if they do: // the method will return the associated vindexes.SingleColumn. - for _, expr := range ctx.SemTable.GetExprAndEqualities(exp) { - col, isCol := expr.(*sqlparser.ColName) + _ = ctx.SemTable.ForEachExprEquality(exp, func(e sqlparser.Expr) error { + col, isCol := e.(*sqlparser.ColName) if !isCol { - continue + return nil } - - deps := ctx.SemTable.RecursiveDeps(expr) - + deps := ctx.SemTable.RecursiveDeps(col) _ = Visit(a, func(rel Operator) error { to, isTableOp := rel.(tableIDIntroducer) if !isTableOp { @@ -408,10 +406,12 @@ func findColumnVindex(ctx *plancontext.PlanningContext, a Operator, exp sqlparse } return nil }) + if singCol != nil { - return singCol + return io.EOF } - } + return nil + }) return singCol } diff --git a/go/vt/vtgate/planbuilder/operators/sharded_routing.go b/go/vt/vtgate/planbuilder/operators/sharded_routing.go index 2c8873dee07..1867ca6135f 100644 --- a/go/vt/vtgate/planbuilder/operators/sharded_routing.go +++ b/go/vt/vtgate/planbuilder/operators/sharded_routing.go @@ -18,6 +18,7 @@ package operators import ( "fmt" + "io" "slices" "vitess.io/vitess/go/mysql/collations" @@ -720,17 +721,18 @@ func tryMergeShardedRouting( } // makeEvalEngineExpr transforms the given sqlparser.Expr into an evalengine expression -func makeEvalEngineExpr(ctx *plancontext.PlanningContext, n sqlparser.Expr) evalengine.Expr { - for _, expr := range ctx.SemTable.GetExprAndEqualities(n) { - ee, _ := evalengine.Translate(expr, &evalengine.Config{ +func makeEvalEngineExpr(ctx *plancontext.PlanningContext, n sqlparser.Expr) (result evalengine.Expr) { + _ = ctx.SemTable.ForEachExprEquality(n, func(expr sqlparser.Expr) error { + result, _ = evalengine.Translate(expr, &evalengine.Config{ Collation: ctx.SemTable.Collation, ResolveType: ctx.TypeForExpr, Environment: ctx.VSchema.Environment(), }) - if ee != nil { - return ee + if result != nil { + return io.EOF } - } + return nil + }) - return nil + return } diff --git a/go/vt/vtgate/semantics/semantic_table.go b/go/vt/vtgate/semantics/semantic_table.go index e3eead71c90..a09a3065970 100644 --- a/go/vt/vtgate/semantics/semantic_table.go +++ b/go/vt/vtgate/semantics/semantic_table.go @@ -651,6 +651,21 @@ func (st *SemTable) GetExprAndEqualities(expr sqlparser.Expr) []sqlparser.Expr { return result } +// ForEachExprEquality returns a slice containing the given expression, and it's known equalities if any +func (st *SemTable) ForEachExprEquality(in sqlparser.Expr, forEach func(sqlparser.Expr) error) error { + switch expr := in.(type) { + case *sqlparser.ColName: + table := st.DirectDeps(expr) + k := columnName{Table: table, ColumnName: expr.Name.String()} + for _, expr := range st.ColumnEqualities[k] { + if err := forEach(expr); err != nil { + return err + } + } + } + return nil +} + // TableInfoForExpr returns the table info of the table that this expression depends on. // Careful: this only works for expressions that have a single table dependency func (st *SemTable) TableInfoForExpr(expr sqlparser.Expr) (TableInfo, error) { From 0ffbcad88d2e66cc144ce0097224398695791bad Mon Sep 17 00:00:00 2001 From: Andres Taylor Date: Tue, 28 Jan 2025 14:11:08 +0100 Subject: [PATCH 03/13] add debug strings Signed-off-by: Andres Taylor --- go/tools/asthelpergen/ast_path_gen.go | 82 +- go/vt/sqlparser/ast_path.go | 1368 +++++++++++++++++++++++-- go/vt/sqlparser/paths.go | 51 + 3 files changed, 1421 insertions(+), 80 deletions(-) create mode 100644 go/vt/sqlparser/paths.go diff --git a/go/tools/asthelpergen/ast_path_gen.go b/go/tools/asthelpergen/ast_path_gen.go index 574455d4bcc..6345ab3c188 100644 --- a/go/tools/asthelpergen/ast_path_gen.go +++ b/go/tools/asthelpergen/ast_path_gen.go @@ -1,6 +1,23 @@ +/* +Copyright 2025 The Vitess Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + package asthelpergen import ( + "fmt" "go/types" "github.com/dave/jennifer/jen" @@ -12,7 +29,7 @@ type ( steps []step } step struct { - container string // the type of the container + container types.Type // the type of the container name string // the name of the field slice bool // whether the field is a slice typ types.Type // the type of the field @@ -51,12 +68,11 @@ func (p *pathGen) ptrToStructMethod(t types.Type, strct *types.Struct, spi gener } func (p *pathGen) addStructFields(t types.Type, strct *types.Struct, spi generatorSPI) { - typeString := printableTypeName(t) for i := range strct.NumFields() { field := strct.Field(i) if types.Implements(field.Type(), spi.iface()) { p.steps = append(p.steps, step{ - container: typeString, + container: t, name: field.Name(), typ: field.Type(), }) @@ -65,7 +81,7 @@ func (p *pathGen) addStructFields(t types.Type, strct *types.Struct, spi generat slice, isSlice := field.Type().(*types.Slice) if isSlice && types.Implements(slice.Elem(), spi.iface()) { p.steps = append(p.steps, step{ - container: typeString, + container: t, slice: true, name: field.Name(), typ: slice.Elem(), @@ -80,7 +96,7 @@ func (p *pathGen) ptrToBasicMethod(t types.Type, basic *types.Basic, spi generat func (p *pathGen) sliceMethod(t types.Type, _ *types.Slice, _ generatorSPI) error { p.steps = append(p.steps, step{ - container: printableTypeName(t), + container: t, name: "Offset", slice: true, typ: t, @@ -94,10 +110,52 @@ func (p *pathGen) basicMethod(t types.Type, basic *types.Basic, spi generatorSPI } func (p *pathGen) close() { + p.file.ImportName("fmt", "fmt") + // Declare the ASTStep type with underlying type uint16 - astStepType := jen.Type().Id("ASTStep").Uint16() + p.file.Add(jen.Type().Id("ASTStep").Uint16()) + + // Add the const block + p.file.Add(p.buildConstWithEnum()) + + // Add the DebugString() method to the file + p.file.Add(p.debugString()) +} + +func (p *pathGen) debugString() *jen.Statement { + var switchCases []jen.Code + + for _, step := range p.steps { + stepName := printableTypeName(step.container) + step.name + + // Generate the debug string using the helper function + debugStr := fmt.Sprintf("%s:%s(%s)", types.TypeString(step.container, noQualifier), step.name, types.TypeString(step.typ, noQualifier)) - // Initialize a slice to hold the constant definitions + if !step.slice { + switchCases = append(switchCases, jen.Case(jen.Id(stepName)).Block( + jen.Return(jen.Lit(debugStr)), + )) + continue + } + + switchCases = append(switchCases, jen.Case(jen.Id(stepName+"8")).Block( + jen.Return(jen.Lit(debugStr+"8")), + )) + switchCases = append(switchCases, jen.Case(jen.Id(stepName+"32")).Block( + jen.Return(jen.Lit(debugStr+"32")), + )) + + } + + debugStringMethod := jen.Func().Params(jen.Id("s").Id("ASTStep")).Id("DebugString").Params().String().Block( + jen.Switch(jen.Id("s")).Block(switchCases...), + jen.Panic(jen.Lit("unknown ASTStep")), + ) + return debugStringMethod +} + +func (p *pathGen) buildConstWithEnum() *jen.Statement { + // Create the const block with all step constants var constDefs []jen.Code addStep := func(step string) { if constDefs == nil { @@ -109,20 +167,16 @@ func (p *pathGen) close() { constDefs = append(constDefs, jen.Id(step)) } for _, step := range p.steps { - stepName := step.container + step.name + stepName := printableTypeName(step.container) + step.name if step.slice { addStep(stepName + "8") - addStep(stepName + "64") + addStep(stepName + "32") continue } addStep(stepName) } - // Create the const block with all step constants constBlock := jen.Const().Defs(constDefs...) - - // Add the type declaration and const block as separate statements to the file - p.file.Add(astStepType) - p.file.Add(constBlock) + return constBlock } diff --git a/go/vt/sqlparser/ast_path.go b/go/vt/sqlparser/ast_path.go index db7c7caf941..56e35f2b2b2 100644 --- a/go/vt/sqlparser/ast_path.go +++ b/go/vt/sqlparser/ast_path.go @@ -21,7 +21,7 @@ type ASTStep uint16 const ( RefOfAddColumnsColumns8 ASTStep = iota - RefOfAddColumnsColumns64 + RefOfAddColumnsColumns32 RefOfAddColumnsAfter RefOfAddConstraintDefinitionConstraintDefinition RefOfAddIndexDefinitionIndexDefinition @@ -41,7 +41,7 @@ const ( RefOfAlterMigrationRatio RefOfAlterTableTable RefOfAlterTableAlterOptions8 - RefOfAlterTableAlterOptions64 + RefOfAlterTableAlterOptions32 RefOfAlterTablePartitionSpec RefOfAlterTablePartitionOption RefOfAlterTableComments @@ -53,7 +53,7 @@ const ( RefOfAlterVschemaTable RefOfAlterVschemaVindexSpec RefOfAlterVschemaVindexCols8 - RefOfAlterVschemaVindexCols64 + RefOfAlterVschemaVindexCols32 RefOfAlterVschemaAutoIncSpec RefOfAnalyzeTable RefOfAndExprLeft @@ -81,7 +81,7 @@ const ( RefOfCallProcParams RefOfCaseExprExpr RefOfCaseExprWhens8 - RefOfCaseExprWhens64 + RefOfCaseExprWhens32 RefOfCaseExprElse RefOfCastExprExpr RefOfCastExprType @@ -96,7 +96,7 @@ const ( RefOfColumnDefinitionName RefOfColumnDefinitionType ColumnsOffset8 - ColumnsOffset64 + ColumnsOffset32 RefOfCommonTableExprID RefOfCommonTableExprColumns RefOfCommonTableExprSubquery @@ -128,7 +128,7 @@ const ( RefOfDeleteWith RefOfDeleteComments RefOfDeleteTableExprs8 - RefOfDeleteTableExprs64 + RefOfDeleteTableExprs32 RefOfDeleteTargets RefOfDeletePartitions RefOfDeleteWhere @@ -146,13 +146,13 @@ const ( RefOfExecuteStmtName RefOfExecuteStmtComments RefOfExecuteStmtArguments8 - RefOfExecuteStmtArguments64 + RefOfExecuteStmtArguments32 RefOfExistsExprSubquery RefOfExplainStmtStatement RefOfExplainStmtComments RefOfExplainTabTable ExprsOffset8 - ExprsOffset64 + ExprsOffset32 RefOfExtractFuncExprExpr RefOfExtractValueExprFragment RefOfExtractValueExprXPathExpr @@ -198,15 +198,15 @@ const ( RefOfGeomFromWKBExprAxisOrderOpt RefOfGeomPropertyFuncExprGeom RefOfGroupByExprs8 - RefOfGroupByExprs64 + RefOfGroupByExprs32 RefOfGroupConcatExprExprs RefOfGroupConcatExprOrderBy RefOfGroupConcatExprLimit RefOfIndexDefinitionInfo RefOfIndexHintIndexes8 - RefOfIndexHintIndexes64 + RefOfIndexHintIndexes32 IndexHintsOffset8 - IndexHintsOffset64 + IndexHintsOffset32 RefOfIndexInfoName RefOfIndexInfoConstraintName RefOfInsertComments @@ -234,21 +234,21 @@ const ( RefOfJSONContainsExprTarget RefOfJSONContainsExprCandidate RefOfJSONContainsExprPathList8 - RefOfJSONContainsExprPathList64 + RefOfJSONContainsExprPathList32 RefOfJSONContainsPathExprJSONDoc RefOfJSONContainsPathExprOneOrAll RefOfJSONContainsPathExprPathList8 - RefOfJSONContainsPathExprPathList64 + RefOfJSONContainsPathExprPathList32 RefOfJSONExtractExprJSONDoc RefOfJSONExtractExprPathList8 - RefOfJSONExtractExprPathList64 + RefOfJSONExtractExprPathList32 RefOfJSONKeysExprJSONDoc RefOfJSONKeysExprPath RefOfJSONObjectAggKey RefOfJSONObjectAggValue RefOfJSONObjectAggOverClause RefOfJSONObjectExprParams8 - RefOfJSONObjectExprParams64 + RefOfJSONObjectExprParams32 RefOfJSONObjectParamKey RefOfJSONObjectParamValue RefOfJSONOverlapsExprJSONDoc1 @@ -266,14 +266,14 @@ const ( RefOfJSONSearchExprSearchStr RefOfJSONSearchExprEscapeChar RefOfJSONSearchExprPathList8 - RefOfJSONSearchExprPathList64 + RefOfJSONSearchExprPathList32 RefOfJSONStorageFreeExprJSONVal RefOfJSONStorageSizeExprJSONVal RefOfJSONTableExprExpr RefOfJSONTableExprAlias RefOfJSONTableExprFilter RefOfJSONTableExprColumns8 - RefOfJSONTableExprColumns64 + RefOfJSONTableExprColumns32 RefOfJSONUnquoteExprJSONValue RefOfJSONValueExprJSONDoc RefOfJSONValueExprPath @@ -284,7 +284,7 @@ const ( RefOfJSONValueMergeExprJSONDocList RefOfJSONValueModifierExprJSONDoc RefOfJSONValueModifierExprParams8 - RefOfJSONValueModifierExprParams64 + RefOfJSONValueModifierExprParams32 RefOfJoinConditionOn RefOfJoinConditionUsing RefOfJoinTableExprLeftExpr @@ -307,7 +307,7 @@ const ( RefOfLockingFuncName RefOfLockingFuncTimeout RefOfMatchExprColumns8 - RefOfMatchExprColumns64 + RefOfMatchExprColumns32 RefOfMatchExprExpr RefOfMaxArg RefOfMaxOverClause @@ -327,20 +327,20 @@ const ( RefOfNTHValueExprNullTreatmentClause RefOfNamedWindowWindows NamedWindowsOffset8 - NamedWindowsOffset64 + NamedWindowsOffset32 RefOfNextvalExpr RefOfNotExprExpr RefOfNtileExprN RefOfNtileExprOverClause RefOfOffsetOriginal OnDupOffset8 - OnDupOffset64 + OnDupOffset32 RefOfOptLikeLikeTable RefOfOrExprLeft RefOfOrExprRight RefOfOrderExpr OrderByOffset8 - OrderByOffset64 + OrderByOffset32 RefOfOrderByOptionCols RefOfOverClauseWindowName RefOfOverClauseWindowSpec @@ -357,15 +357,15 @@ const ( RefOfPartitionOptionExpr RefOfPartitionOptionSubPartition RefOfPartitionOptionDefinitions8 - RefOfPartitionOptionDefinitions64 + RefOfPartitionOptionDefinitions32 RefOfPartitionSpecNames RefOfPartitionSpecNumber RefOfPartitionSpecTableName RefOfPartitionSpecDefinitions8 - RefOfPartitionSpecDefinitions64 + RefOfPartitionSpecDefinitions32 RefOfPartitionValueRangeRange PartitionsOffset8 - PartitionsOffset64 + PartitionsOffset32 RefOfPerformanceSchemaFuncExprArgument RefOfPointExprXCordinate RefOfPointExprYCordinate @@ -416,7 +416,7 @@ const ( RefOfSavepointName RefOfSelectWith RefOfSelectFrom8 - RefOfSelectFrom64 + RefOfSelectFrom32 RefOfSelectComments RefOfSelectSelectExprs RefOfSelectWhere @@ -427,13 +427,13 @@ const ( RefOfSelectLimit RefOfSelectInto SelectExprsOffset8 - SelectExprsOffset64 + SelectExprsOffset32 RefOfSetComments RefOfSetExprs RefOfSetExprVar RefOfSetExprExpr SetExprsOffset8 - SetExprsOffset64 + SetExprsOffset32 RefOfShowInternal RefOfShowBasicTbl RefOfShowBasicDbName @@ -462,7 +462,7 @@ const ( RefOfSubPartitionDefinitionOptionsDataDirectory RefOfSubPartitionDefinitionOptionsIndexDirectory SubPartitionDefinitionsOffset8 - SubPartitionDefinitionsOffset64 + SubPartitionDefinitionsOffset32 RefOfSubquerySelect RefOfSubstrExprName RefOfSubstrExprFrom @@ -470,19 +470,19 @@ const ( RefOfSumArg RefOfSumOverClause TableExprsOffset8 - TableExprsOffset64 + TableExprsOffset32 TableNameName TableNameQualifier TableNamesOffset8 - TableNamesOffset64 + TableNamesOffset32 TableOptionsOffset8 - TableOptionsOffset64 + TableOptionsOffset32 RefOfTableSpecColumns8 - RefOfTableSpecColumns64 + RefOfTableSpecColumns32 RefOfTableSpecIndexes8 - RefOfTableSpecIndexes64 + RefOfTableSpecIndexes32 RefOfTableSpecConstraints8 - RefOfTableSpecConstraints64 + RefOfTableSpecConstraints32 RefOfTableSpecOptions RefOfTableSpecPartitionOption RefOfTimestampDiffExprExpr1 @@ -500,7 +500,7 @@ const ( RefOfUpdateWith RefOfUpdateComments RefOfUpdateTableExprs8 - RefOfUpdateTableExprs64 + RefOfUpdateTableExprs32 RefOfUpdateExprs RefOfUpdateWhere RefOfUpdateOrderBy @@ -508,7 +508,7 @@ const ( RefOfUpdateExprName RefOfUpdateExprExpr UpdateExprsOffset8 - UpdateExprsOffset64 + UpdateExprsOffset32 RefOfUpdateXMLExprTarget RefOfUpdateXMLExprXPathExpr RefOfUpdateXMLExprNewXML @@ -521,9 +521,9 @@ const ( RefOfVStreamWhere RefOfVStreamLimit ValTupleOffset8 - ValTupleOffset64 + ValTupleOffset32 ValuesOffset8 - ValuesOffset64 + ValuesOffset32 RefOfValuesFuncExprName RefOfValuesStatementWith RefOfValuesStatementRows @@ -542,7 +542,7 @@ const ( RefOfVindexSpecName RefOfVindexSpecType RefOfVindexSpecParams8 - RefOfVindexSpecParams64 + RefOfVindexSpecParams32 RefOfWeightStringFuncExprExpr RefOfWeightStringFuncExprAs RefOfWhenCond @@ -551,27 +551,27 @@ const ( RefOfWindowDefinitionName RefOfWindowDefinitionWindowSpec WindowDefinitionsOffset8 - WindowDefinitionsOffset64 + WindowDefinitionsOffset32 RefOfWindowSpecificationName RefOfWindowSpecificationPartitionClause RefOfWindowSpecificationOrderClause RefOfWindowSpecificationFrameClause RefOfWithCTEs8 - RefOfWithCTEs64 + RefOfWithCTEs32 RefOfXorExprLeft RefOfXorExprRight SliceOfRefOfColumnDefinitionOffset8 - SliceOfRefOfColumnDefinitionOffset64 + SliceOfRefOfColumnDefinitionOffset32 SliceOfDatabaseOptionOffset8 - SliceOfDatabaseOptionOffset64 + SliceOfDatabaseOptionOffset32 SliceOfAlterOptionOffset8 - SliceOfAlterOptionOffset64 + SliceOfAlterOptionOffset32 SliceOfIdentifierCIOffset8 - SliceOfIdentifierCIOffset64 + SliceOfIdentifierCIOffset32 SliceOfTxAccessModeOffset8 - SliceOfTxAccessModeOffset64 + SliceOfTxAccessModeOffset32 SliceOfRefOfWhenOffset8 - SliceOfRefOfWhenOffset64 + SliceOfRefOfWhenOffset32 RefOfColumnTypeOptionsDefault RefOfColumnTypeOptionsOnUpdate RefOfColumnTypeOptionsAs @@ -581,21 +581,21 @@ const ( RefOfColumnTypeOptionsSecondaryEngineAttribute RefOfColumnTypeOptionsSRID SliceOfStringOffset8 - SliceOfStringOffset64 + SliceOfStringOffset32 SliceOfTableExprOffset8 - SliceOfTableExprOffset64 + SliceOfTableExprOffset32 SliceOfRefOfVariableOffset8 - SliceOfRefOfVariableOffset64 + SliceOfRefOfVariableOffset32 SliceOfExprOffset8 - SliceOfExprOffset64 + SliceOfExprOffset32 SliceOfRefOfIndexColumnOffset8 - SliceOfRefOfIndexColumnOffset64 + SliceOfRefOfIndexColumnOffset32 SliceOfRefOfIndexOptionOffset8 - SliceOfRefOfIndexOptionOffset64 + SliceOfRefOfIndexOptionOffset32 SliceOfRefOfJSONObjectParamOffset8 - SliceOfRefOfJSONObjectParamOffset64 + SliceOfRefOfJSONObjectParamOffset32 SliceOfRefOfJtColumnDefinitionOffset8 - SliceOfRefOfJtColumnDefinitionOffset64 + SliceOfRefOfJtColumnDefinitionOffset32 RefOfJtOrdinalColDefName RefOfJtPathColDefName RefOfJtPathColDefType @@ -604,31 +604,31 @@ const ( RefOfJtPathColDefErrorOnResponse RefOfJtNestedPathColDefPath RefOfJtNestedPathColDefColumns8 - RefOfJtNestedPathColDefColumns64 + RefOfJtNestedPathColDefColumns32 TableAndLockTypesOffset8 - TableAndLockTypesOffset64 + TableAndLockTypesOffset32 SliceOfRefOfColNameOffset8 - SliceOfRefOfColNameOffset64 + SliceOfRefOfColNameOffset32 CommentsOffset8 - CommentsOffset64 + CommentsOffset32 SliceOfRefOfPartitionDefinitionOffset8 - SliceOfRefOfPartitionDefinitionOffset64 + SliceOfRefOfPartitionDefinitionOffset32 SliceOfRefOfRenameTablePairOffset8 - SliceOfRefOfRenameTablePairOffset64 + SliceOfRefOfRenameTablePairOffset32 RefOfRootNodeSQLNode RefOfTableNameName RefOfTableNameQualifier RefOfTableOptionValue RefOfTableOptionTables SliceOfRefOfIndexDefinitionOffset8 - SliceOfRefOfIndexDefinitionOffset64 + SliceOfRefOfIndexDefinitionOffset32 SliceOfRefOfConstraintDefinitionOffset8 - SliceOfRefOfConstraintDefinitionOffset64 + SliceOfRefOfConstraintDefinitionOffset32 RefOfVindexParamKey SliceOfVindexParamOffset8 - SliceOfVindexParamOffset64 + SliceOfVindexParamOffset32 SliceOfRefOfCommonTableExprOffset8 - SliceOfRefOfCommonTableExprOffset64 + SliceOfRefOfCommonTableExprOffset32 RefOfIndexColumnColumn RefOfIndexColumnExpression RefOfIndexOptionValue @@ -636,3 +636,1239 @@ const ( RefOfRenameTablePairFromTable RefOfRenameTablePairToTable ) + +func (s ASTStep) DebugString() string { + switch s { + case RefOfAddColumnsColumns8: + return "*AddColumns:Columns(*ColumnDefinition)8" + case RefOfAddColumnsColumns32: + return "*AddColumns:Columns(*ColumnDefinition)32" + case RefOfAddColumnsAfter: + return "*AddColumns:After(*ColName)" + case RefOfAddConstraintDefinitionConstraintDefinition: + return "*AddConstraintDefinition:ConstraintDefinition(*ConstraintDefinition)" + case RefOfAddIndexDefinitionIndexDefinition: + return "*AddIndexDefinition:IndexDefinition(*IndexDefinition)" + case RefOfAliasedExprExpr: + return "*AliasedExpr:Expr(Expr)" + case RefOfAliasedExprAs: + return "*AliasedExpr:As(IdentifierCI)" + case RefOfAliasedTableExprExpr: + return "*AliasedTableExpr:Expr(SimpleTableExpr)" + case RefOfAliasedTableExprPartitions: + return "*AliasedTableExpr:Partitions(Partitions)" + case RefOfAliasedTableExprAs: + return "*AliasedTableExpr:As(IdentifierCS)" + case RefOfAliasedTableExprHints: + return "*AliasedTableExpr:Hints(IndexHints)" + case RefOfAliasedTableExprColumns: + return "*AliasedTableExpr:Columns(Columns)" + case RefOfAlterCheckName: + return "*AlterCheck:Name(IdentifierCI)" + case RefOfAlterColumnColumn: + return "*AlterColumn:Column(*ColName)" + case RefOfAlterColumnDefaultVal: + return "*AlterColumn:DefaultVal(Expr)" + case RefOfAlterDatabaseComments: + return "*AlterDatabase:Comments(*ParsedComments)" + case RefOfAlterDatabaseDBName: + return "*AlterDatabase:DBName(IdentifierCS)" + case RefOfAlterIndexName: + return "*AlterIndex:Name(IdentifierCI)" + case RefOfAlterMigrationRatio: + return "*AlterMigration:Ratio(*Literal)" + case RefOfAlterTableTable: + return "*AlterTable:Table(TableName)" + case RefOfAlterTableAlterOptions8: + return "*AlterTable:AlterOptions(AlterOption)8" + case RefOfAlterTableAlterOptions32: + return "*AlterTable:AlterOptions(AlterOption)32" + case RefOfAlterTablePartitionSpec: + return "*AlterTable:PartitionSpec(*PartitionSpec)" + case RefOfAlterTablePartitionOption: + return "*AlterTable:PartitionOption(*PartitionOption)" + case RefOfAlterTableComments: + return "*AlterTable:Comments(*ParsedComments)" + case RefOfAlterViewViewName: + return "*AlterView:ViewName(TableName)" + case RefOfAlterViewDefiner: + return "*AlterView:Definer(*Definer)" + case RefOfAlterViewColumns: + return "*AlterView:Columns(Columns)" + case RefOfAlterViewSelect: + return "*AlterView:Select(TableStatement)" + case RefOfAlterViewComments: + return "*AlterView:Comments(*ParsedComments)" + case RefOfAlterVschemaTable: + return "*AlterVschema:Table(TableName)" + case RefOfAlterVschemaVindexSpec: + return "*AlterVschema:VindexSpec(*VindexSpec)" + case RefOfAlterVschemaVindexCols8: + return "*AlterVschema:VindexCols(IdentifierCI)8" + case RefOfAlterVschemaVindexCols32: + return "*AlterVschema:VindexCols(IdentifierCI)32" + case RefOfAlterVschemaAutoIncSpec: + return "*AlterVschema:AutoIncSpec(*AutoIncSpec)" + case RefOfAnalyzeTable: + return "*Analyze:Table(TableName)" + case RefOfAndExprLeft: + return "*AndExpr:Left(Expr)" + case RefOfAndExprRight: + return "*AndExpr:Right(Expr)" + case RefOfAnyValueArg: + return "*AnyValue:Arg(Expr)" + case RefOfArgumentLessWindowExprOverClause: + return "*ArgumentLessWindowExpr:OverClause(*OverClause)" + case RefOfAssignmentExprLeft: + return "*AssignmentExpr:Left(Expr)" + case RefOfAssignmentExprRight: + return "*AssignmentExpr:Right(Expr)" + case RefOfAutoIncSpecColumn: + return "*AutoIncSpec:Column(IdentifierCI)" + case RefOfAutoIncSpecSequence: + return "*AutoIncSpec:Sequence(TableName)" + case RefOfAvgArg: + return "*Avg:Arg(Expr)" + case RefOfAvgOverClause: + return "*Avg:OverClause(*OverClause)" + case RefOfBetweenExprLeft: + return "*BetweenExpr:Left(Expr)" + case RefOfBetweenExprFrom: + return "*BetweenExpr:From(Expr)" + case RefOfBetweenExprTo: + return "*BetweenExpr:To(Expr)" + case RefOfBinaryExprLeft: + return "*BinaryExpr:Left(Expr)" + case RefOfBinaryExprRight: + return "*BinaryExpr:Right(Expr)" + case RefOfBitAndArg: + return "*BitAnd:Arg(Expr)" + case RefOfBitAndOverClause: + return "*BitAnd:OverClause(*OverClause)" + case RefOfBitOrArg: + return "*BitOr:Arg(Expr)" + case RefOfBitOrOverClause: + return "*BitOr:OverClause(*OverClause)" + case RefOfBitXorArg: + return "*BitXor:Arg(Expr)" + case RefOfBitXorOverClause: + return "*BitXor:OverClause(*OverClause)" + case RefOfCallProcName: + return "*CallProc:Name(TableName)" + case RefOfCallProcParams: + return "*CallProc:Params(Exprs)" + case RefOfCaseExprExpr: + return "*CaseExpr:Expr(Expr)" + case RefOfCaseExprWhens8: + return "*CaseExpr:Whens(*When)8" + case RefOfCaseExprWhens32: + return "*CaseExpr:Whens(*When)32" + case RefOfCaseExprElse: + return "*CaseExpr:Else(Expr)" + case RefOfCastExprExpr: + return "*CastExpr:Expr(Expr)" + case RefOfCastExprType: + return "*CastExpr:Type(*ConvertType)" + case RefOfChangeColumnOldColumn: + return "*ChangeColumn:OldColumn(*ColName)" + case RefOfChangeColumnNewColDefinition: + return "*ChangeColumn:NewColDefinition(*ColumnDefinition)" + case RefOfChangeColumnAfter: + return "*ChangeColumn:After(*ColName)" + case RefOfCharExprExprs: + return "*CharExpr:Exprs(Exprs)" + case RefOfCheckConstraintDefinitionExpr: + return "*CheckConstraintDefinition:Expr(Expr)" + case RefOfColNameName: + return "*ColName:Name(IdentifierCI)" + case RefOfColNameQualifier: + return "*ColName:Qualifier(TableName)" + case RefOfCollateExprExpr: + return "*CollateExpr:Expr(Expr)" + case RefOfColumnDefinitionName: + return "*ColumnDefinition:Name(IdentifierCI)" + case RefOfColumnDefinitionType: + return "*ColumnDefinition:Type(*ColumnType)" + case ColumnsOffset8: + return "Columns:Offset(Columns)8" + case ColumnsOffset32: + return "Columns:Offset(Columns)32" + case RefOfCommonTableExprID: + return "*CommonTableExpr:ID(IdentifierCS)" + case RefOfCommonTableExprColumns: + return "*CommonTableExpr:Columns(Columns)" + case RefOfCommonTableExprSubquery: + return "*CommonTableExpr:Subquery(TableStatement)" + case RefOfComparisonExprLeft: + return "*ComparisonExpr:Left(Expr)" + case RefOfComparisonExprRight: + return "*ComparisonExpr:Right(Expr)" + case RefOfComparisonExprEscape: + return "*ComparisonExpr:Escape(Expr)" + case RefOfConstraintDefinitionName: + return "*ConstraintDefinition:Name(IdentifierCI)" + case RefOfConstraintDefinitionDetails: + return "*ConstraintDefinition:Details(ConstraintInfo)" + case RefOfConvertExprExpr: + return "*ConvertExpr:Expr(Expr)" + case RefOfConvertExprType: + return "*ConvertExpr:Type(*ConvertType)" + case RefOfConvertUsingExprExpr: + return "*ConvertUsingExpr:Expr(Expr)" + case RefOfCountArgs: + return "*Count:Args(Exprs)" + case RefOfCountOverClause: + return "*Count:OverClause(*OverClause)" + case RefOfCountStarOverClause: + return "*CountStar:OverClause(*OverClause)" + case RefOfCreateDatabaseComments: + return "*CreateDatabase:Comments(*ParsedComments)" + case RefOfCreateDatabaseDBName: + return "*CreateDatabase:DBName(IdentifierCS)" + case RefOfCreateTableTable: + return "*CreateTable:Table(TableName)" + case RefOfCreateTableTableSpec: + return "*CreateTable:TableSpec(*TableSpec)" + case RefOfCreateTableOptLike: + return "*CreateTable:OptLike(*OptLike)" + case RefOfCreateTableComments: + return "*CreateTable:Comments(*ParsedComments)" + case RefOfCreateViewViewName: + return "*CreateView:ViewName(TableName)" + case RefOfCreateViewDefiner: + return "*CreateView:Definer(*Definer)" + case RefOfCreateViewColumns: + return "*CreateView:Columns(Columns)" + case RefOfCreateViewSelect: + return "*CreateView:Select(TableStatement)" + case RefOfCreateViewComments: + return "*CreateView:Comments(*ParsedComments)" + case RefOfCurTimeFuncExprName: + return "*CurTimeFuncExpr:Name(IdentifierCI)" + case RefOfDeallocateStmtComments: + return "*DeallocateStmt:Comments(*ParsedComments)" + case RefOfDeallocateStmtName: + return "*DeallocateStmt:Name(IdentifierCI)" + case RefOfDeleteWith: + return "*Delete:With(*With)" + case RefOfDeleteComments: + return "*Delete:Comments(*ParsedComments)" + case RefOfDeleteTableExprs8: + return "*Delete:TableExprs(TableExpr)8" + case RefOfDeleteTableExprs32: + return "*Delete:TableExprs(TableExpr)32" + case RefOfDeleteTargets: + return "*Delete:Targets(TableNames)" + case RefOfDeletePartitions: + return "*Delete:Partitions(Partitions)" + case RefOfDeleteWhere: + return "*Delete:Where(*Where)" + case RefOfDeleteOrderBy: + return "*Delete:OrderBy(OrderBy)" + case RefOfDeleteLimit: + return "*Delete:Limit(*Limit)" + case RefOfDerivedTableSelect: + return "*DerivedTable:Select(TableStatement)" + case RefOfDropColumnName: + return "*DropColumn:Name(*ColName)" + case RefOfDropDatabaseComments: + return "*DropDatabase:Comments(*ParsedComments)" + case RefOfDropDatabaseDBName: + return "*DropDatabase:DBName(IdentifierCS)" + case RefOfDropKeyName: + return "*DropKey:Name(IdentifierCI)" + case RefOfDropTableFromTables: + return "*DropTable:FromTables(TableNames)" + case RefOfDropTableComments: + return "*DropTable:Comments(*ParsedComments)" + case RefOfDropViewFromTables: + return "*DropView:FromTables(TableNames)" + case RefOfDropViewComments: + return "*DropView:Comments(*ParsedComments)" + case RefOfExecuteStmtName: + return "*ExecuteStmt:Name(IdentifierCI)" + case RefOfExecuteStmtComments: + return "*ExecuteStmt:Comments(*ParsedComments)" + case RefOfExecuteStmtArguments8: + return "*ExecuteStmt:Arguments(*Variable)8" + case RefOfExecuteStmtArguments32: + return "*ExecuteStmt:Arguments(*Variable)32" + case RefOfExistsExprSubquery: + return "*ExistsExpr:Subquery(*Subquery)" + case RefOfExplainStmtStatement: + return "*ExplainStmt:Statement(Statement)" + case RefOfExplainStmtComments: + return "*ExplainStmt:Comments(*ParsedComments)" + case RefOfExplainTabTable: + return "*ExplainTab:Table(TableName)" + case ExprsOffset8: + return "Exprs:Offset(Exprs)8" + case ExprsOffset32: + return "Exprs:Offset(Exprs)32" + case RefOfExtractFuncExprExpr: + return "*ExtractFuncExpr:Expr(Expr)" + case RefOfExtractValueExprFragment: + return "*ExtractValueExpr:Fragment(Expr)" + case RefOfExtractValueExprXPathExpr: + return "*ExtractValueExpr:XPathExpr(Expr)" + case RefOfFirstOrLastValueExprExpr: + return "*FirstOrLastValueExpr:Expr(Expr)" + case RefOfFirstOrLastValueExprNullTreatmentClause: + return "*FirstOrLastValueExpr:NullTreatmentClause(*NullTreatmentClause)" + case RefOfFirstOrLastValueExprOverClause: + return "*FirstOrLastValueExpr:OverClause(*OverClause)" + case RefOfFlushTableNames: + return "*Flush:TableNames(TableNames)" + case RefOfForeignKeyDefinitionSource: + return "*ForeignKeyDefinition:Source(Columns)" + case RefOfForeignKeyDefinitionIndexName: + return "*ForeignKeyDefinition:IndexName(IdentifierCI)" + case RefOfForeignKeyDefinitionReferenceDefinition: + return "*ForeignKeyDefinition:ReferenceDefinition(*ReferenceDefinition)" + case RefOfFrameClauseStart: + return "*FrameClause:Start(*FramePoint)" + case RefOfFrameClauseEnd: + return "*FrameClause:End(*FramePoint)" + case RefOfFramePointExpr: + return "*FramePoint:Expr(Expr)" + case RefOfFuncExprQualifier: + return "*FuncExpr:Qualifier(IdentifierCS)" + case RefOfFuncExprName: + return "*FuncExpr:Name(IdentifierCI)" + case RefOfFuncExprExprs: + return "*FuncExpr:Exprs(Exprs)" + case RefOfGTIDFuncExprSet1: + return "*GTIDFuncExpr:Set1(Expr)" + case RefOfGTIDFuncExprSet2: + return "*GTIDFuncExpr:Set2(Expr)" + case RefOfGTIDFuncExprTimeout: + return "*GTIDFuncExpr:Timeout(Expr)" + case RefOfGTIDFuncExprChannel: + return "*GTIDFuncExpr:Channel(Expr)" + case RefOfGeoHashFromLatLongExprLatitude: + return "*GeoHashFromLatLongExpr:Latitude(Expr)" + case RefOfGeoHashFromLatLongExprLongitude: + return "*GeoHashFromLatLongExpr:Longitude(Expr)" + case RefOfGeoHashFromLatLongExprMaxLength: + return "*GeoHashFromLatLongExpr:MaxLength(Expr)" + case RefOfGeoHashFromPointExprPoint: + return "*GeoHashFromPointExpr:Point(Expr)" + case RefOfGeoHashFromPointExprMaxLength: + return "*GeoHashFromPointExpr:MaxLength(Expr)" + case RefOfGeoJSONFromGeomExprGeom: + return "*GeoJSONFromGeomExpr:Geom(Expr)" + case RefOfGeoJSONFromGeomExprMaxDecimalDigits: + return "*GeoJSONFromGeomExpr:MaxDecimalDigits(Expr)" + case RefOfGeoJSONFromGeomExprBitmask: + return "*GeoJSONFromGeomExpr:Bitmask(Expr)" + case RefOfGeomCollPropertyFuncExprGeomColl: + return "*GeomCollPropertyFuncExpr:GeomColl(Expr)" + case RefOfGeomCollPropertyFuncExprPropertyDefArg: + return "*GeomCollPropertyFuncExpr:PropertyDefArg(Expr)" + case RefOfGeomFormatExprGeom: + return "*GeomFormatExpr:Geom(Expr)" + case RefOfGeomFormatExprAxisOrderOpt: + return "*GeomFormatExpr:AxisOrderOpt(Expr)" + case RefOfGeomFromGeoHashExprGeoHash: + return "*GeomFromGeoHashExpr:GeoHash(Expr)" + case RefOfGeomFromGeoHashExprSridOpt: + return "*GeomFromGeoHashExpr:SridOpt(Expr)" + case RefOfGeomFromGeoJSONExprGeoJSON: + return "*GeomFromGeoJSONExpr:GeoJSON(Expr)" + case RefOfGeomFromGeoJSONExprHigherDimHandlerOpt: + return "*GeomFromGeoJSONExpr:HigherDimHandlerOpt(Expr)" + case RefOfGeomFromGeoJSONExprSrid: + return "*GeomFromGeoJSONExpr:Srid(Expr)" + case RefOfGeomFromTextExprWktText: + return "*GeomFromTextExpr:WktText(Expr)" + case RefOfGeomFromTextExprSrid: + return "*GeomFromTextExpr:Srid(Expr)" + case RefOfGeomFromTextExprAxisOrderOpt: + return "*GeomFromTextExpr:AxisOrderOpt(Expr)" + case RefOfGeomFromWKBExprWkbBlob: + return "*GeomFromWKBExpr:WkbBlob(Expr)" + case RefOfGeomFromWKBExprSrid: + return "*GeomFromWKBExpr:Srid(Expr)" + case RefOfGeomFromWKBExprAxisOrderOpt: + return "*GeomFromWKBExpr:AxisOrderOpt(Expr)" + case RefOfGeomPropertyFuncExprGeom: + return "*GeomPropertyFuncExpr:Geom(Expr)" + case RefOfGroupByExprs8: + return "*GroupBy:Exprs(Expr)8" + case RefOfGroupByExprs32: + return "*GroupBy:Exprs(Expr)32" + case RefOfGroupConcatExprExprs: + return "*GroupConcatExpr:Exprs(Exprs)" + case RefOfGroupConcatExprOrderBy: + return "*GroupConcatExpr:OrderBy(OrderBy)" + case RefOfGroupConcatExprLimit: + return "*GroupConcatExpr:Limit(*Limit)" + case RefOfIndexDefinitionInfo: + return "*IndexDefinition:Info(*IndexInfo)" + case RefOfIndexHintIndexes8: + return "*IndexHint:Indexes(IdentifierCI)8" + case RefOfIndexHintIndexes32: + return "*IndexHint:Indexes(IdentifierCI)32" + case IndexHintsOffset8: + return "IndexHints:Offset(IndexHints)8" + case IndexHintsOffset32: + return "IndexHints:Offset(IndexHints)32" + case RefOfIndexInfoName: + return "*IndexInfo:Name(IdentifierCI)" + case RefOfIndexInfoConstraintName: + return "*IndexInfo:ConstraintName(IdentifierCI)" + case RefOfInsertComments: + return "*Insert:Comments(*ParsedComments)" + case RefOfInsertTable: + return "*Insert:Table(*AliasedTableExpr)" + case RefOfInsertPartitions: + return "*Insert:Partitions(Partitions)" + case RefOfInsertColumns: + return "*Insert:Columns(Columns)" + case RefOfInsertRows: + return "*Insert:Rows(InsertRows)" + case RefOfInsertRowAlias: + return "*Insert:RowAlias(*RowAlias)" + case RefOfInsertOnDup: + return "*Insert:OnDup(OnDup)" + case RefOfInsertExprStr: + return "*InsertExpr:Str(Expr)" + case RefOfInsertExprPos: + return "*InsertExpr:Pos(Expr)" + case RefOfInsertExprLen: + return "*InsertExpr:Len(Expr)" + case RefOfInsertExprNewStr: + return "*InsertExpr:NewStr(Expr)" + case RefOfIntervalDateExprDate: + return "*IntervalDateExpr:Date(Expr)" + case RefOfIntervalDateExprInterval: + return "*IntervalDateExpr:Interval(Expr)" + case RefOfIntervalFuncExprExpr: + return "*IntervalFuncExpr:Expr(Expr)" + case RefOfIntervalFuncExprExprs: + return "*IntervalFuncExpr:Exprs(Exprs)" + case RefOfIntroducerExprExpr: + return "*IntroducerExpr:Expr(Expr)" + case RefOfIsExprLeft: + return "*IsExpr:Left(Expr)" + case RefOfJSONArrayAggExpr: + return "*JSONArrayAgg:Expr(Expr)" + case RefOfJSONArrayAggOverClause: + return "*JSONArrayAgg:OverClause(*OverClause)" + case RefOfJSONArrayExprParams: + return "*JSONArrayExpr:Params(Exprs)" + case RefOfJSONAttributesExprJSONDoc: + return "*JSONAttributesExpr:JSONDoc(Expr)" + case RefOfJSONAttributesExprPath: + return "*JSONAttributesExpr:Path(Expr)" + case RefOfJSONContainsExprTarget: + return "*JSONContainsExpr:Target(Expr)" + case RefOfJSONContainsExprCandidate: + return "*JSONContainsExpr:Candidate(Expr)" + case RefOfJSONContainsExprPathList8: + return "*JSONContainsExpr:PathList(Expr)8" + case RefOfJSONContainsExprPathList32: + return "*JSONContainsExpr:PathList(Expr)32" + case RefOfJSONContainsPathExprJSONDoc: + return "*JSONContainsPathExpr:JSONDoc(Expr)" + case RefOfJSONContainsPathExprOneOrAll: + return "*JSONContainsPathExpr:OneOrAll(Expr)" + case RefOfJSONContainsPathExprPathList8: + return "*JSONContainsPathExpr:PathList(Expr)8" + case RefOfJSONContainsPathExprPathList32: + return "*JSONContainsPathExpr:PathList(Expr)32" + case RefOfJSONExtractExprJSONDoc: + return "*JSONExtractExpr:JSONDoc(Expr)" + case RefOfJSONExtractExprPathList8: + return "*JSONExtractExpr:PathList(Expr)8" + case RefOfJSONExtractExprPathList32: + return "*JSONExtractExpr:PathList(Expr)32" + case RefOfJSONKeysExprJSONDoc: + return "*JSONKeysExpr:JSONDoc(Expr)" + case RefOfJSONKeysExprPath: + return "*JSONKeysExpr:Path(Expr)" + case RefOfJSONObjectAggKey: + return "*JSONObjectAgg:Key(Expr)" + case RefOfJSONObjectAggValue: + return "*JSONObjectAgg:Value(Expr)" + case RefOfJSONObjectAggOverClause: + return "*JSONObjectAgg:OverClause(*OverClause)" + case RefOfJSONObjectExprParams8: + return "*JSONObjectExpr:Params(*JSONObjectParam)8" + case RefOfJSONObjectExprParams32: + return "*JSONObjectExpr:Params(*JSONObjectParam)32" + case RefOfJSONObjectParamKey: + return "*JSONObjectParam:Key(Expr)" + case RefOfJSONObjectParamValue: + return "*JSONObjectParam:Value(Expr)" + case RefOfJSONOverlapsExprJSONDoc1: + return "*JSONOverlapsExpr:JSONDoc1(Expr)" + case RefOfJSONOverlapsExprJSONDoc2: + return "*JSONOverlapsExpr:JSONDoc2(Expr)" + case RefOfJSONPrettyExprJSONVal: + return "*JSONPrettyExpr:JSONVal(Expr)" + case RefOfJSONQuoteExprStringArg: + return "*JSONQuoteExpr:StringArg(Expr)" + case RefOfJSONRemoveExprJSONDoc: + return "*JSONRemoveExpr:JSONDoc(Expr)" + case RefOfJSONRemoveExprPathList: + return "*JSONRemoveExpr:PathList(Exprs)" + case RefOfJSONSchemaValidFuncExprSchema: + return "*JSONSchemaValidFuncExpr:Schema(Expr)" + case RefOfJSONSchemaValidFuncExprDocument: + return "*JSONSchemaValidFuncExpr:Document(Expr)" + case RefOfJSONSchemaValidationReportFuncExprSchema: + return "*JSONSchemaValidationReportFuncExpr:Schema(Expr)" + case RefOfJSONSchemaValidationReportFuncExprDocument: + return "*JSONSchemaValidationReportFuncExpr:Document(Expr)" + case RefOfJSONSearchExprJSONDoc: + return "*JSONSearchExpr:JSONDoc(Expr)" + case RefOfJSONSearchExprOneOrAll: + return "*JSONSearchExpr:OneOrAll(Expr)" + case RefOfJSONSearchExprSearchStr: + return "*JSONSearchExpr:SearchStr(Expr)" + case RefOfJSONSearchExprEscapeChar: + return "*JSONSearchExpr:EscapeChar(Expr)" + case RefOfJSONSearchExprPathList8: + return "*JSONSearchExpr:PathList(Expr)8" + case RefOfJSONSearchExprPathList32: + return "*JSONSearchExpr:PathList(Expr)32" + case RefOfJSONStorageFreeExprJSONVal: + return "*JSONStorageFreeExpr:JSONVal(Expr)" + case RefOfJSONStorageSizeExprJSONVal: + return "*JSONStorageSizeExpr:JSONVal(Expr)" + case RefOfJSONTableExprExpr: + return "*JSONTableExpr:Expr(Expr)" + case RefOfJSONTableExprAlias: + return "*JSONTableExpr:Alias(IdentifierCS)" + case RefOfJSONTableExprFilter: + return "*JSONTableExpr:Filter(Expr)" + case RefOfJSONTableExprColumns8: + return "*JSONTableExpr:Columns(*JtColumnDefinition)8" + case RefOfJSONTableExprColumns32: + return "*JSONTableExpr:Columns(*JtColumnDefinition)32" + case RefOfJSONUnquoteExprJSONValue: + return "*JSONUnquoteExpr:JSONValue(Expr)" + case RefOfJSONValueExprJSONDoc: + return "*JSONValueExpr:JSONDoc(Expr)" + case RefOfJSONValueExprPath: + return "*JSONValueExpr:Path(Expr)" + case RefOfJSONValueExprReturningType: + return "*JSONValueExpr:ReturningType(*ConvertType)" + case RefOfJSONValueExprEmptyOnResponse: + return "*JSONValueExpr:EmptyOnResponse(*JtOnResponse)" + case RefOfJSONValueExprErrorOnResponse: + return "*JSONValueExpr:ErrorOnResponse(*JtOnResponse)" + case RefOfJSONValueMergeExprJSONDoc: + return "*JSONValueMergeExpr:JSONDoc(Expr)" + case RefOfJSONValueMergeExprJSONDocList: + return "*JSONValueMergeExpr:JSONDocList(Exprs)" + case RefOfJSONValueModifierExprJSONDoc: + return "*JSONValueModifierExpr:JSONDoc(Expr)" + case RefOfJSONValueModifierExprParams8: + return "*JSONValueModifierExpr:Params(*JSONObjectParam)8" + case RefOfJSONValueModifierExprParams32: + return "*JSONValueModifierExpr:Params(*JSONObjectParam)32" + case RefOfJoinConditionOn: + return "*JoinCondition:On(Expr)" + case RefOfJoinConditionUsing: + return "*JoinCondition:Using(Columns)" + case RefOfJoinTableExprLeftExpr: + return "*JoinTableExpr:LeftExpr(TableExpr)" + case RefOfJoinTableExprRightExpr: + return "*JoinTableExpr:RightExpr(TableExpr)" + case RefOfJoinTableExprCondition: + return "*JoinTableExpr:Condition(*JoinCondition)" + case RefOfJtOnResponseExpr: + return "*JtOnResponse:Expr(Expr)" + case RefOfLagLeadExprExpr: + return "*LagLeadExpr:Expr(Expr)" + case RefOfLagLeadExprN: + return "*LagLeadExpr:N(Expr)" + case RefOfLagLeadExprDefault: + return "*LagLeadExpr:Default(Expr)" + case RefOfLagLeadExprOverClause: + return "*LagLeadExpr:OverClause(*OverClause)" + case RefOfLagLeadExprNullTreatmentClause: + return "*LagLeadExpr:NullTreatmentClause(*NullTreatmentClause)" + case RefOfLimitOffset: + return "*Limit:Offset(Expr)" + case RefOfLimitRowcount: + return "*Limit:Rowcount(Expr)" + case RefOfLineStringExprPointParams: + return "*LineStringExpr:PointParams(Exprs)" + case RefOfLinestrPropertyFuncExprLinestring: + return "*LinestrPropertyFuncExpr:Linestring(Expr)" + case RefOfLinestrPropertyFuncExprPropertyDefArg: + return "*LinestrPropertyFuncExpr:PropertyDefArg(Expr)" + case RefOfLocateExprSubStr: + return "*LocateExpr:SubStr(Expr)" + case RefOfLocateExprStr: + return "*LocateExpr:Str(Expr)" + case RefOfLocateExprPos: + return "*LocateExpr:Pos(Expr)" + case RefOfLockingFuncName: + return "*LockingFunc:Name(Expr)" + case RefOfLockingFuncTimeout: + return "*LockingFunc:Timeout(Expr)" + case RefOfMatchExprColumns8: + return "*MatchExpr:Columns(*ColName)8" + case RefOfMatchExprColumns32: + return "*MatchExpr:Columns(*ColName)32" + case RefOfMatchExprExpr: + return "*MatchExpr:Expr(Expr)" + case RefOfMaxArg: + return "*Max:Arg(Expr)" + case RefOfMaxOverClause: + return "*Max:OverClause(*OverClause)" + case RefOfMemberOfExprValue: + return "*MemberOfExpr:Value(Expr)" + case RefOfMemberOfExprJSONArr: + return "*MemberOfExpr:JSONArr(Expr)" + case RefOfMinArg: + return "*Min:Arg(Expr)" + case RefOfMinOverClause: + return "*Min:OverClause(*OverClause)" + case RefOfModifyColumnNewColDefinition: + return "*ModifyColumn:NewColDefinition(*ColumnDefinition)" + case RefOfModifyColumnAfter: + return "*ModifyColumn:After(*ColName)" + case RefOfMultiLinestringExprLinestringParams: + return "*MultiLinestringExpr:LinestringParams(Exprs)" + case RefOfMultiPointExprPointParams: + return "*MultiPointExpr:PointParams(Exprs)" + case RefOfMultiPolygonExprPolygonParams: + return "*MultiPolygonExpr:PolygonParams(Exprs)" + case RefOfNTHValueExprExpr: + return "*NTHValueExpr:Expr(Expr)" + case RefOfNTHValueExprN: + return "*NTHValueExpr:N(Expr)" + case RefOfNTHValueExprOverClause: + return "*NTHValueExpr:OverClause(*OverClause)" + case RefOfNTHValueExprFromFirstLastClause: + return "*NTHValueExpr:FromFirstLastClause(*FromFirstLastClause)" + case RefOfNTHValueExprNullTreatmentClause: + return "*NTHValueExpr:NullTreatmentClause(*NullTreatmentClause)" + case RefOfNamedWindowWindows: + return "*NamedWindow:Windows(WindowDefinitions)" + case NamedWindowsOffset8: + return "NamedWindows:Offset(NamedWindows)8" + case NamedWindowsOffset32: + return "NamedWindows:Offset(NamedWindows)32" + case RefOfNextvalExpr: + return "*Nextval:Expr(Expr)" + case RefOfNotExprExpr: + return "*NotExpr:Expr(Expr)" + case RefOfNtileExprN: + return "*NtileExpr:N(Expr)" + case RefOfNtileExprOverClause: + return "*NtileExpr:OverClause(*OverClause)" + case RefOfOffsetOriginal: + return "*Offset:Original(Expr)" + case OnDupOffset8: + return "OnDup:Offset(OnDup)8" + case OnDupOffset32: + return "OnDup:Offset(OnDup)32" + case RefOfOptLikeLikeTable: + return "*OptLike:LikeTable(TableName)" + case RefOfOrExprLeft: + return "*OrExpr:Left(Expr)" + case RefOfOrExprRight: + return "*OrExpr:Right(Expr)" + case RefOfOrderExpr: + return "*Order:Expr(Expr)" + case OrderByOffset8: + return "OrderBy:Offset(OrderBy)8" + case OrderByOffset32: + return "OrderBy:Offset(OrderBy)32" + case RefOfOrderByOptionCols: + return "*OrderByOption:Cols(Columns)" + case RefOfOverClauseWindowName: + return "*OverClause:WindowName(IdentifierCI)" + case RefOfOverClauseWindowSpec: + return "*OverClause:WindowSpec(*WindowSpecification)" + case RefOfParenTableExprExprs: + return "*ParenTableExpr:Exprs(TableExprs)" + case RefOfPartitionDefinitionName: + return "*PartitionDefinition:Name(IdentifierCI)" + case RefOfPartitionDefinitionOptions: + return "*PartitionDefinition:Options(*PartitionDefinitionOptions)" + case RefOfPartitionDefinitionOptionsValueRange: + return "*PartitionDefinitionOptions:ValueRange(*PartitionValueRange)" + case RefOfPartitionDefinitionOptionsComment: + return "*PartitionDefinitionOptions:Comment(*Literal)" + case RefOfPartitionDefinitionOptionsEngine: + return "*PartitionDefinitionOptions:Engine(*PartitionEngine)" + case RefOfPartitionDefinitionOptionsDataDirectory: + return "*PartitionDefinitionOptions:DataDirectory(*Literal)" + case RefOfPartitionDefinitionOptionsIndexDirectory: + return "*PartitionDefinitionOptions:IndexDirectory(*Literal)" + case RefOfPartitionDefinitionOptionsSubPartitionDefinitions: + return "*PartitionDefinitionOptions:SubPartitionDefinitions(SubPartitionDefinitions)" + case RefOfPartitionOptionColList: + return "*PartitionOption:ColList(Columns)" + case RefOfPartitionOptionExpr: + return "*PartitionOption:Expr(Expr)" + case RefOfPartitionOptionSubPartition: + return "*PartitionOption:SubPartition(*SubPartition)" + case RefOfPartitionOptionDefinitions8: + return "*PartitionOption:Definitions(*PartitionDefinition)8" + case RefOfPartitionOptionDefinitions32: + return "*PartitionOption:Definitions(*PartitionDefinition)32" + case RefOfPartitionSpecNames: + return "*PartitionSpec:Names(Partitions)" + case RefOfPartitionSpecNumber: + return "*PartitionSpec:Number(*Literal)" + case RefOfPartitionSpecTableName: + return "*PartitionSpec:TableName(TableName)" + case RefOfPartitionSpecDefinitions8: + return "*PartitionSpec:Definitions(*PartitionDefinition)8" + case RefOfPartitionSpecDefinitions32: + return "*PartitionSpec:Definitions(*PartitionDefinition)32" + case RefOfPartitionValueRangeRange: + return "*PartitionValueRange:Range(ValTuple)" + case PartitionsOffset8: + return "Partitions:Offset(Partitions)8" + case PartitionsOffset32: + return "Partitions:Offset(Partitions)32" + case RefOfPerformanceSchemaFuncExprArgument: + return "*PerformanceSchemaFuncExpr:Argument(Expr)" + case RefOfPointExprXCordinate: + return "*PointExpr:XCordinate(Expr)" + case RefOfPointExprYCordinate: + return "*PointExpr:YCordinate(Expr)" + case RefOfPointPropertyFuncExprPoint: + return "*PointPropertyFuncExpr:Point(Expr)" + case RefOfPointPropertyFuncExprValueToSet: + return "*PointPropertyFuncExpr:ValueToSet(Expr)" + case RefOfPolygonExprLinestringParams: + return "*PolygonExpr:LinestringParams(Exprs)" + case RefOfPolygonPropertyFuncExprPolygon: + return "*PolygonPropertyFuncExpr:Polygon(Expr)" + case RefOfPolygonPropertyFuncExprPropertyDefArg: + return "*PolygonPropertyFuncExpr:PropertyDefArg(Expr)" + case RefOfPrepareStmtName: + return "*PrepareStmt:Name(IdentifierCI)" + case RefOfPrepareStmtStatement: + return "*PrepareStmt:Statement(Expr)" + case RefOfPrepareStmtComments: + return "*PrepareStmt:Comments(*ParsedComments)" + case RefOfReferenceDefinitionReferencedTable: + return "*ReferenceDefinition:ReferencedTable(TableName)" + case RefOfReferenceDefinitionReferencedColumns: + return "*ReferenceDefinition:ReferencedColumns(Columns)" + case RefOfReferenceDefinitionMatch: + return "*ReferenceDefinition:Match(MatchAction)" + case RefOfReferenceDefinitionOnDelete: + return "*ReferenceDefinition:OnDelete(ReferenceAction)" + case RefOfReferenceDefinitionOnUpdate: + return "*ReferenceDefinition:OnUpdate(ReferenceAction)" + case RefOfRegexpInstrExprExpr: + return "*RegexpInstrExpr:Expr(Expr)" + case RefOfRegexpInstrExprPattern: + return "*RegexpInstrExpr:Pattern(Expr)" + case RefOfRegexpInstrExprPosition: + return "*RegexpInstrExpr:Position(Expr)" + case RefOfRegexpInstrExprOccurrence: + return "*RegexpInstrExpr:Occurrence(Expr)" + case RefOfRegexpInstrExprReturnOption: + return "*RegexpInstrExpr:ReturnOption(Expr)" + case RefOfRegexpInstrExprMatchType: + return "*RegexpInstrExpr:MatchType(Expr)" + case RefOfRegexpLikeExprExpr: + return "*RegexpLikeExpr:Expr(Expr)" + case RefOfRegexpLikeExprPattern: + return "*RegexpLikeExpr:Pattern(Expr)" + case RefOfRegexpLikeExprMatchType: + return "*RegexpLikeExpr:MatchType(Expr)" + case RefOfRegexpReplaceExprExpr: + return "*RegexpReplaceExpr:Expr(Expr)" + case RefOfRegexpReplaceExprPattern: + return "*RegexpReplaceExpr:Pattern(Expr)" + case RefOfRegexpReplaceExprRepl: + return "*RegexpReplaceExpr:Repl(Expr)" + case RefOfRegexpReplaceExprOccurrence: + return "*RegexpReplaceExpr:Occurrence(Expr)" + case RefOfRegexpReplaceExprPosition: + return "*RegexpReplaceExpr:Position(Expr)" + case RefOfRegexpReplaceExprMatchType: + return "*RegexpReplaceExpr:MatchType(Expr)" + case RefOfRegexpSubstrExprExpr: + return "*RegexpSubstrExpr:Expr(Expr)" + case RefOfRegexpSubstrExprPattern: + return "*RegexpSubstrExpr:Pattern(Expr)" + case RefOfRegexpSubstrExprOccurrence: + return "*RegexpSubstrExpr:Occurrence(Expr)" + case RefOfRegexpSubstrExprPosition: + return "*RegexpSubstrExpr:Position(Expr)" + case RefOfRegexpSubstrExprMatchType: + return "*RegexpSubstrExpr:MatchType(Expr)" + case RefOfReleaseName: + return "*Release:Name(IdentifierCI)" + case RefOfRenameColumnOldName: + return "*RenameColumn:OldName(*ColName)" + case RefOfRenameColumnNewName: + return "*RenameColumn:NewName(*ColName)" + case RefOfRenameIndexOldName: + return "*RenameIndex:OldName(IdentifierCI)" + case RefOfRenameIndexNewName: + return "*RenameIndex:NewName(IdentifierCI)" + case RefOfRenameTableNameTable: + return "*RenameTableName:Table(TableName)" + case RefOfRevertMigrationComments: + return "*RevertMigration:Comments(*ParsedComments)" + case RootNodeSQLNode: + return "RootNode:SQLNode(SQLNode)" + case RefOfRowAliasTableName: + return "*RowAlias:TableName(IdentifierCS)" + case RefOfRowAliasColumns: + return "*RowAlias:Columns(Columns)" + case RefOfSRollbackName: + return "*SRollback:Name(IdentifierCI)" + case RefOfSavepointName: + return "*Savepoint:Name(IdentifierCI)" + case RefOfSelectWith: + return "*Select:With(*With)" + case RefOfSelectFrom8: + return "*Select:From(TableExpr)8" + case RefOfSelectFrom32: + return "*Select:From(TableExpr)32" + case RefOfSelectComments: + return "*Select:Comments(*ParsedComments)" + case RefOfSelectSelectExprs: + return "*Select:SelectExprs(SelectExprs)" + case RefOfSelectWhere: + return "*Select:Where(*Where)" + case RefOfSelectGroupBy: + return "*Select:GroupBy(*GroupBy)" + case RefOfSelectHaving: + return "*Select:Having(*Where)" + case RefOfSelectWindows: + return "*Select:Windows(NamedWindows)" + case RefOfSelectOrderBy: + return "*Select:OrderBy(OrderBy)" + case RefOfSelectLimit: + return "*Select:Limit(*Limit)" + case RefOfSelectInto: + return "*Select:Into(*SelectInto)" + case SelectExprsOffset8: + return "SelectExprs:Offset(SelectExprs)8" + case SelectExprsOffset32: + return "SelectExprs:Offset(SelectExprs)32" + case RefOfSetComments: + return "*Set:Comments(*ParsedComments)" + case RefOfSetExprs: + return "*Set:Exprs(SetExprs)" + case RefOfSetExprVar: + return "*SetExpr:Var(*Variable)" + case RefOfSetExprExpr: + return "*SetExpr:Expr(Expr)" + case SetExprsOffset8: + return "SetExprs:Offset(SetExprs)8" + case SetExprsOffset32: + return "SetExprs:Offset(SetExprs)32" + case RefOfShowInternal: + return "*Show:Internal(ShowInternal)" + case RefOfShowBasicTbl: + return "*ShowBasic:Tbl(TableName)" + case RefOfShowBasicDbName: + return "*ShowBasic:DbName(IdentifierCS)" + case RefOfShowBasicFilter: + return "*ShowBasic:Filter(*ShowFilter)" + case RefOfShowCreateOp: + return "*ShowCreate:Op(TableName)" + case RefOfShowFilterFilter: + return "*ShowFilter:Filter(Expr)" + case RefOfShowMigrationLogsComments: + return "*ShowMigrationLogs:Comments(*ParsedComments)" + case RefOfStarExprTableName: + return "*StarExpr:TableName(TableName)" + case RefOfStdArg: + return "*Std:Arg(Expr)" + case RefOfStdOverClause: + return "*Std:OverClause(*OverClause)" + case RefOfStdDevArg: + return "*StdDev:Arg(Expr)" + case RefOfStdDevOverClause: + return "*StdDev:OverClause(*OverClause)" + case RefOfStdPopArg: + return "*StdPop:Arg(Expr)" + case RefOfStdPopOverClause: + return "*StdPop:OverClause(*OverClause)" + case RefOfStdSampArg: + return "*StdSamp:Arg(Expr)" + case RefOfStdSampOverClause: + return "*StdSamp:OverClause(*OverClause)" + case RefOfStreamComments: + return "*Stream:Comments(*ParsedComments)" + case RefOfStreamSelectExpr: + return "*Stream:SelectExpr(SelectExpr)" + case RefOfStreamTable: + return "*Stream:Table(TableName)" + case RefOfSubPartitionColList: + return "*SubPartition:ColList(Columns)" + case RefOfSubPartitionExpr: + return "*SubPartition:Expr(Expr)" + case RefOfSubPartitionDefinitionName: + return "*SubPartitionDefinition:Name(IdentifierCI)" + case RefOfSubPartitionDefinitionOptions: + return "*SubPartitionDefinition:Options(*SubPartitionDefinitionOptions)" + case RefOfSubPartitionDefinitionOptionsComment: + return "*SubPartitionDefinitionOptions:Comment(*Literal)" + case RefOfSubPartitionDefinitionOptionsEngine: + return "*SubPartitionDefinitionOptions:Engine(*PartitionEngine)" + case RefOfSubPartitionDefinitionOptionsDataDirectory: + return "*SubPartitionDefinitionOptions:DataDirectory(*Literal)" + case RefOfSubPartitionDefinitionOptionsIndexDirectory: + return "*SubPartitionDefinitionOptions:IndexDirectory(*Literal)" + case SubPartitionDefinitionsOffset8: + return "SubPartitionDefinitions:Offset(SubPartitionDefinitions)8" + case SubPartitionDefinitionsOffset32: + return "SubPartitionDefinitions:Offset(SubPartitionDefinitions)32" + case RefOfSubquerySelect: + return "*Subquery:Select(TableStatement)" + case RefOfSubstrExprName: + return "*SubstrExpr:Name(Expr)" + case RefOfSubstrExprFrom: + return "*SubstrExpr:From(Expr)" + case RefOfSubstrExprTo: + return "*SubstrExpr:To(Expr)" + case RefOfSumArg: + return "*Sum:Arg(Expr)" + case RefOfSumOverClause: + return "*Sum:OverClause(*OverClause)" + case TableExprsOffset8: + return "TableExprs:Offset(TableExprs)8" + case TableExprsOffset32: + return "TableExprs:Offset(TableExprs)32" + case TableNameName: + return "TableName:Name(IdentifierCS)" + case TableNameQualifier: + return "TableName:Qualifier(IdentifierCS)" + case TableNamesOffset8: + return "TableNames:Offset(TableNames)8" + case TableNamesOffset32: + return "TableNames:Offset(TableNames)32" + case TableOptionsOffset8: + return "TableOptions:Offset(TableOptions)8" + case TableOptionsOffset32: + return "TableOptions:Offset(TableOptions)32" + case RefOfTableSpecColumns8: + return "*TableSpec:Columns(*ColumnDefinition)8" + case RefOfTableSpecColumns32: + return "*TableSpec:Columns(*ColumnDefinition)32" + case RefOfTableSpecIndexes8: + return "*TableSpec:Indexes(*IndexDefinition)8" + case RefOfTableSpecIndexes32: + return "*TableSpec:Indexes(*IndexDefinition)32" + case RefOfTableSpecConstraints8: + return "*TableSpec:Constraints(*ConstraintDefinition)8" + case RefOfTableSpecConstraints32: + return "*TableSpec:Constraints(*ConstraintDefinition)32" + case RefOfTableSpecOptions: + return "*TableSpec:Options(TableOptions)" + case RefOfTableSpecPartitionOption: + return "*TableSpec:PartitionOption(*PartitionOption)" + case RefOfTimestampDiffExprExpr1: + return "*TimestampDiffExpr:Expr1(Expr)" + case RefOfTimestampDiffExprExpr2: + return "*TimestampDiffExpr:Expr2(Expr)" + case RefOfTrimFuncExprTrimArg: + return "*TrimFuncExpr:TrimArg(Expr)" + case RefOfTrimFuncExprStringArg: + return "*TrimFuncExpr:StringArg(Expr)" + case RefOfTruncateTableTable: + return "*TruncateTable:Table(TableName)" + case RefOfUnaryExprExpr: + return "*UnaryExpr:Expr(Expr)" + case RefOfUnionWith: + return "*Union:With(*With)" + case RefOfUnionLeft: + return "*Union:Left(TableStatement)" + case RefOfUnionRight: + return "*Union:Right(TableStatement)" + case RefOfUnionOrderBy: + return "*Union:OrderBy(OrderBy)" + case RefOfUnionLimit: + return "*Union:Limit(*Limit)" + case RefOfUnionInto: + return "*Union:Into(*SelectInto)" + case RefOfUpdateWith: + return "*Update:With(*With)" + case RefOfUpdateComments: + return "*Update:Comments(*ParsedComments)" + case RefOfUpdateTableExprs8: + return "*Update:TableExprs(TableExpr)8" + case RefOfUpdateTableExprs32: + return "*Update:TableExprs(TableExpr)32" + case RefOfUpdateExprs: + return "*Update:Exprs(UpdateExprs)" + case RefOfUpdateWhere: + return "*Update:Where(*Where)" + case RefOfUpdateOrderBy: + return "*Update:OrderBy(OrderBy)" + case RefOfUpdateLimit: + return "*Update:Limit(*Limit)" + case RefOfUpdateExprName: + return "*UpdateExpr:Name(*ColName)" + case RefOfUpdateExprExpr: + return "*UpdateExpr:Expr(Expr)" + case UpdateExprsOffset8: + return "UpdateExprs:Offset(UpdateExprs)8" + case UpdateExprsOffset32: + return "UpdateExprs:Offset(UpdateExprs)32" + case RefOfUpdateXMLExprTarget: + return "*UpdateXMLExpr:Target(Expr)" + case RefOfUpdateXMLExprXPathExpr: + return "*UpdateXMLExpr:XPathExpr(Expr)" + case RefOfUpdateXMLExprNewXML: + return "*UpdateXMLExpr:NewXML(Expr)" + case RefOfUseDBName: + return "*Use:DBName(IdentifierCS)" + case RefOfVExplainStmtStatement: + return "*VExplainStmt:Statement(Statement)" + case RefOfVExplainStmtComments: + return "*VExplainStmt:Comments(*ParsedComments)" + case RefOfVStreamComments: + return "*VStream:Comments(*ParsedComments)" + case RefOfVStreamSelectExpr: + return "*VStream:SelectExpr(SelectExpr)" + case RefOfVStreamTable: + return "*VStream:Table(TableName)" + case RefOfVStreamWhere: + return "*VStream:Where(*Where)" + case RefOfVStreamLimit: + return "*VStream:Limit(*Limit)" + case ValTupleOffset8: + return "ValTuple:Offset(ValTuple)8" + case ValTupleOffset32: + return "ValTuple:Offset(ValTuple)32" + case ValuesOffset8: + return "Values:Offset(Values)8" + case ValuesOffset32: + return "Values:Offset(Values)32" + case RefOfValuesFuncExprName: + return "*ValuesFuncExpr:Name(*ColName)" + case RefOfValuesStatementWith: + return "*ValuesStatement:With(*With)" + case RefOfValuesStatementRows: + return "*ValuesStatement:Rows(Values)" + case RefOfValuesStatementListArg: + return "*ValuesStatement:ListArg(ListArg)" + case RefOfValuesStatementComments: + return "*ValuesStatement:Comments(*ParsedComments)" + case RefOfValuesStatementOrder: + return "*ValuesStatement:Order(OrderBy)" + case RefOfValuesStatementLimit: + return "*ValuesStatement:Limit(*Limit)" + case RefOfVarPopArg: + return "*VarPop:Arg(Expr)" + case RefOfVarPopOverClause: + return "*VarPop:OverClause(*OverClause)" + case RefOfVarSampArg: + return "*VarSamp:Arg(Expr)" + case RefOfVarSampOverClause: + return "*VarSamp:OverClause(*OverClause)" + case RefOfVariableName: + return "*Variable:Name(IdentifierCI)" + case RefOfVarianceArg: + return "*Variance:Arg(Expr)" + case RefOfVarianceOverClause: + return "*Variance:OverClause(*OverClause)" + case VindexParamKey: + return "VindexParam:Key(IdentifierCI)" + case RefOfVindexSpecName: + return "*VindexSpec:Name(IdentifierCI)" + case RefOfVindexSpecType: + return "*VindexSpec:Type(IdentifierCI)" + case RefOfVindexSpecParams8: + return "*VindexSpec:Params(VindexParam)8" + case RefOfVindexSpecParams32: + return "*VindexSpec:Params(VindexParam)32" + case RefOfWeightStringFuncExprExpr: + return "*WeightStringFuncExpr:Expr(Expr)" + case RefOfWeightStringFuncExprAs: + return "*WeightStringFuncExpr:As(*ConvertType)" + case RefOfWhenCond: + return "*When:Cond(Expr)" + case RefOfWhenVal: + return "*When:Val(Expr)" + case RefOfWhereExpr: + return "*Where:Expr(Expr)" + case RefOfWindowDefinitionName: + return "*WindowDefinition:Name(IdentifierCI)" + case RefOfWindowDefinitionWindowSpec: + return "*WindowDefinition:WindowSpec(*WindowSpecification)" + case WindowDefinitionsOffset8: + return "WindowDefinitions:Offset(WindowDefinitions)8" + case WindowDefinitionsOffset32: + return "WindowDefinitions:Offset(WindowDefinitions)32" + case RefOfWindowSpecificationName: + return "*WindowSpecification:Name(IdentifierCI)" + case RefOfWindowSpecificationPartitionClause: + return "*WindowSpecification:PartitionClause(Exprs)" + case RefOfWindowSpecificationOrderClause: + return "*WindowSpecification:OrderClause(OrderBy)" + case RefOfWindowSpecificationFrameClause: + return "*WindowSpecification:FrameClause(*FrameClause)" + case RefOfWithCTEs8: + return "*With:CTEs(*CommonTableExpr)8" + case RefOfWithCTEs32: + return "*With:CTEs(*CommonTableExpr)32" + case RefOfXorExprLeft: + return "*XorExpr:Left(Expr)" + case RefOfXorExprRight: + return "*XorExpr:Right(Expr)" + case SliceOfRefOfColumnDefinitionOffset8: + return "[]*ColumnDefinition:Offset([]*ColumnDefinition)8" + case SliceOfRefOfColumnDefinitionOffset32: + return "[]*ColumnDefinition:Offset([]*ColumnDefinition)32" + case SliceOfDatabaseOptionOffset8: + return "[]DatabaseOption:Offset([]DatabaseOption)8" + case SliceOfDatabaseOptionOffset32: + return "[]DatabaseOption:Offset([]DatabaseOption)32" + case SliceOfAlterOptionOffset8: + return "[]AlterOption:Offset([]AlterOption)8" + case SliceOfAlterOptionOffset32: + return "[]AlterOption:Offset([]AlterOption)32" + case SliceOfIdentifierCIOffset8: + return "[]IdentifierCI:Offset([]IdentifierCI)8" + case SliceOfIdentifierCIOffset32: + return "[]IdentifierCI:Offset([]IdentifierCI)32" + case SliceOfTxAccessModeOffset8: + return "[]TxAccessMode:Offset([]TxAccessMode)8" + case SliceOfTxAccessModeOffset32: + return "[]TxAccessMode:Offset([]TxAccessMode)32" + case SliceOfRefOfWhenOffset8: + return "[]*When:Offset([]*When)8" + case SliceOfRefOfWhenOffset32: + return "[]*When:Offset([]*When)32" + case RefOfColumnTypeOptionsDefault: + return "*ColumnTypeOptions:Default(Expr)" + case RefOfColumnTypeOptionsOnUpdate: + return "*ColumnTypeOptions:OnUpdate(Expr)" + case RefOfColumnTypeOptionsAs: + return "*ColumnTypeOptions:As(Expr)" + case RefOfColumnTypeOptionsComment: + return "*ColumnTypeOptions:Comment(*Literal)" + case RefOfColumnTypeOptionsReference: + return "*ColumnTypeOptions:Reference(*ReferenceDefinition)" + case RefOfColumnTypeOptionsEngineAttribute: + return "*ColumnTypeOptions:EngineAttribute(*Literal)" + case RefOfColumnTypeOptionsSecondaryEngineAttribute: + return "*ColumnTypeOptions:SecondaryEngineAttribute(*Literal)" + case RefOfColumnTypeOptionsSRID: + return "*ColumnTypeOptions:SRID(*Literal)" + case SliceOfStringOffset8: + return "[]string:Offset([]string)8" + case SliceOfStringOffset32: + return "[]string:Offset([]string)32" + case SliceOfTableExprOffset8: + return "[]TableExpr:Offset([]TableExpr)8" + case SliceOfTableExprOffset32: + return "[]TableExpr:Offset([]TableExpr)32" + case SliceOfRefOfVariableOffset8: + return "[]*Variable:Offset([]*Variable)8" + case SliceOfRefOfVariableOffset32: + return "[]*Variable:Offset([]*Variable)32" + case SliceOfExprOffset8: + return "[]Expr:Offset([]Expr)8" + case SliceOfExprOffset32: + return "[]Expr:Offset([]Expr)32" + case SliceOfRefOfIndexColumnOffset8: + return "[]*IndexColumn:Offset([]*IndexColumn)8" + case SliceOfRefOfIndexColumnOffset32: + return "[]*IndexColumn:Offset([]*IndexColumn)32" + case SliceOfRefOfIndexOptionOffset8: + return "[]*IndexOption:Offset([]*IndexOption)8" + case SliceOfRefOfIndexOptionOffset32: + return "[]*IndexOption:Offset([]*IndexOption)32" + case SliceOfRefOfJSONObjectParamOffset8: + return "[]*JSONObjectParam:Offset([]*JSONObjectParam)8" + case SliceOfRefOfJSONObjectParamOffset32: + return "[]*JSONObjectParam:Offset([]*JSONObjectParam)32" + case SliceOfRefOfJtColumnDefinitionOffset8: + return "[]*JtColumnDefinition:Offset([]*JtColumnDefinition)8" + case SliceOfRefOfJtColumnDefinitionOffset32: + return "[]*JtColumnDefinition:Offset([]*JtColumnDefinition)32" + case RefOfJtOrdinalColDefName: + return "*JtOrdinalColDef:Name(IdentifierCI)" + case RefOfJtPathColDefName: + return "*JtPathColDef:Name(IdentifierCI)" + case RefOfJtPathColDefType: + return "*JtPathColDef:Type(*ColumnType)" + case RefOfJtPathColDefPath: + return "*JtPathColDef:Path(Expr)" + case RefOfJtPathColDefEmptyOnResponse: + return "*JtPathColDef:EmptyOnResponse(*JtOnResponse)" + case RefOfJtPathColDefErrorOnResponse: + return "*JtPathColDef:ErrorOnResponse(*JtOnResponse)" + case RefOfJtNestedPathColDefPath: + return "*JtNestedPathColDef:Path(Expr)" + case RefOfJtNestedPathColDefColumns8: + return "*JtNestedPathColDef:Columns(*JtColumnDefinition)8" + case RefOfJtNestedPathColDefColumns32: + return "*JtNestedPathColDef:Columns(*JtColumnDefinition)32" + case TableAndLockTypesOffset8: + return "TableAndLockTypes:Offset(TableAndLockTypes)8" + case TableAndLockTypesOffset32: + return "TableAndLockTypes:Offset(TableAndLockTypes)32" + case SliceOfRefOfColNameOffset8: + return "[]*ColName:Offset([]*ColName)8" + case SliceOfRefOfColNameOffset32: + return "[]*ColName:Offset([]*ColName)32" + case CommentsOffset8: + return "Comments:Offset(Comments)8" + case CommentsOffset32: + return "Comments:Offset(Comments)32" + case SliceOfRefOfPartitionDefinitionOffset8: + return "[]*PartitionDefinition:Offset([]*PartitionDefinition)8" + case SliceOfRefOfPartitionDefinitionOffset32: + return "[]*PartitionDefinition:Offset([]*PartitionDefinition)32" + case SliceOfRefOfRenameTablePairOffset8: + return "[]*RenameTablePair:Offset([]*RenameTablePair)8" + case SliceOfRefOfRenameTablePairOffset32: + return "[]*RenameTablePair:Offset([]*RenameTablePair)32" + case RefOfRootNodeSQLNode: + return "*RootNode:SQLNode(SQLNode)" + case RefOfTableNameName: + return "*TableName:Name(IdentifierCS)" + case RefOfTableNameQualifier: + return "*TableName:Qualifier(IdentifierCS)" + case RefOfTableOptionValue: + return "*TableOption:Value(*Literal)" + case RefOfTableOptionTables: + return "*TableOption:Tables(TableNames)" + case SliceOfRefOfIndexDefinitionOffset8: + return "[]*IndexDefinition:Offset([]*IndexDefinition)8" + case SliceOfRefOfIndexDefinitionOffset32: + return "[]*IndexDefinition:Offset([]*IndexDefinition)32" + case SliceOfRefOfConstraintDefinitionOffset8: + return "[]*ConstraintDefinition:Offset([]*ConstraintDefinition)8" + case SliceOfRefOfConstraintDefinitionOffset32: + return "[]*ConstraintDefinition:Offset([]*ConstraintDefinition)32" + case RefOfVindexParamKey: + return "*VindexParam:Key(IdentifierCI)" + case SliceOfVindexParamOffset8: + return "[]VindexParam:Offset([]VindexParam)8" + case SliceOfVindexParamOffset32: + return "[]VindexParam:Offset([]VindexParam)32" + case SliceOfRefOfCommonTableExprOffset8: + return "[]*CommonTableExpr:Offset([]*CommonTableExpr)8" + case SliceOfRefOfCommonTableExprOffset32: + return "[]*CommonTableExpr:Offset([]*CommonTableExpr)32" + case RefOfIndexColumnColumn: + return "*IndexColumn:Column(IdentifierCI)" + case RefOfIndexColumnExpression: + return "*IndexColumn:Expression(Expr)" + case RefOfIndexOptionValue: + return "*IndexOption:Value(*Literal)" + case RefOfTableAndLockTypeTable: + return "*TableAndLockType:Table(TableExpr)" + case RefOfRenameTablePairFromTable: + return "*RenameTablePair:FromTable(TableName)" + case RefOfRenameTablePairToTable: + return "*RenameTablePair:ToTable(TableName)" + } + panic("unknown ASTStep") +} diff --git a/go/vt/sqlparser/paths.go b/go/vt/sqlparser/paths.go new file mode 100644 index 00000000000..1a6e4af4493 --- /dev/null +++ b/go/vt/sqlparser/paths.go @@ -0,0 +1,51 @@ +/* +Copyright 2025 The Vitess Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package sqlparser + +import "encoding/binary" + +// ASTPath is stored as a string. +// Each 2 bytes => one step (big-endian). +// Some steps (e.g., referencing a slice) consume *additional* bytes for an index +type ASTPath string + +// AddStep appends a single step (2 bytes) to path. +func AddStep(path ASTPath, step ASTStep) ASTPath { + b := make([]byte, 2) + binary.BigEndian.PutUint16(b, uint16(step)) + return path + ASTPath(b) +} + +func AddStepWithSliceIndex(path ASTPath, step ASTStep, idx int) ASTPath { + if idx < 255 { + // 2 bytes for step code + 1 byte for index + b := make([]byte, 3) + binary.BigEndian.PutUint16(b[:2], uint16(step)) + b[2] = byte(idx) + return path + ASTPath(b) + } + + // 2 bytes for step code + 4 byte for index + b := make([]byte, 6) + longStep := step + 1 + binary.BigEndian.PutUint16(b[:2], uint16(longStep)) + binary.BigEndian.PutUint32(b[2:], uint32(idx)) + return path + ASTPath(b) +} + +// func (p ASTPath) DebugString() string { +// } From 1291440f06eff9a2df2b0b66ef58524865f5497b Mon Sep 17 00:00:00 2001 From: Andres Taylor Date: Wed, 29 Jan 2025 10:54:22 +0100 Subject: [PATCH 04/13] update test code Signed-off-by: Andres Taylor --- go/tools/asthelpergen/ast_path_gen.go | 24 ++-- go/tools/asthelpergen/asthelpergen_test.go | 19 +++ .../asthelpergen/integration/ast_clone.go | 4 +- .../integration/ast_copy_on_rewrite.go | 26 +--- .../asthelpergen/integration/ast_equals.go | 6 +- go/tools/asthelpergen/integration/ast_path.go | 116 +++++++++++++++++ .../asthelpergen/integration/ast_rewrite.go | 24 ++-- .../asthelpergen/integration/ast_visit.go | 14 +- go/tools/asthelpergen/integration/types.go | 123 ++++++++---------- 9 files changed, 225 insertions(+), 131 deletions(-) create mode 100644 go/tools/asthelpergen/integration/ast_path.go diff --git a/go/tools/asthelpergen/ast_path_gen.go b/go/tools/asthelpergen/ast_path_gen.go index 6345ab3c188..d0465cad2fa 100644 --- a/go/tools/asthelpergen/ast_path_gen.go +++ b/go/tools/asthelpergen/ast_path_gen.go @@ -49,7 +49,16 @@ func newPathGen(pkgname string) *pathGen { } func (p *pathGen) genFile() (string, *jen.File) { - p.close() + p.file.ImportName("fmt", "fmt") + + // Declare the ASTStep type with underlying type uint16 + p.file.Add(jen.Type().Id("ASTStep").Uint16()) + + // Add the const block + p.file.Add(p.buildConstWithEnum()) + + // Add the ASTStep#DebugString() method to the file + p.file.Add(p.debugString()) return "ast_path.go", p.file } @@ -109,19 +118,6 @@ func (p *pathGen) basicMethod(t types.Type, basic *types.Basic, spi generatorSPI return nil } -func (p *pathGen) close() { - p.file.ImportName("fmt", "fmt") - - // Declare the ASTStep type with underlying type uint16 - p.file.Add(jen.Type().Id("ASTStep").Uint16()) - - // Add the const block - p.file.Add(p.buildConstWithEnum()) - - // Add the DebugString() method to the file - p.file.Add(p.debugString()) -} - func (p *pathGen) debugString() *jen.Statement { var switchCases []jen.Code diff --git a/go/tools/asthelpergen/asthelpergen_test.go b/go/tools/asthelpergen/asthelpergen_test.go index 19ac865575d..f1f52b5b9c0 100644 --- a/go/tools/asthelpergen/asthelpergen_test.go +++ b/go/tools/asthelpergen/asthelpergen_test.go @@ -21,6 +21,8 @@ import ( "strings" "testing" + "vitess.io/vitess/go/tools/codegen" + "github.com/stretchr/testify/require" ) @@ -45,3 +47,20 @@ func TestFullGeneration(t *testing.T) { require.False(t, applyIdx == 0 && cloneIdx == 0, "file doesn't contain expected contents") } } + +func TestRecreateAllFiles(t *testing.T) { + t.Skip("This test recreates all files in the integration directory. It should only be run when the ASTHelperGen code has changed.") + result, err := GenerateASTHelpers(&Options{ + Packages: []string{"./integration/..."}, + RootInterface: "vitess.io/vitess/go/tools/asthelpergen/integration.AST", + Clone: CloneOptions{ + Exclude: []string{"*NoCloneType"}, + }, + }) + require.NoError(t, err) + + for fullPath, file := range result { + err := codegen.SaveJenFile(fullPath, file) + require.NoError(t, err) + } +} diff --git a/go/tools/asthelpergen/integration/ast_clone.go b/go/tools/asthelpergen/integration/ast_clone.go index d5857c89834..db16c1bf4bb 100644 --- a/go/tools/asthelpergen/integration/ast_clone.go +++ b/go/tools/asthelpergen/integration/ast_clone.go @@ -1,5 +1,5 @@ /* -Copyright 2023 The Vitess Authors. +Copyright 2025 The Vitess Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -238,6 +238,6 @@ func CloneRefOfValueSliceContainer(n *ValueSliceContainer) *ValueSliceContainer out := *n out.ASTElements = CloneSliceOfAST(n.ASTElements) out.NotASTElements = CloneSliceOfInt(n.NotASTElements) - out.ASTImplementationElements = CloneSliceOfRefOfLeaf(n.ASTImplementationElements) + out.ASTImplementationElements = CloneLeafSlice(n.ASTImplementationElements) return &out } diff --git a/go/tools/asthelpergen/integration/ast_copy_on_rewrite.go b/go/tools/asthelpergen/integration/ast_copy_on_rewrite.go index d48e8621692..84c13fac6a7 100644 --- a/go/tools/asthelpergen/integration/ast_copy_on_rewrite.go +++ b/go/tools/asthelpergen/integration/ast_copy_on_rewrite.go @@ -1,5 +1,5 @@ /* -Copyright 2023 The Vitess Authors. +Copyright 2025 The Vitess Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -262,19 +262,11 @@ func (c *cow) copyOnRewriteValueSliceContainer(n ValueSliceContainer, parent AST changedASTElements = true } } - var changedASTImplementationElements bool - _ASTImplementationElements := make([]*Leaf, len(n.ASTImplementationElements)) - for x, el := range n.ASTImplementationElements { - this, changed := c.copyOnRewriteRefOfLeaf(el, n) - _ASTImplementationElements[x] = this.(*Leaf) - if changed { - changedASTImplementationElements = true - } - } + _ASTImplementationElements, changedASTImplementationElements := c.copyOnRewriteLeafSlice(n.ASTImplementationElements, n) if changedASTElements || changedASTImplementationElements { res := n res.ASTElements = _ASTElements - res.ASTImplementationElements = _ASTImplementationElements + res.ASTImplementationElements, _ = _ASTImplementationElements.(LeafSlice) out = &res if c.cloned != nil { c.cloned(n, out) @@ -364,19 +356,11 @@ func (c *cow) copyOnRewriteRefOfValueSliceContainer(n *ValueSliceContainer, pare changedASTElements = true } } - var changedASTImplementationElements bool - _ASTImplementationElements := make([]*Leaf, len(n.ASTImplementationElements)) - for x, el := range n.ASTImplementationElements { - this, changed := c.copyOnRewriteRefOfLeaf(el, n) - _ASTImplementationElements[x] = this.(*Leaf) - if changed { - changedASTImplementationElements = true - } - } + _ASTImplementationElements, changedASTImplementationElements := c.copyOnRewriteLeafSlice(n.ASTImplementationElements, n) if changedASTElements || changedASTImplementationElements { res := *n res.ASTElements = _ASTElements - res.ASTImplementationElements = _ASTImplementationElements + res.ASTImplementationElements, _ = _ASTImplementationElements.(LeafSlice) out = &res if c.cloned != nil { c.cloned(n, out) diff --git a/go/tools/asthelpergen/integration/ast_equals.go b/go/tools/asthelpergen/integration/ast_equals.go index 553851a8c97..5e7b068671c 100644 --- a/go/tools/asthelpergen/integration/ast_equals.go +++ b/go/tools/asthelpergen/integration/ast_equals.go @@ -1,5 +1,5 @@ /* -Copyright 2023 The Vitess Authors. +Copyright 2025 The Vitess Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -219,7 +219,7 @@ func (cmp *Comparator) ValueContainer(a, b ValueContainer) bool { func (cmp *Comparator) ValueSliceContainer(a, b ValueSliceContainer) bool { return cmp.SliceOfAST(a.ASTElements, b.ASTElements) && cmp.SliceOfInt(a.NotASTElements, b.NotASTElements) && - cmp.SliceOfRefOfLeaf(a.ASTImplementationElements, b.ASTImplementationElements) + cmp.LeafSlice(a.ASTImplementationElements, b.ASTImplementationElements) } // SubIface does deep equals between the two objects. @@ -327,7 +327,7 @@ func (cmp *Comparator) RefOfValueSliceContainer(a, b *ValueSliceContainer) bool } return cmp.SliceOfAST(a.ASTElements, b.ASTElements) && cmp.SliceOfInt(a.NotASTElements, b.NotASTElements) && - cmp.SliceOfRefOfLeaf(a.ASTImplementationElements, b.ASTImplementationElements) + cmp.LeafSlice(a.ASTImplementationElements, b.ASTImplementationElements) } type Comparator struct{} diff --git a/go/tools/asthelpergen/integration/ast_path.go b/go/tools/asthelpergen/integration/ast_path.go new file mode 100644 index 00000000000..d778538c90e --- /dev/null +++ b/go/tools/asthelpergen/integration/ast_path.go @@ -0,0 +1,116 @@ +/* +Copyright 2025 The Vitess Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +// Code generated by ASTHelperGen. DO NOT EDIT. + +package integration + +type ASTStep uint16 + +const ( + BytesOffset8 ASTStep = iota + BytesOffset32 + InterfaceSliceOffset8 + InterfaceSliceOffset32 + LeafSliceOffset8 + LeafSliceOffset32 + RefOfRefContainerASTType + RefOfRefContainerASTImplementationType + RefOfRefSliceContainerASTElements8 + RefOfRefSliceContainerASTElements32 + RefOfRefSliceContainerASTImplementationElements8 + RefOfRefSliceContainerASTImplementationElements32 + RefOfSubImplinner + ValueContainerASTType + ValueContainerASTImplementationType + ValueSliceContainerASTElements8 + ValueSliceContainerASTElements32 + ValueSliceContainerASTImplementationElements + SliceOfASTOffset8 + SliceOfASTOffset32 + SliceOfIntOffset8 + SliceOfIntOffset32 + SliceOfRefOfLeafOffset8 + SliceOfRefOfLeafOffset32 + RefOfValueContainerASTType + RefOfValueContainerASTImplementationType + RefOfValueSliceContainerASTElements8 + RefOfValueSliceContainerASTElements32 + RefOfValueSliceContainerASTImplementationElements +) + +func (s ASTStep) DebugString() string { + switch s { + case BytesOffset8: + return "Bytes:Offset(Bytes)8" + case BytesOffset32: + return "Bytes:Offset(Bytes)32" + case InterfaceSliceOffset8: + return "InterfaceSlice:Offset(InterfaceSlice)8" + case InterfaceSliceOffset32: + return "InterfaceSlice:Offset(InterfaceSlice)32" + case LeafSliceOffset8: + return "LeafSlice:Offset(LeafSlice)8" + case LeafSliceOffset32: + return "LeafSlice:Offset(LeafSlice)32" + case RefOfRefContainerASTType: + return "*RefContainer:ASTType(AST)" + case RefOfRefContainerASTImplementationType: + return "*RefContainer:ASTImplementationType(*Leaf)" + case RefOfRefSliceContainerASTElements8: + return "*RefSliceContainer:ASTElements(AST)8" + case RefOfRefSliceContainerASTElements32: + return "*RefSliceContainer:ASTElements(AST)32" + case RefOfRefSliceContainerASTImplementationElements8: + return "*RefSliceContainer:ASTImplementationElements(*Leaf)8" + case RefOfRefSliceContainerASTImplementationElements32: + return "*RefSliceContainer:ASTImplementationElements(*Leaf)32" + case RefOfSubImplinner: + return "*SubImpl:inner(SubIface)" + case ValueContainerASTType: + return "ValueContainer:ASTType(AST)" + case ValueContainerASTImplementationType: + return "ValueContainer:ASTImplementationType(*Leaf)" + case ValueSliceContainerASTElements8: + return "ValueSliceContainer:ASTElements(AST)8" + case ValueSliceContainerASTElements32: + return "ValueSliceContainer:ASTElements(AST)32" + case ValueSliceContainerASTImplementationElements: + return "ValueSliceContainer:ASTImplementationElements(LeafSlice)" + case SliceOfASTOffset8: + return "[]AST:Offset([]AST)8" + case SliceOfASTOffset32: + return "[]AST:Offset([]AST)32" + case SliceOfIntOffset8: + return "[]int:Offset([]int)8" + case SliceOfIntOffset32: + return "[]int:Offset([]int)32" + case SliceOfRefOfLeafOffset8: + return "[]*Leaf:Offset([]*Leaf)8" + case SliceOfRefOfLeafOffset32: + return "[]*Leaf:Offset([]*Leaf)32" + case RefOfValueContainerASTType: + return "*ValueContainer:ASTType(AST)" + case RefOfValueContainerASTImplementationType: + return "*ValueContainer:ASTImplementationType(*Leaf)" + case RefOfValueSliceContainerASTElements8: + return "*ValueSliceContainer:ASTElements(AST)8" + case RefOfValueSliceContainerASTElements32: + return "*ValueSliceContainer:ASTElements(AST)32" + case RefOfValueSliceContainerASTImplementationElements: + return "*ValueSliceContainer:ASTImplementationElements(LeafSlice)" + } + panic("unknown ASTStep") +} diff --git a/go/tools/asthelpergen/integration/ast_rewrite.go b/go/tools/asthelpergen/integration/ast_rewrite.go index cf92b358862..11f6e5bfb33 100644 --- a/go/tools/asthelpergen/integration/ast_rewrite.go +++ b/go/tools/asthelpergen/integration/ast_rewrite.go @@ -1,5 +1,5 @@ /* -Copyright 2023 The Vitess Authors. +Copyright 2025 The Vitess Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -368,12 +368,10 @@ func (a *application) rewriteValueSliceContainer(parent AST, node ValueSliceCont return false } } - for _, el := range node.ASTImplementationElements { - if !a.rewriteRefOfLeaf(node, el, func(newNode, parent AST) { - panic("[BUG] tried to replace 'ASTImplementationElements' on 'ValueSliceContainer'") - }) { - return false - } + if !a.rewriteLeafSlice(node, node.ASTImplementationElements, func(newNode, parent AST) { + panic("[BUG] tried to replace 'ASTImplementationElements' on 'ValueSliceContainer'") + }) { + return false } if a.post != nil { a.cur.replacer = replacer @@ -495,14 +493,10 @@ func (a *application) rewriteRefOfValueSliceContainer(parent AST, node *ValueSli return false } } - for x, el := range node.ASTImplementationElements { - if !a.rewriteRefOfLeaf(node, el, func(idx int) replacerFunc { - return func(newNode, parent AST) { - parent.(*ValueSliceContainer).ASTImplementationElements[idx] = newNode.(*Leaf) - } - }(x)) { - return false - } + if !a.rewriteLeafSlice(node, node.ASTImplementationElements, func(newNode, parent AST) { + parent.(*ValueSliceContainer).ASTImplementationElements = newNode.(LeafSlice) + }) { + return false } if a.post != nil { a.cur.replacer = replacer diff --git a/go/tools/asthelpergen/integration/ast_visit.go b/go/tools/asthelpergen/integration/ast_visit.go index 6ceec4e2fc5..252541677eb 100644 --- a/go/tools/asthelpergen/integration/ast_visit.go +++ b/go/tools/asthelpergen/integration/ast_visit.go @@ -1,5 +1,5 @@ /* -Copyright 2023 The Vitess Authors. +Copyright 2025 The Vitess Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -174,10 +174,8 @@ func VisitValueSliceContainer(in ValueSliceContainer, f Visit) error { return err } } - for _, el := range in.ASTImplementationElements { - if err := VisitRefOfLeaf(el, f); err != nil { - return err - } + if err := VisitLeafSlice(in.ASTImplementationElements, f); err != nil { + return err } return nil } @@ -233,10 +231,8 @@ func VisitRefOfValueSliceContainer(in *ValueSliceContainer, f Visit) error { return err } } - for _, el := range in.ASTImplementationElements { - if err := VisitRefOfLeaf(el, f); err != nil { - return err - } + if err := VisitLeafSlice(in.ASTImplementationElements, f); err != nil { + return err } return nil } diff --git a/go/tools/asthelpergen/integration/types.go b/go/tools/asthelpergen/integration/types.go index 921759f3ad1..3e8fef6f81d 100644 --- a/go/tools/asthelpergen/integration/types.go +++ b/go/tools/asthelpergen/integration/types.go @@ -24,15 +24,62 @@ import ( //go:generate go run ../main --in . --iface vitess.io/vitess/go/tools/asthelpergen/integration.AST --clone_exclude "*NoCloneType" -// AST is the interface all interface types implement -type AST interface { - String() string -} - -// Empty struct impl of the iface -type Leaf struct { - v int -} +type ( + // AST is the interface all interface types implement + AST interface { + String() string + } + // Empty struct impl of the iface + Leaf struct { + v int + } + // Container implements the interface ByRef + RefContainer struct { + ASTType AST + NotASTType int + ASTImplementationType *Leaf + } + // Container implements the interface ByRef + RefSliceContainer struct { + ASTElements []AST + NotASTElements []int + ASTImplementationElements []*Leaf + } + // Container implements the interface ByValue + ValueContainer struct { + ASTType AST + NotASTType int + ASTImplementationType *Leaf + } + // Container implements the interface ByValue + ValueSliceContainer struct { + ASTElements []AST + NotASTElements []int + ASTImplementationElements LeafSlice + } + // We need to support these types - a slice of AST elements can implement the interface + InterfaceSlice []AST + // We need to support these types - a slice of AST elements can implement the interface + Bytes []byte + LeafSlice []*Leaf + BasicType int + NoCloneType struct { + v int + } + // We want to support all types that are used as field types, which can include interfaces. + // Example would be sqlparser.Expr that implements sqlparser.SQLNode + SubIface interface { + AST + iface() + } + SubImpl struct { + inner SubIface + field *bool + } + InterfaceContainer struct { + v any + } +) func (l *Leaf) String() string { if l == nil { @@ -41,13 +88,6 @@ func (l *Leaf) String() string { return fmt.Sprintf("Leaf(%d)", l.v) } -// Container implements the interface ByRef -type RefContainer struct { - ASTType AST - NotASTType int - ASTImplementationType *Leaf -} - func (r *RefContainer) String() string { if r == nil { return "nil" @@ -61,42 +101,18 @@ func (r *RefContainer) String() string { return fmt.Sprintf("RefContainer{%s, %d, %s}", astType, r.NotASTType, r.ASTImplementationType.String()) } -// Container implements the interface ByRef -type RefSliceContainer struct { - ASTElements []AST - NotASTElements []int - ASTImplementationElements []*Leaf -} - func (r *RefSliceContainer) String() string { return fmt.Sprintf("RefSliceContainer{%s, %s, %s}", sliceStringAST(r.ASTElements...), "r.NotASTType", sliceStringLeaf(r.ASTImplementationElements...)) } -// Container implements the interface ByValue -type ValueContainer struct { - ASTType AST - NotASTType int - ASTImplementationType *Leaf -} - func (r ValueContainer) String() string { return fmt.Sprintf("ValueContainer{%s, %d, %s}", r.ASTType.String(), r.NotASTType, r.ASTImplementationType.String()) } -// Container implements the interface ByValue -type ValueSliceContainer struct { - ASTElements []AST - NotASTElements []int - ASTImplementationElements []*Leaf -} - func (r ValueSliceContainer) String() string { return fmt.Sprintf("ValueSliceContainer{%s, %s, %s}", sliceStringAST(r.ASTElements...), "r.NotASTType", sliceStringLeaf(r.ASTImplementationElements...)) } -// We need to support these types - a slice of AST elements can implement the interface -type InterfaceSlice []AST - func (r InterfaceSlice) String() string { var elements []string for _, el := range r { @@ -106,15 +122,10 @@ func (r InterfaceSlice) String() string { return "[" + strings.Join(elements, ", ") + "]" } -// We need to support these types - a slice of AST elements can implement the interface -type Bytes []byte - func (r Bytes) String() string { return string(r) } -type LeafSlice []*Leaf - func (r LeafSlice) String() string { var elements []string for _, el := range r { @@ -123,8 +134,6 @@ func (r LeafSlice) String() string { return strings.Join(elements, ", ") } -type BasicType int - func (r BasicType) String() string { return fmt.Sprintf("int(%d)", r) } @@ -135,35 +144,15 @@ const ( thisIsNotAType2 BasicType = 2 ) -// We want to support all types that are used as field types, which can include interfaces. -// Example would be sqlparser.Expr that implements sqlparser.SQLNode -type SubIface interface { - AST - iface() -} - -type SubImpl struct { - inner SubIface - field *bool -} - func (r *SubImpl) String() string { return "SubImpl" } func (r *SubImpl) iface() {} -type InterfaceContainer struct { - v any -} - func (r InterfaceContainer) String() string { return fmt.Sprintf("%v", r.v) } -type NoCloneType struct { - v int -} - func (r *NoCloneType) String() string { return fmt.Sprintf("NoClone(%d)", r.v) } From 29415bf99ffb2b0530d35b50670632317da50c58 Mon Sep 17 00:00:00 2001 From: Andres Taylor Date: Wed, 29 Jan 2025 13:05:21 +0100 Subject: [PATCH 05/13] change DebugString() for ASTPath and ASTStep Signed-off-by: Andres Taylor --- go/tools/asthelpergen/ast_path_gen.go | 2 +- go/tools/asthelpergen/integration/ast_path.go | 58 +- go/vt/sqlparser/ast_path.go | 1230 ++++++++--------- go/vt/sqlparser/paths.go | 62 +- go/vt/sqlparser/paths_test.go | 34 + 5 files changed, 738 insertions(+), 648 deletions(-) create mode 100644 go/vt/sqlparser/paths_test.go diff --git a/go/tools/asthelpergen/ast_path_gen.go b/go/tools/asthelpergen/ast_path_gen.go index d0465cad2fa..b000a53fcbd 100644 --- a/go/tools/asthelpergen/ast_path_gen.go +++ b/go/tools/asthelpergen/ast_path_gen.go @@ -125,7 +125,7 @@ func (p *pathGen) debugString() *jen.Statement { stepName := printableTypeName(step.container) + step.name // Generate the debug string using the helper function - debugStr := fmt.Sprintf("%s:%s(%s)", types.TypeString(step.container, noQualifier), step.name, types.TypeString(step.typ, noQualifier)) + debugStr := fmt.Sprintf("(%s).%s", types.TypeString(step.container, noQualifier), step.name) if !step.slice { switchCases = append(switchCases, jen.Case(jen.Id(stepName)).Block( diff --git a/go/tools/asthelpergen/integration/ast_path.go b/go/tools/asthelpergen/integration/ast_path.go index d778538c90e..efb4bac3512 100644 --- a/go/tools/asthelpergen/integration/ast_path.go +++ b/go/tools/asthelpergen/integration/ast_path.go @@ -54,63 +54,63 @@ const ( func (s ASTStep) DebugString() string { switch s { case BytesOffset8: - return "Bytes:Offset(Bytes)8" + return "(Bytes).Offset8" case BytesOffset32: - return "Bytes:Offset(Bytes)32" + return "(Bytes).Offset32" case InterfaceSliceOffset8: - return "InterfaceSlice:Offset(InterfaceSlice)8" + return "(InterfaceSlice).Offset8" case InterfaceSliceOffset32: - return "InterfaceSlice:Offset(InterfaceSlice)32" + return "(InterfaceSlice).Offset32" case LeafSliceOffset8: - return "LeafSlice:Offset(LeafSlice)8" + return "(LeafSlice).Offset8" case LeafSliceOffset32: - return "LeafSlice:Offset(LeafSlice)32" + return "(LeafSlice).Offset32" case RefOfRefContainerASTType: - return "*RefContainer:ASTType(AST)" + return "(*RefContainer).ASTType" case RefOfRefContainerASTImplementationType: - return "*RefContainer:ASTImplementationType(*Leaf)" + return "(*RefContainer).ASTImplementationType" case RefOfRefSliceContainerASTElements8: - return "*RefSliceContainer:ASTElements(AST)8" + return "(*RefSliceContainer).ASTElements8" case RefOfRefSliceContainerASTElements32: - return "*RefSliceContainer:ASTElements(AST)32" + return "(*RefSliceContainer).ASTElements32" case RefOfRefSliceContainerASTImplementationElements8: - return "*RefSliceContainer:ASTImplementationElements(*Leaf)8" + return "(*RefSliceContainer).ASTImplementationElements8" case RefOfRefSliceContainerASTImplementationElements32: - return "*RefSliceContainer:ASTImplementationElements(*Leaf)32" + return "(*RefSliceContainer).ASTImplementationElements32" case RefOfSubImplinner: - return "*SubImpl:inner(SubIface)" + return "(*SubImpl).inner" case ValueContainerASTType: - return "ValueContainer:ASTType(AST)" + return "(ValueContainer).ASTType" case ValueContainerASTImplementationType: - return "ValueContainer:ASTImplementationType(*Leaf)" + return "(ValueContainer).ASTImplementationType" case ValueSliceContainerASTElements8: - return "ValueSliceContainer:ASTElements(AST)8" + return "(ValueSliceContainer).ASTElements8" case ValueSliceContainerASTElements32: - return "ValueSliceContainer:ASTElements(AST)32" + return "(ValueSliceContainer).ASTElements32" case ValueSliceContainerASTImplementationElements: - return "ValueSliceContainer:ASTImplementationElements(LeafSlice)" + return "(ValueSliceContainer).ASTImplementationElements" case SliceOfASTOffset8: - return "[]AST:Offset([]AST)8" + return "([]AST).Offset8" case SliceOfASTOffset32: - return "[]AST:Offset([]AST)32" + return "([]AST).Offset32" case SliceOfIntOffset8: - return "[]int:Offset([]int)8" + return "([]int).Offset8" case SliceOfIntOffset32: - return "[]int:Offset([]int)32" + return "([]int).Offset32" case SliceOfRefOfLeafOffset8: - return "[]*Leaf:Offset([]*Leaf)8" + return "([]*Leaf).Offset8" case SliceOfRefOfLeafOffset32: - return "[]*Leaf:Offset([]*Leaf)32" + return "([]*Leaf).Offset32" case RefOfValueContainerASTType: - return "*ValueContainer:ASTType(AST)" + return "(*ValueContainer).ASTType" case RefOfValueContainerASTImplementationType: - return "*ValueContainer:ASTImplementationType(*Leaf)" + return "(*ValueContainer).ASTImplementationType" case RefOfValueSliceContainerASTElements8: - return "*ValueSliceContainer:ASTElements(AST)8" + return "(*ValueSliceContainer).ASTElements8" case RefOfValueSliceContainerASTElements32: - return "*ValueSliceContainer:ASTElements(AST)32" + return "(*ValueSliceContainer).ASTElements32" case RefOfValueSliceContainerASTImplementationElements: - return "*ValueSliceContainer:ASTImplementationElements(LeafSlice)" + return "(*ValueSliceContainer).ASTImplementationElements" } panic("unknown ASTStep") } diff --git a/go/vt/sqlparser/ast_path.go b/go/vt/sqlparser/ast_path.go index 56e35f2b2b2..17168849f9e 100644 --- a/go/vt/sqlparser/ast_path.go +++ b/go/vt/sqlparser/ast_path.go @@ -640,1235 +640,1235 @@ const ( func (s ASTStep) DebugString() string { switch s { case RefOfAddColumnsColumns8: - return "*AddColumns:Columns(*ColumnDefinition)8" + return "(*AddColumns).Columns8" case RefOfAddColumnsColumns32: - return "*AddColumns:Columns(*ColumnDefinition)32" + return "(*AddColumns).Columns32" case RefOfAddColumnsAfter: - return "*AddColumns:After(*ColName)" + return "(*AddColumns).After" case RefOfAddConstraintDefinitionConstraintDefinition: - return "*AddConstraintDefinition:ConstraintDefinition(*ConstraintDefinition)" + return "(*AddConstraintDefinition).ConstraintDefinition" case RefOfAddIndexDefinitionIndexDefinition: - return "*AddIndexDefinition:IndexDefinition(*IndexDefinition)" + return "(*AddIndexDefinition).IndexDefinition" case RefOfAliasedExprExpr: - return "*AliasedExpr:Expr(Expr)" + return "(*AliasedExpr).Expr" case RefOfAliasedExprAs: - return "*AliasedExpr:As(IdentifierCI)" + return "(*AliasedExpr).As" case RefOfAliasedTableExprExpr: - return "*AliasedTableExpr:Expr(SimpleTableExpr)" + return "(*AliasedTableExpr).Expr" case RefOfAliasedTableExprPartitions: - return "*AliasedTableExpr:Partitions(Partitions)" + return "(*AliasedTableExpr).Partitions" case RefOfAliasedTableExprAs: - return "*AliasedTableExpr:As(IdentifierCS)" + return "(*AliasedTableExpr).As" case RefOfAliasedTableExprHints: - return "*AliasedTableExpr:Hints(IndexHints)" + return "(*AliasedTableExpr).Hints" case RefOfAliasedTableExprColumns: - return "*AliasedTableExpr:Columns(Columns)" + return "(*AliasedTableExpr).Columns" case RefOfAlterCheckName: - return "*AlterCheck:Name(IdentifierCI)" + return "(*AlterCheck).Name" case RefOfAlterColumnColumn: - return "*AlterColumn:Column(*ColName)" + return "(*AlterColumn).Column" case RefOfAlterColumnDefaultVal: - return "*AlterColumn:DefaultVal(Expr)" + return "(*AlterColumn).DefaultVal" case RefOfAlterDatabaseComments: - return "*AlterDatabase:Comments(*ParsedComments)" + return "(*AlterDatabase).Comments" case RefOfAlterDatabaseDBName: - return "*AlterDatabase:DBName(IdentifierCS)" + return "(*AlterDatabase).DBName" case RefOfAlterIndexName: - return "*AlterIndex:Name(IdentifierCI)" + return "(*AlterIndex).Name" case RefOfAlterMigrationRatio: - return "*AlterMigration:Ratio(*Literal)" + return "(*AlterMigration).Ratio" case RefOfAlterTableTable: - return "*AlterTable:Table(TableName)" + return "(*AlterTable).Table" case RefOfAlterTableAlterOptions8: - return "*AlterTable:AlterOptions(AlterOption)8" + return "(*AlterTable).AlterOptions8" case RefOfAlterTableAlterOptions32: - return "*AlterTable:AlterOptions(AlterOption)32" + return "(*AlterTable).AlterOptions32" case RefOfAlterTablePartitionSpec: - return "*AlterTable:PartitionSpec(*PartitionSpec)" + return "(*AlterTable).PartitionSpec" case RefOfAlterTablePartitionOption: - return "*AlterTable:PartitionOption(*PartitionOption)" + return "(*AlterTable).PartitionOption" case RefOfAlterTableComments: - return "*AlterTable:Comments(*ParsedComments)" + return "(*AlterTable).Comments" case RefOfAlterViewViewName: - return "*AlterView:ViewName(TableName)" + return "(*AlterView).ViewName" case RefOfAlterViewDefiner: - return "*AlterView:Definer(*Definer)" + return "(*AlterView).Definer" case RefOfAlterViewColumns: - return "*AlterView:Columns(Columns)" + return "(*AlterView).Columns" case RefOfAlterViewSelect: - return "*AlterView:Select(TableStatement)" + return "(*AlterView).Select" case RefOfAlterViewComments: - return "*AlterView:Comments(*ParsedComments)" + return "(*AlterView).Comments" case RefOfAlterVschemaTable: - return "*AlterVschema:Table(TableName)" + return "(*AlterVschema).Table" case RefOfAlterVschemaVindexSpec: - return "*AlterVschema:VindexSpec(*VindexSpec)" + return "(*AlterVschema).VindexSpec" case RefOfAlterVschemaVindexCols8: - return "*AlterVschema:VindexCols(IdentifierCI)8" + return "(*AlterVschema).VindexCols8" case RefOfAlterVschemaVindexCols32: - return "*AlterVschema:VindexCols(IdentifierCI)32" + return "(*AlterVschema).VindexCols32" case RefOfAlterVschemaAutoIncSpec: - return "*AlterVschema:AutoIncSpec(*AutoIncSpec)" + return "(*AlterVschema).AutoIncSpec" case RefOfAnalyzeTable: - return "*Analyze:Table(TableName)" + return "(*Analyze).Table" case RefOfAndExprLeft: - return "*AndExpr:Left(Expr)" + return "(*AndExpr).Left" case RefOfAndExprRight: - return "*AndExpr:Right(Expr)" + return "(*AndExpr).Right" case RefOfAnyValueArg: - return "*AnyValue:Arg(Expr)" + return "(*AnyValue).Arg" case RefOfArgumentLessWindowExprOverClause: - return "*ArgumentLessWindowExpr:OverClause(*OverClause)" + return "(*ArgumentLessWindowExpr).OverClause" case RefOfAssignmentExprLeft: - return "*AssignmentExpr:Left(Expr)" + return "(*AssignmentExpr).Left" case RefOfAssignmentExprRight: - return "*AssignmentExpr:Right(Expr)" + return "(*AssignmentExpr).Right" case RefOfAutoIncSpecColumn: - return "*AutoIncSpec:Column(IdentifierCI)" + return "(*AutoIncSpec).Column" case RefOfAutoIncSpecSequence: - return "*AutoIncSpec:Sequence(TableName)" + return "(*AutoIncSpec).Sequence" case RefOfAvgArg: - return "*Avg:Arg(Expr)" + return "(*Avg).Arg" case RefOfAvgOverClause: - return "*Avg:OverClause(*OverClause)" + return "(*Avg).OverClause" case RefOfBetweenExprLeft: - return "*BetweenExpr:Left(Expr)" + return "(*BetweenExpr).Left" case RefOfBetweenExprFrom: - return "*BetweenExpr:From(Expr)" + return "(*BetweenExpr).From" case RefOfBetweenExprTo: - return "*BetweenExpr:To(Expr)" + return "(*BetweenExpr).To" case RefOfBinaryExprLeft: - return "*BinaryExpr:Left(Expr)" + return "(*BinaryExpr).Left" case RefOfBinaryExprRight: - return "*BinaryExpr:Right(Expr)" + return "(*BinaryExpr).Right" case RefOfBitAndArg: - return "*BitAnd:Arg(Expr)" + return "(*BitAnd).Arg" case RefOfBitAndOverClause: - return "*BitAnd:OverClause(*OverClause)" + return "(*BitAnd).OverClause" case RefOfBitOrArg: - return "*BitOr:Arg(Expr)" + return "(*BitOr).Arg" case RefOfBitOrOverClause: - return "*BitOr:OverClause(*OverClause)" + return "(*BitOr).OverClause" case RefOfBitXorArg: - return "*BitXor:Arg(Expr)" + return "(*BitXor).Arg" case RefOfBitXorOverClause: - return "*BitXor:OverClause(*OverClause)" + return "(*BitXor).OverClause" case RefOfCallProcName: - return "*CallProc:Name(TableName)" + return "(*CallProc).Name" case RefOfCallProcParams: - return "*CallProc:Params(Exprs)" + return "(*CallProc).Params" case RefOfCaseExprExpr: - return "*CaseExpr:Expr(Expr)" + return "(*CaseExpr).Expr" case RefOfCaseExprWhens8: - return "*CaseExpr:Whens(*When)8" + return "(*CaseExpr).Whens8" case RefOfCaseExprWhens32: - return "*CaseExpr:Whens(*When)32" + return "(*CaseExpr).Whens32" case RefOfCaseExprElse: - return "*CaseExpr:Else(Expr)" + return "(*CaseExpr).Else" case RefOfCastExprExpr: - return "*CastExpr:Expr(Expr)" + return "(*CastExpr).Expr" case RefOfCastExprType: - return "*CastExpr:Type(*ConvertType)" + return "(*CastExpr).Type" case RefOfChangeColumnOldColumn: - return "*ChangeColumn:OldColumn(*ColName)" + return "(*ChangeColumn).OldColumn" case RefOfChangeColumnNewColDefinition: - return "*ChangeColumn:NewColDefinition(*ColumnDefinition)" + return "(*ChangeColumn).NewColDefinition" case RefOfChangeColumnAfter: - return "*ChangeColumn:After(*ColName)" + return "(*ChangeColumn).After" case RefOfCharExprExprs: - return "*CharExpr:Exprs(Exprs)" + return "(*CharExpr).Exprs" case RefOfCheckConstraintDefinitionExpr: - return "*CheckConstraintDefinition:Expr(Expr)" + return "(*CheckConstraintDefinition).Expr" case RefOfColNameName: - return "*ColName:Name(IdentifierCI)" + return "(*ColName).Name" case RefOfColNameQualifier: - return "*ColName:Qualifier(TableName)" + return "(*ColName).Qualifier" case RefOfCollateExprExpr: - return "*CollateExpr:Expr(Expr)" + return "(*CollateExpr).Expr" case RefOfColumnDefinitionName: - return "*ColumnDefinition:Name(IdentifierCI)" + return "(*ColumnDefinition).Name" case RefOfColumnDefinitionType: - return "*ColumnDefinition:Type(*ColumnType)" + return "(*ColumnDefinition).Type" case ColumnsOffset8: - return "Columns:Offset(Columns)8" + return "(Columns).Offset8" case ColumnsOffset32: - return "Columns:Offset(Columns)32" + return "(Columns).Offset32" case RefOfCommonTableExprID: - return "*CommonTableExpr:ID(IdentifierCS)" + return "(*CommonTableExpr).ID" case RefOfCommonTableExprColumns: - return "*CommonTableExpr:Columns(Columns)" + return "(*CommonTableExpr).Columns" case RefOfCommonTableExprSubquery: - return "*CommonTableExpr:Subquery(TableStatement)" + return "(*CommonTableExpr).Subquery" case RefOfComparisonExprLeft: - return "*ComparisonExpr:Left(Expr)" + return "(*ComparisonExpr).Left" case RefOfComparisonExprRight: - return "*ComparisonExpr:Right(Expr)" + return "(*ComparisonExpr).Right" case RefOfComparisonExprEscape: - return "*ComparisonExpr:Escape(Expr)" + return "(*ComparisonExpr).Escape" case RefOfConstraintDefinitionName: - return "*ConstraintDefinition:Name(IdentifierCI)" + return "(*ConstraintDefinition).Name" case RefOfConstraintDefinitionDetails: - return "*ConstraintDefinition:Details(ConstraintInfo)" + return "(*ConstraintDefinition).Details" case RefOfConvertExprExpr: - return "*ConvertExpr:Expr(Expr)" + return "(*ConvertExpr).Expr" case RefOfConvertExprType: - return "*ConvertExpr:Type(*ConvertType)" + return "(*ConvertExpr).Type" case RefOfConvertUsingExprExpr: - return "*ConvertUsingExpr:Expr(Expr)" + return "(*ConvertUsingExpr).Expr" case RefOfCountArgs: - return "*Count:Args(Exprs)" + return "(*Count).Args" case RefOfCountOverClause: - return "*Count:OverClause(*OverClause)" + return "(*Count).OverClause" case RefOfCountStarOverClause: - return "*CountStar:OverClause(*OverClause)" + return "(*CountStar).OverClause" case RefOfCreateDatabaseComments: - return "*CreateDatabase:Comments(*ParsedComments)" + return "(*CreateDatabase).Comments" case RefOfCreateDatabaseDBName: - return "*CreateDatabase:DBName(IdentifierCS)" + return "(*CreateDatabase).DBName" case RefOfCreateTableTable: - return "*CreateTable:Table(TableName)" + return "(*CreateTable).Table" case RefOfCreateTableTableSpec: - return "*CreateTable:TableSpec(*TableSpec)" + return "(*CreateTable).TableSpec" case RefOfCreateTableOptLike: - return "*CreateTable:OptLike(*OptLike)" + return "(*CreateTable).OptLike" case RefOfCreateTableComments: - return "*CreateTable:Comments(*ParsedComments)" + return "(*CreateTable).Comments" case RefOfCreateViewViewName: - return "*CreateView:ViewName(TableName)" + return "(*CreateView).ViewName" case RefOfCreateViewDefiner: - return "*CreateView:Definer(*Definer)" + return "(*CreateView).Definer" case RefOfCreateViewColumns: - return "*CreateView:Columns(Columns)" + return "(*CreateView).Columns" case RefOfCreateViewSelect: - return "*CreateView:Select(TableStatement)" + return "(*CreateView).Select" case RefOfCreateViewComments: - return "*CreateView:Comments(*ParsedComments)" + return "(*CreateView).Comments" case RefOfCurTimeFuncExprName: - return "*CurTimeFuncExpr:Name(IdentifierCI)" + return "(*CurTimeFuncExpr).Name" case RefOfDeallocateStmtComments: - return "*DeallocateStmt:Comments(*ParsedComments)" + return "(*DeallocateStmt).Comments" case RefOfDeallocateStmtName: - return "*DeallocateStmt:Name(IdentifierCI)" + return "(*DeallocateStmt).Name" case RefOfDeleteWith: - return "*Delete:With(*With)" + return "(*Delete).With" case RefOfDeleteComments: - return "*Delete:Comments(*ParsedComments)" + return "(*Delete).Comments" case RefOfDeleteTableExprs8: - return "*Delete:TableExprs(TableExpr)8" + return "(*Delete).TableExprs8" case RefOfDeleteTableExprs32: - return "*Delete:TableExprs(TableExpr)32" + return "(*Delete).TableExprs32" case RefOfDeleteTargets: - return "*Delete:Targets(TableNames)" + return "(*Delete).Targets" case RefOfDeletePartitions: - return "*Delete:Partitions(Partitions)" + return "(*Delete).Partitions" case RefOfDeleteWhere: - return "*Delete:Where(*Where)" + return "(*Delete).Where" case RefOfDeleteOrderBy: - return "*Delete:OrderBy(OrderBy)" + return "(*Delete).OrderBy" case RefOfDeleteLimit: - return "*Delete:Limit(*Limit)" + return "(*Delete).Limit" case RefOfDerivedTableSelect: - return "*DerivedTable:Select(TableStatement)" + return "(*DerivedTable).Select" case RefOfDropColumnName: - return "*DropColumn:Name(*ColName)" + return "(*DropColumn).Name" case RefOfDropDatabaseComments: - return "*DropDatabase:Comments(*ParsedComments)" + return "(*DropDatabase).Comments" case RefOfDropDatabaseDBName: - return "*DropDatabase:DBName(IdentifierCS)" + return "(*DropDatabase).DBName" case RefOfDropKeyName: - return "*DropKey:Name(IdentifierCI)" + return "(*DropKey).Name" case RefOfDropTableFromTables: - return "*DropTable:FromTables(TableNames)" + return "(*DropTable).FromTables" case RefOfDropTableComments: - return "*DropTable:Comments(*ParsedComments)" + return "(*DropTable).Comments" case RefOfDropViewFromTables: - return "*DropView:FromTables(TableNames)" + return "(*DropView).FromTables" case RefOfDropViewComments: - return "*DropView:Comments(*ParsedComments)" + return "(*DropView).Comments" case RefOfExecuteStmtName: - return "*ExecuteStmt:Name(IdentifierCI)" + return "(*ExecuteStmt).Name" case RefOfExecuteStmtComments: - return "*ExecuteStmt:Comments(*ParsedComments)" + return "(*ExecuteStmt).Comments" case RefOfExecuteStmtArguments8: - return "*ExecuteStmt:Arguments(*Variable)8" + return "(*ExecuteStmt).Arguments8" case RefOfExecuteStmtArguments32: - return "*ExecuteStmt:Arguments(*Variable)32" + return "(*ExecuteStmt).Arguments32" case RefOfExistsExprSubquery: - return "*ExistsExpr:Subquery(*Subquery)" + return "(*ExistsExpr).Subquery" case RefOfExplainStmtStatement: - return "*ExplainStmt:Statement(Statement)" + return "(*ExplainStmt).Statement" case RefOfExplainStmtComments: - return "*ExplainStmt:Comments(*ParsedComments)" + return "(*ExplainStmt).Comments" case RefOfExplainTabTable: - return "*ExplainTab:Table(TableName)" + return "(*ExplainTab).Table" case ExprsOffset8: - return "Exprs:Offset(Exprs)8" + return "(Exprs).Offset8" case ExprsOffset32: - return "Exprs:Offset(Exprs)32" + return "(Exprs).Offset32" case RefOfExtractFuncExprExpr: - return "*ExtractFuncExpr:Expr(Expr)" + return "(*ExtractFuncExpr).Expr" case RefOfExtractValueExprFragment: - return "*ExtractValueExpr:Fragment(Expr)" + return "(*ExtractValueExpr).Fragment" case RefOfExtractValueExprXPathExpr: - return "*ExtractValueExpr:XPathExpr(Expr)" + return "(*ExtractValueExpr).XPathExpr" case RefOfFirstOrLastValueExprExpr: - return "*FirstOrLastValueExpr:Expr(Expr)" + return "(*FirstOrLastValueExpr).Expr" case RefOfFirstOrLastValueExprNullTreatmentClause: - return "*FirstOrLastValueExpr:NullTreatmentClause(*NullTreatmentClause)" + return "(*FirstOrLastValueExpr).NullTreatmentClause" case RefOfFirstOrLastValueExprOverClause: - return "*FirstOrLastValueExpr:OverClause(*OverClause)" + return "(*FirstOrLastValueExpr).OverClause" case RefOfFlushTableNames: - return "*Flush:TableNames(TableNames)" + return "(*Flush).TableNames" case RefOfForeignKeyDefinitionSource: - return "*ForeignKeyDefinition:Source(Columns)" + return "(*ForeignKeyDefinition).Source" case RefOfForeignKeyDefinitionIndexName: - return "*ForeignKeyDefinition:IndexName(IdentifierCI)" + return "(*ForeignKeyDefinition).IndexName" case RefOfForeignKeyDefinitionReferenceDefinition: - return "*ForeignKeyDefinition:ReferenceDefinition(*ReferenceDefinition)" + return "(*ForeignKeyDefinition).ReferenceDefinition" case RefOfFrameClauseStart: - return "*FrameClause:Start(*FramePoint)" + return "(*FrameClause).Start" case RefOfFrameClauseEnd: - return "*FrameClause:End(*FramePoint)" + return "(*FrameClause).End" case RefOfFramePointExpr: - return "*FramePoint:Expr(Expr)" + return "(*FramePoint).Expr" case RefOfFuncExprQualifier: - return "*FuncExpr:Qualifier(IdentifierCS)" + return "(*FuncExpr).Qualifier" case RefOfFuncExprName: - return "*FuncExpr:Name(IdentifierCI)" + return "(*FuncExpr).Name" case RefOfFuncExprExprs: - return "*FuncExpr:Exprs(Exprs)" + return "(*FuncExpr).Exprs" case RefOfGTIDFuncExprSet1: - return "*GTIDFuncExpr:Set1(Expr)" + return "(*GTIDFuncExpr).Set1" case RefOfGTIDFuncExprSet2: - return "*GTIDFuncExpr:Set2(Expr)" + return "(*GTIDFuncExpr).Set2" case RefOfGTIDFuncExprTimeout: - return "*GTIDFuncExpr:Timeout(Expr)" + return "(*GTIDFuncExpr).Timeout" case RefOfGTIDFuncExprChannel: - return "*GTIDFuncExpr:Channel(Expr)" + return "(*GTIDFuncExpr).Channel" case RefOfGeoHashFromLatLongExprLatitude: - return "*GeoHashFromLatLongExpr:Latitude(Expr)" + return "(*GeoHashFromLatLongExpr).Latitude" case RefOfGeoHashFromLatLongExprLongitude: - return "*GeoHashFromLatLongExpr:Longitude(Expr)" + return "(*GeoHashFromLatLongExpr).Longitude" case RefOfGeoHashFromLatLongExprMaxLength: - return "*GeoHashFromLatLongExpr:MaxLength(Expr)" + return "(*GeoHashFromLatLongExpr).MaxLength" case RefOfGeoHashFromPointExprPoint: - return "*GeoHashFromPointExpr:Point(Expr)" + return "(*GeoHashFromPointExpr).Point" case RefOfGeoHashFromPointExprMaxLength: - return "*GeoHashFromPointExpr:MaxLength(Expr)" + return "(*GeoHashFromPointExpr).MaxLength" case RefOfGeoJSONFromGeomExprGeom: - return "*GeoJSONFromGeomExpr:Geom(Expr)" + return "(*GeoJSONFromGeomExpr).Geom" case RefOfGeoJSONFromGeomExprMaxDecimalDigits: - return "*GeoJSONFromGeomExpr:MaxDecimalDigits(Expr)" + return "(*GeoJSONFromGeomExpr).MaxDecimalDigits" case RefOfGeoJSONFromGeomExprBitmask: - return "*GeoJSONFromGeomExpr:Bitmask(Expr)" + return "(*GeoJSONFromGeomExpr).Bitmask" case RefOfGeomCollPropertyFuncExprGeomColl: - return "*GeomCollPropertyFuncExpr:GeomColl(Expr)" + return "(*GeomCollPropertyFuncExpr).GeomColl" case RefOfGeomCollPropertyFuncExprPropertyDefArg: - return "*GeomCollPropertyFuncExpr:PropertyDefArg(Expr)" + return "(*GeomCollPropertyFuncExpr).PropertyDefArg" case RefOfGeomFormatExprGeom: - return "*GeomFormatExpr:Geom(Expr)" + return "(*GeomFormatExpr).Geom" case RefOfGeomFormatExprAxisOrderOpt: - return "*GeomFormatExpr:AxisOrderOpt(Expr)" + return "(*GeomFormatExpr).AxisOrderOpt" case RefOfGeomFromGeoHashExprGeoHash: - return "*GeomFromGeoHashExpr:GeoHash(Expr)" + return "(*GeomFromGeoHashExpr).GeoHash" case RefOfGeomFromGeoHashExprSridOpt: - return "*GeomFromGeoHashExpr:SridOpt(Expr)" + return "(*GeomFromGeoHashExpr).SridOpt" case RefOfGeomFromGeoJSONExprGeoJSON: - return "*GeomFromGeoJSONExpr:GeoJSON(Expr)" + return "(*GeomFromGeoJSONExpr).GeoJSON" case RefOfGeomFromGeoJSONExprHigherDimHandlerOpt: - return "*GeomFromGeoJSONExpr:HigherDimHandlerOpt(Expr)" + return "(*GeomFromGeoJSONExpr).HigherDimHandlerOpt" case RefOfGeomFromGeoJSONExprSrid: - return "*GeomFromGeoJSONExpr:Srid(Expr)" + return "(*GeomFromGeoJSONExpr).Srid" case RefOfGeomFromTextExprWktText: - return "*GeomFromTextExpr:WktText(Expr)" + return "(*GeomFromTextExpr).WktText" case RefOfGeomFromTextExprSrid: - return "*GeomFromTextExpr:Srid(Expr)" + return "(*GeomFromTextExpr).Srid" case RefOfGeomFromTextExprAxisOrderOpt: - return "*GeomFromTextExpr:AxisOrderOpt(Expr)" + return "(*GeomFromTextExpr).AxisOrderOpt" case RefOfGeomFromWKBExprWkbBlob: - return "*GeomFromWKBExpr:WkbBlob(Expr)" + return "(*GeomFromWKBExpr).WkbBlob" case RefOfGeomFromWKBExprSrid: - return "*GeomFromWKBExpr:Srid(Expr)" + return "(*GeomFromWKBExpr).Srid" case RefOfGeomFromWKBExprAxisOrderOpt: - return "*GeomFromWKBExpr:AxisOrderOpt(Expr)" + return "(*GeomFromWKBExpr).AxisOrderOpt" case RefOfGeomPropertyFuncExprGeom: - return "*GeomPropertyFuncExpr:Geom(Expr)" + return "(*GeomPropertyFuncExpr).Geom" case RefOfGroupByExprs8: - return "*GroupBy:Exprs(Expr)8" + return "(*GroupBy).Exprs8" case RefOfGroupByExprs32: - return "*GroupBy:Exprs(Expr)32" + return "(*GroupBy).Exprs32" case RefOfGroupConcatExprExprs: - return "*GroupConcatExpr:Exprs(Exprs)" + return "(*GroupConcatExpr).Exprs" case RefOfGroupConcatExprOrderBy: - return "*GroupConcatExpr:OrderBy(OrderBy)" + return "(*GroupConcatExpr).OrderBy" case RefOfGroupConcatExprLimit: - return "*GroupConcatExpr:Limit(*Limit)" + return "(*GroupConcatExpr).Limit" case RefOfIndexDefinitionInfo: - return "*IndexDefinition:Info(*IndexInfo)" + return "(*IndexDefinition).Info" case RefOfIndexHintIndexes8: - return "*IndexHint:Indexes(IdentifierCI)8" + return "(*IndexHint).Indexes8" case RefOfIndexHintIndexes32: - return "*IndexHint:Indexes(IdentifierCI)32" + return "(*IndexHint).Indexes32" case IndexHintsOffset8: - return "IndexHints:Offset(IndexHints)8" + return "(IndexHints).Offset8" case IndexHintsOffset32: - return "IndexHints:Offset(IndexHints)32" + return "(IndexHints).Offset32" case RefOfIndexInfoName: - return "*IndexInfo:Name(IdentifierCI)" + return "(*IndexInfo).Name" case RefOfIndexInfoConstraintName: - return "*IndexInfo:ConstraintName(IdentifierCI)" + return "(*IndexInfo).ConstraintName" case RefOfInsertComments: - return "*Insert:Comments(*ParsedComments)" + return "(*Insert).Comments" case RefOfInsertTable: - return "*Insert:Table(*AliasedTableExpr)" + return "(*Insert).Table" case RefOfInsertPartitions: - return "*Insert:Partitions(Partitions)" + return "(*Insert).Partitions" case RefOfInsertColumns: - return "*Insert:Columns(Columns)" + return "(*Insert).Columns" case RefOfInsertRows: - return "*Insert:Rows(InsertRows)" + return "(*Insert).Rows" case RefOfInsertRowAlias: - return "*Insert:RowAlias(*RowAlias)" + return "(*Insert).RowAlias" case RefOfInsertOnDup: - return "*Insert:OnDup(OnDup)" + return "(*Insert).OnDup" case RefOfInsertExprStr: - return "*InsertExpr:Str(Expr)" + return "(*InsertExpr).Str" case RefOfInsertExprPos: - return "*InsertExpr:Pos(Expr)" + return "(*InsertExpr).Pos" case RefOfInsertExprLen: - return "*InsertExpr:Len(Expr)" + return "(*InsertExpr).Len" case RefOfInsertExprNewStr: - return "*InsertExpr:NewStr(Expr)" + return "(*InsertExpr).NewStr" case RefOfIntervalDateExprDate: - return "*IntervalDateExpr:Date(Expr)" + return "(*IntervalDateExpr).Date" case RefOfIntervalDateExprInterval: - return "*IntervalDateExpr:Interval(Expr)" + return "(*IntervalDateExpr).Interval" case RefOfIntervalFuncExprExpr: - return "*IntervalFuncExpr:Expr(Expr)" + return "(*IntervalFuncExpr).Expr" case RefOfIntervalFuncExprExprs: - return "*IntervalFuncExpr:Exprs(Exprs)" + return "(*IntervalFuncExpr).Exprs" case RefOfIntroducerExprExpr: - return "*IntroducerExpr:Expr(Expr)" + return "(*IntroducerExpr).Expr" case RefOfIsExprLeft: - return "*IsExpr:Left(Expr)" + return "(*IsExpr).Left" case RefOfJSONArrayAggExpr: - return "*JSONArrayAgg:Expr(Expr)" + return "(*JSONArrayAgg).Expr" case RefOfJSONArrayAggOverClause: - return "*JSONArrayAgg:OverClause(*OverClause)" + return "(*JSONArrayAgg).OverClause" case RefOfJSONArrayExprParams: - return "*JSONArrayExpr:Params(Exprs)" + return "(*JSONArrayExpr).Params" case RefOfJSONAttributesExprJSONDoc: - return "*JSONAttributesExpr:JSONDoc(Expr)" + return "(*JSONAttributesExpr).JSONDoc" case RefOfJSONAttributesExprPath: - return "*JSONAttributesExpr:Path(Expr)" + return "(*JSONAttributesExpr).Path" case RefOfJSONContainsExprTarget: - return "*JSONContainsExpr:Target(Expr)" + return "(*JSONContainsExpr).Target" case RefOfJSONContainsExprCandidate: - return "*JSONContainsExpr:Candidate(Expr)" + return "(*JSONContainsExpr).Candidate" case RefOfJSONContainsExprPathList8: - return "*JSONContainsExpr:PathList(Expr)8" + return "(*JSONContainsExpr).PathList8" case RefOfJSONContainsExprPathList32: - return "*JSONContainsExpr:PathList(Expr)32" + return "(*JSONContainsExpr).PathList32" case RefOfJSONContainsPathExprJSONDoc: - return "*JSONContainsPathExpr:JSONDoc(Expr)" + return "(*JSONContainsPathExpr).JSONDoc" case RefOfJSONContainsPathExprOneOrAll: - return "*JSONContainsPathExpr:OneOrAll(Expr)" + return "(*JSONContainsPathExpr).OneOrAll" case RefOfJSONContainsPathExprPathList8: - return "*JSONContainsPathExpr:PathList(Expr)8" + return "(*JSONContainsPathExpr).PathList8" case RefOfJSONContainsPathExprPathList32: - return "*JSONContainsPathExpr:PathList(Expr)32" + return "(*JSONContainsPathExpr).PathList32" case RefOfJSONExtractExprJSONDoc: - return "*JSONExtractExpr:JSONDoc(Expr)" + return "(*JSONExtractExpr).JSONDoc" case RefOfJSONExtractExprPathList8: - return "*JSONExtractExpr:PathList(Expr)8" + return "(*JSONExtractExpr).PathList8" case RefOfJSONExtractExprPathList32: - return "*JSONExtractExpr:PathList(Expr)32" + return "(*JSONExtractExpr).PathList32" case RefOfJSONKeysExprJSONDoc: - return "*JSONKeysExpr:JSONDoc(Expr)" + return "(*JSONKeysExpr).JSONDoc" case RefOfJSONKeysExprPath: - return "*JSONKeysExpr:Path(Expr)" + return "(*JSONKeysExpr).Path" case RefOfJSONObjectAggKey: - return "*JSONObjectAgg:Key(Expr)" + return "(*JSONObjectAgg).Key" case RefOfJSONObjectAggValue: - return "*JSONObjectAgg:Value(Expr)" + return "(*JSONObjectAgg).Value" case RefOfJSONObjectAggOverClause: - return "*JSONObjectAgg:OverClause(*OverClause)" + return "(*JSONObjectAgg).OverClause" case RefOfJSONObjectExprParams8: - return "*JSONObjectExpr:Params(*JSONObjectParam)8" + return "(*JSONObjectExpr).Params8" case RefOfJSONObjectExprParams32: - return "*JSONObjectExpr:Params(*JSONObjectParam)32" + return "(*JSONObjectExpr).Params32" case RefOfJSONObjectParamKey: - return "*JSONObjectParam:Key(Expr)" + return "(*JSONObjectParam).Key" case RefOfJSONObjectParamValue: - return "*JSONObjectParam:Value(Expr)" + return "(*JSONObjectParam).Value" case RefOfJSONOverlapsExprJSONDoc1: - return "*JSONOverlapsExpr:JSONDoc1(Expr)" + return "(*JSONOverlapsExpr).JSONDoc1" case RefOfJSONOverlapsExprJSONDoc2: - return "*JSONOverlapsExpr:JSONDoc2(Expr)" + return "(*JSONOverlapsExpr).JSONDoc2" case RefOfJSONPrettyExprJSONVal: - return "*JSONPrettyExpr:JSONVal(Expr)" + return "(*JSONPrettyExpr).JSONVal" case RefOfJSONQuoteExprStringArg: - return "*JSONQuoteExpr:StringArg(Expr)" + return "(*JSONQuoteExpr).StringArg" case RefOfJSONRemoveExprJSONDoc: - return "*JSONRemoveExpr:JSONDoc(Expr)" + return "(*JSONRemoveExpr).JSONDoc" case RefOfJSONRemoveExprPathList: - return "*JSONRemoveExpr:PathList(Exprs)" + return "(*JSONRemoveExpr).PathList" case RefOfJSONSchemaValidFuncExprSchema: - return "*JSONSchemaValidFuncExpr:Schema(Expr)" + return "(*JSONSchemaValidFuncExpr).Schema" case RefOfJSONSchemaValidFuncExprDocument: - return "*JSONSchemaValidFuncExpr:Document(Expr)" + return "(*JSONSchemaValidFuncExpr).Document" case RefOfJSONSchemaValidationReportFuncExprSchema: - return "*JSONSchemaValidationReportFuncExpr:Schema(Expr)" + return "(*JSONSchemaValidationReportFuncExpr).Schema" case RefOfJSONSchemaValidationReportFuncExprDocument: - return "*JSONSchemaValidationReportFuncExpr:Document(Expr)" + return "(*JSONSchemaValidationReportFuncExpr).Document" case RefOfJSONSearchExprJSONDoc: - return "*JSONSearchExpr:JSONDoc(Expr)" + return "(*JSONSearchExpr).JSONDoc" case RefOfJSONSearchExprOneOrAll: - return "*JSONSearchExpr:OneOrAll(Expr)" + return "(*JSONSearchExpr).OneOrAll" case RefOfJSONSearchExprSearchStr: - return "*JSONSearchExpr:SearchStr(Expr)" + return "(*JSONSearchExpr).SearchStr" case RefOfJSONSearchExprEscapeChar: - return "*JSONSearchExpr:EscapeChar(Expr)" + return "(*JSONSearchExpr).EscapeChar" case RefOfJSONSearchExprPathList8: - return "*JSONSearchExpr:PathList(Expr)8" + return "(*JSONSearchExpr).PathList8" case RefOfJSONSearchExprPathList32: - return "*JSONSearchExpr:PathList(Expr)32" + return "(*JSONSearchExpr).PathList32" case RefOfJSONStorageFreeExprJSONVal: - return "*JSONStorageFreeExpr:JSONVal(Expr)" + return "(*JSONStorageFreeExpr).JSONVal" case RefOfJSONStorageSizeExprJSONVal: - return "*JSONStorageSizeExpr:JSONVal(Expr)" + return "(*JSONStorageSizeExpr).JSONVal" case RefOfJSONTableExprExpr: - return "*JSONTableExpr:Expr(Expr)" + return "(*JSONTableExpr).Expr" case RefOfJSONTableExprAlias: - return "*JSONTableExpr:Alias(IdentifierCS)" + return "(*JSONTableExpr).Alias" case RefOfJSONTableExprFilter: - return "*JSONTableExpr:Filter(Expr)" + return "(*JSONTableExpr).Filter" case RefOfJSONTableExprColumns8: - return "*JSONTableExpr:Columns(*JtColumnDefinition)8" + return "(*JSONTableExpr).Columns8" case RefOfJSONTableExprColumns32: - return "*JSONTableExpr:Columns(*JtColumnDefinition)32" + return "(*JSONTableExpr).Columns32" case RefOfJSONUnquoteExprJSONValue: - return "*JSONUnquoteExpr:JSONValue(Expr)" + return "(*JSONUnquoteExpr).JSONValue" case RefOfJSONValueExprJSONDoc: - return "*JSONValueExpr:JSONDoc(Expr)" + return "(*JSONValueExpr).JSONDoc" case RefOfJSONValueExprPath: - return "*JSONValueExpr:Path(Expr)" + return "(*JSONValueExpr).Path" case RefOfJSONValueExprReturningType: - return "*JSONValueExpr:ReturningType(*ConvertType)" + return "(*JSONValueExpr).ReturningType" case RefOfJSONValueExprEmptyOnResponse: - return "*JSONValueExpr:EmptyOnResponse(*JtOnResponse)" + return "(*JSONValueExpr).EmptyOnResponse" case RefOfJSONValueExprErrorOnResponse: - return "*JSONValueExpr:ErrorOnResponse(*JtOnResponse)" + return "(*JSONValueExpr).ErrorOnResponse" case RefOfJSONValueMergeExprJSONDoc: - return "*JSONValueMergeExpr:JSONDoc(Expr)" + return "(*JSONValueMergeExpr).JSONDoc" case RefOfJSONValueMergeExprJSONDocList: - return "*JSONValueMergeExpr:JSONDocList(Exprs)" + return "(*JSONValueMergeExpr).JSONDocList" case RefOfJSONValueModifierExprJSONDoc: - return "*JSONValueModifierExpr:JSONDoc(Expr)" + return "(*JSONValueModifierExpr).JSONDoc" case RefOfJSONValueModifierExprParams8: - return "*JSONValueModifierExpr:Params(*JSONObjectParam)8" + return "(*JSONValueModifierExpr).Params8" case RefOfJSONValueModifierExprParams32: - return "*JSONValueModifierExpr:Params(*JSONObjectParam)32" + return "(*JSONValueModifierExpr).Params32" case RefOfJoinConditionOn: - return "*JoinCondition:On(Expr)" + return "(*JoinCondition).On" case RefOfJoinConditionUsing: - return "*JoinCondition:Using(Columns)" + return "(*JoinCondition).Using" case RefOfJoinTableExprLeftExpr: - return "*JoinTableExpr:LeftExpr(TableExpr)" + return "(*JoinTableExpr).LeftExpr" case RefOfJoinTableExprRightExpr: - return "*JoinTableExpr:RightExpr(TableExpr)" + return "(*JoinTableExpr).RightExpr" case RefOfJoinTableExprCondition: - return "*JoinTableExpr:Condition(*JoinCondition)" + return "(*JoinTableExpr).Condition" case RefOfJtOnResponseExpr: - return "*JtOnResponse:Expr(Expr)" + return "(*JtOnResponse).Expr" case RefOfLagLeadExprExpr: - return "*LagLeadExpr:Expr(Expr)" + return "(*LagLeadExpr).Expr" case RefOfLagLeadExprN: - return "*LagLeadExpr:N(Expr)" + return "(*LagLeadExpr).N" case RefOfLagLeadExprDefault: - return "*LagLeadExpr:Default(Expr)" + return "(*LagLeadExpr).Default" case RefOfLagLeadExprOverClause: - return "*LagLeadExpr:OverClause(*OverClause)" + return "(*LagLeadExpr).OverClause" case RefOfLagLeadExprNullTreatmentClause: - return "*LagLeadExpr:NullTreatmentClause(*NullTreatmentClause)" + return "(*LagLeadExpr).NullTreatmentClause" case RefOfLimitOffset: - return "*Limit:Offset(Expr)" + return "(*Limit).Offset" case RefOfLimitRowcount: - return "*Limit:Rowcount(Expr)" + return "(*Limit).Rowcount" case RefOfLineStringExprPointParams: - return "*LineStringExpr:PointParams(Exprs)" + return "(*LineStringExpr).PointParams" case RefOfLinestrPropertyFuncExprLinestring: - return "*LinestrPropertyFuncExpr:Linestring(Expr)" + return "(*LinestrPropertyFuncExpr).Linestring" case RefOfLinestrPropertyFuncExprPropertyDefArg: - return "*LinestrPropertyFuncExpr:PropertyDefArg(Expr)" + return "(*LinestrPropertyFuncExpr).PropertyDefArg" case RefOfLocateExprSubStr: - return "*LocateExpr:SubStr(Expr)" + return "(*LocateExpr).SubStr" case RefOfLocateExprStr: - return "*LocateExpr:Str(Expr)" + return "(*LocateExpr).Str" case RefOfLocateExprPos: - return "*LocateExpr:Pos(Expr)" + return "(*LocateExpr).Pos" case RefOfLockingFuncName: - return "*LockingFunc:Name(Expr)" + return "(*LockingFunc).Name" case RefOfLockingFuncTimeout: - return "*LockingFunc:Timeout(Expr)" + return "(*LockingFunc).Timeout" case RefOfMatchExprColumns8: - return "*MatchExpr:Columns(*ColName)8" + return "(*MatchExpr).Columns8" case RefOfMatchExprColumns32: - return "*MatchExpr:Columns(*ColName)32" + return "(*MatchExpr).Columns32" case RefOfMatchExprExpr: - return "*MatchExpr:Expr(Expr)" + return "(*MatchExpr).Expr" case RefOfMaxArg: - return "*Max:Arg(Expr)" + return "(*Max).Arg" case RefOfMaxOverClause: - return "*Max:OverClause(*OverClause)" + return "(*Max).OverClause" case RefOfMemberOfExprValue: - return "*MemberOfExpr:Value(Expr)" + return "(*MemberOfExpr).Value" case RefOfMemberOfExprJSONArr: - return "*MemberOfExpr:JSONArr(Expr)" + return "(*MemberOfExpr).JSONArr" case RefOfMinArg: - return "*Min:Arg(Expr)" + return "(*Min).Arg" case RefOfMinOverClause: - return "*Min:OverClause(*OverClause)" + return "(*Min).OverClause" case RefOfModifyColumnNewColDefinition: - return "*ModifyColumn:NewColDefinition(*ColumnDefinition)" + return "(*ModifyColumn).NewColDefinition" case RefOfModifyColumnAfter: - return "*ModifyColumn:After(*ColName)" + return "(*ModifyColumn).After" case RefOfMultiLinestringExprLinestringParams: - return "*MultiLinestringExpr:LinestringParams(Exprs)" + return "(*MultiLinestringExpr).LinestringParams" case RefOfMultiPointExprPointParams: - return "*MultiPointExpr:PointParams(Exprs)" + return "(*MultiPointExpr).PointParams" case RefOfMultiPolygonExprPolygonParams: - return "*MultiPolygonExpr:PolygonParams(Exprs)" + return "(*MultiPolygonExpr).PolygonParams" case RefOfNTHValueExprExpr: - return "*NTHValueExpr:Expr(Expr)" + return "(*NTHValueExpr).Expr" case RefOfNTHValueExprN: - return "*NTHValueExpr:N(Expr)" + return "(*NTHValueExpr).N" case RefOfNTHValueExprOverClause: - return "*NTHValueExpr:OverClause(*OverClause)" + return "(*NTHValueExpr).OverClause" case RefOfNTHValueExprFromFirstLastClause: - return "*NTHValueExpr:FromFirstLastClause(*FromFirstLastClause)" + return "(*NTHValueExpr).FromFirstLastClause" case RefOfNTHValueExprNullTreatmentClause: - return "*NTHValueExpr:NullTreatmentClause(*NullTreatmentClause)" + return "(*NTHValueExpr).NullTreatmentClause" case RefOfNamedWindowWindows: - return "*NamedWindow:Windows(WindowDefinitions)" + return "(*NamedWindow).Windows" case NamedWindowsOffset8: - return "NamedWindows:Offset(NamedWindows)8" + return "(NamedWindows).Offset8" case NamedWindowsOffset32: - return "NamedWindows:Offset(NamedWindows)32" + return "(NamedWindows).Offset32" case RefOfNextvalExpr: - return "*Nextval:Expr(Expr)" + return "(*Nextval).Expr" case RefOfNotExprExpr: - return "*NotExpr:Expr(Expr)" + return "(*NotExpr).Expr" case RefOfNtileExprN: - return "*NtileExpr:N(Expr)" + return "(*NtileExpr).N" case RefOfNtileExprOverClause: - return "*NtileExpr:OverClause(*OverClause)" + return "(*NtileExpr).OverClause" case RefOfOffsetOriginal: - return "*Offset:Original(Expr)" + return "(*Offset).Original" case OnDupOffset8: - return "OnDup:Offset(OnDup)8" + return "(OnDup).Offset8" case OnDupOffset32: - return "OnDup:Offset(OnDup)32" + return "(OnDup).Offset32" case RefOfOptLikeLikeTable: - return "*OptLike:LikeTable(TableName)" + return "(*OptLike).LikeTable" case RefOfOrExprLeft: - return "*OrExpr:Left(Expr)" + return "(*OrExpr).Left" case RefOfOrExprRight: - return "*OrExpr:Right(Expr)" + return "(*OrExpr).Right" case RefOfOrderExpr: - return "*Order:Expr(Expr)" + return "(*Order).Expr" case OrderByOffset8: - return "OrderBy:Offset(OrderBy)8" + return "(OrderBy).Offset8" case OrderByOffset32: - return "OrderBy:Offset(OrderBy)32" + return "(OrderBy).Offset32" case RefOfOrderByOptionCols: - return "*OrderByOption:Cols(Columns)" + return "(*OrderByOption).Cols" case RefOfOverClauseWindowName: - return "*OverClause:WindowName(IdentifierCI)" + return "(*OverClause).WindowName" case RefOfOverClauseWindowSpec: - return "*OverClause:WindowSpec(*WindowSpecification)" + return "(*OverClause).WindowSpec" case RefOfParenTableExprExprs: - return "*ParenTableExpr:Exprs(TableExprs)" + return "(*ParenTableExpr).Exprs" case RefOfPartitionDefinitionName: - return "*PartitionDefinition:Name(IdentifierCI)" + return "(*PartitionDefinition).Name" case RefOfPartitionDefinitionOptions: - return "*PartitionDefinition:Options(*PartitionDefinitionOptions)" + return "(*PartitionDefinition).Options" case RefOfPartitionDefinitionOptionsValueRange: - return "*PartitionDefinitionOptions:ValueRange(*PartitionValueRange)" + return "(*PartitionDefinitionOptions).ValueRange" case RefOfPartitionDefinitionOptionsComment: - return "*PartitionDefinitionOptions:Comment(*Literal)" + return "(*PartitionDefinitionOptions).Comment" case RefOfPartitionDefinitionOptionsEngine: - return "*PartitionDefinitionOptions:Engine(*PartitionEngine)" + return "(*PartitionDefinitionOptions).Engine" case RefOfPartitionDefinitionOptionsDataDirectory: - return "*PartitionDefinitionOptions:DataDirectory(*Literal)" + return "(*PartitionDefinitionOptions).DataDirectory" case RefOfPartitionDefinitionOptionsIndexDirectory: - return "*PartitionDefinitionOptions:IndexDirectory(*Literal)" + return "(*PartitionDefinitionOptions).IndexDirectory" case RefOfPartitionDefinitionOptionsSubPartitionDefinitions: - return "*PartitionDefinitionOptions:SubPartitionDefinitions(SubPartitionDefinitions)" + return "(*PartitionDefinitionOptions).SubPartitionDefinitions" case RefOfPartitionOptionColList: - return "*PartitionOption:ColList(Columns)" + return "(*PartitionOption).ColList" case RefOfPartitionOptionExpr: - return "*PartitionOption:Expr(Expr)" + return "(*PartitionOption).Expr" case RefOfPartitionOptionSubPartition: - return "*PartitionOption:SubPartition(*SubPartition)" + return "(*PartitionOption).SubPartition" case RefOfPartitionOptionDefinitions8: - return "*PartitionOption:Definitions(*PartitionDefinition)8" + return "(*PartitionOption).Definitions8" case RefOfPartitionOptionDefinitions32: - return "*PartitionOption:Definitions(*PartitionDefinition)32" + return "(*PartitionOption).Definitions32" case RefOfPartitionSpecNames: - return "*PartitionSpec:Names(Partitions)" + return "(*PartitionSpec).Names" case RefOfPartitionSpecNumber: - return "*PartitionSpec:Number(*Literal)" + return "(*PartitionSpec).Number" case RefOfPartitionSpecTableName: - return "*PartitionSpec:TableName(TableName)" + return "(*PartitionSpec).TableName" case RefOfPartitionSpecDefinitions8: - return "*PartitionSpec:Definitions(*PartitionDefinition)8" + return "(*PartitionSpec).Definitions8" case RefOfPartitionSpecDefinitions32: - return "*PartitionSpec:Definitions(*PartitionDefinition)32" + return "(*PartitionSpec).Definitions32" case RefOfPartitionValueRangeRange: - return "*PartitionValueRange:Range(ValTuple)" + return "(*PartitionValueRange).Range" case PartitionsOffset8: - return "Partitions:Offset(Partitions)8" + return "(Partitions).Offset8" case PartitionsOffset32: - return "Partitions:Offset(Partitions)32" + return "(Partitions).Offset32" case RefOfPerformanceSchemaFuncExprArgument: - return "*PerformanceSchemaFuncExpr:Argument(Expr)" + return "(*PerformanceSchemaFuncExpr).Argument" case RefOfPointExprXCordinate: - return "*PointExpr:XCordinate(Expr)" + return "(*PointExpr).XCordinate" case RefOfPointExprYCordinate: - return "*PointExpr:YCordinate(Expr)" + return "(*PointExpr).YCordinate" case RefOfPointPropertyFuncExprPoint: - return "*PointPropertyFuncExpr:Point(Expr)" + return "(*PointPropertyFuncExpr).Point" case RefOfPointPropertyFuncExprValueToSet: - return "*PointPropertyFuncExpr:ValueToSet(Expr)" + return "(*PointPropertyFuncExpr).ValueToSet" case RefOfPolygonExprLinestringParams: - return "*PolygonExpr:LinestringParams(Exprs)" + return "(*PolygonExpr).LinestringParams" case RefOfPolygonPropertyFuncExprPolygon: - return "*PolygonPropertyFuncExpr:Polygon(Expr)" + return "(*PolygonPropertyFuncExpr).Polygon" case RefOfPolygonPropertyFuncExprPropertyDefArg: - return "*PolygonPropertyFuncExpr:PropertyDefArg(Expr)" + return "(*PolygonPropertyFuncExpr).PropertyDefArg" case RefOfPrepareStmtName: - return "*PrepareStmt:Name(IdentifierCI)" + return "(*PrepareStmt).Name" case RefOfPrepareStmtStatement: - return "*PrepareStmt:Statement(Expr)" + return "(*PrepareStmt).Statement" case RefOfPrepareStmtComments: - return "*PrepareStmt:Comments(*ParsedComments)" + return "(*PrepareStmt).Comments" case RefOfReferenceDefinitionReferencedTable: - return "*ReferenceDefinition:ReferencedTable(TableName)" + return "(*ReferenceDefinition).ReferencedTable" case RefOfReferenceDefinitionReferencedColumns: - return "*ReferenceDefinition:ReferencedColumns(Columns)" + return "(*ReferenceDefinition).ReferencedColumns" case RefOfReferenceDefinitionMatch: - return "*ReferenceDefinition:Match(MatchAction)" + return "(*ReferenceDefinition).Match" case RefOfReferenceDefinitionOnDelete: - return "*ReferenceDefinition:OnDelete(ReferenceAction)" + return "(*ReferenceDefinition).OnDelete" case RefOfReferenceDefinitionOnUpdate: - return "*ReferenceDefinition:OnUpdate(ReferenceAction)" + return "(*ReferenceDefinition).OnUpdate" case RefOfRegexpInstrExprExpr: - return "*RegexpInstrExpr:Expr(Expr)" + return "(*RegexpInstrExpr).Expr" case RefOfRegexpInstrExprPattern: - return "*RegexpInstrExpr:Pattern(Expr)" + return "(*RegexpInstrExpr).Pattern" case RefOfRegexpInstrExprPosition: - return "*RegexpInstrExpr:Position(Expr)" + return "(*RegexpInstrExpr).Position" case RefOfRegexpInstrExprOccurrence: - return "*RegexpInstrExpr:Occurrence(Expr)" + return "(*RegexpInstrExpr).Occurrence" case RefOfRegexpInstrExprReturnOption: - return "*RegexpInstrExpr:ReturnOption(Expr)" + return "(*RegexpInstrExpr).ReturnOption" case RefOfRegexpInstrExprMatchType: - return "*RegexpInstrExpr:MatchType(Expr)" + return "(*RegexpInstrExpr).MatchType" case RefOfRegexpLikeExprExpr: - return "*RegexpLikeExpr:Expr(Expr)" + return "(*RegexpLikeExpr).Expr" case RefOfRegexpLikeExprPattern: - return "*RegexpLikeExpr:Pattern(Expr)" + return "(*RegexpLikeExpr).Pattern" case RefOfRegexpLikeExprMatchType: - return "*RegexpLikeExpr:MatchType(Expr)" + return "(*RegexpLikeExpr).MatchType" case RefOfRegexpReplaceExprExpr: - return "*RegexpReplaceExpr:Expr(Expr)" + return "(*RegexpReplaceExpr).Expr" case RefOfRegexpReplaceExprPattern: - return "*RegexpReplaceExpr:Pattern(Expr)" + return "(*RegexpReplaceExpr).Pattern" case RefOfRegexpReplaceExprRepl: - return "*RegexpReplaceExpr:Repl(Expr)" + return "(*RegexpReplaceExpr).Repl" case RefOfRegexpReplaceExprOccurrence: - return "*RegexpReplaceExpr:Occurrence(Expr)" + return "(*RegexpReplaceExpr).Occurrence" case RefOfRegexpReplaceExprPosition: - return "*RegexpReplaceExpr:Position(Expr)" + return "(*RegexpReplaceExpr).Position" case RefOfRegexpReplaceExprMatchType: - return "*RegexpReplaceExpr:MatchType(Expr)" + return "(*RegexpReplaceExpr).MatchType" case RefOfRegexpSubstrExprExpr: - return "*RegexpSubstrExpr:Expr(Expr)" + return "(*RegexpSubstrExpr).Expr" case RefOfRegexpSubstrExprPattern: - return "*RegexpSubstrExpr:Pattern(Expr)" + return "(*RegexpSubstrExpr).Pattern" case RefOfRegexpSubstrExprOccurrence: - return "*RegexpSubstrExpr:Occurrence(Expr)" + return "(*RegexpSubstrExpr).Occurrence" case RefOfRegexpSubstrExprPosition: - return "*RegexpSubstrExpr:Position(Expr)" + return "(*RegexpSubstrExpr).Position" case RefOfRegexpSubstrExprMatchType: - return "*RegexpSubstrExpr:MatchType(Expr)" + return "(*RegexpSubstrExpr).MatchType" case RefOfReleaseName: - return "*Release:Name(IdentifierCI)" + return "(*Release).Name" case RefOfRenameColumnOldName: - return "*RenameColumn:OldName(*ColName)" + return "(*RenameColumn).OldName" case RefOfRenameColumnNewName: - return "*RenameColumn:NewName(*ColName)" + return "(*RenameColumn).NewName" case RefOfRenameIndexOldName: - return "*RenameIndex:OldName(IdentifierCI)" + return "(*RenameIndex).OldName" case RefOfRenameIndexNewName: - return "*RenameIndex:NewName(IdentifierCI)" + return "(*RenameIndex).NewName" case RefOfRenameTableNameTable: - return "*RenameTableName:Table(TableName)" + return "(*RenameTableName).Table" case RefOfRevertMigrationComments: - return "*RevertMigration:Comments(*ParsedComments)" + return "(*RevertMigration).Comments" case RootNodeSQLNode: - return "RootNode:SQLNode(SQLNode)" + return "(RootNode).SQLNode" case RefOfRowAliasTableName: - return "*RowAlias:TableName(IdentifierCS)" + return "(*RowAlias).TableName" case RefOfRowAliasColumns: - return "*RowAlias:Columns(Columns)" + return "(*RowAlias).Columns" case RefOfSRollbackName: - return "*SRollback:Name(IdentifierCI)" + return "(*SRollback).Name" case RefOfSavepointName: - return "*Savepoint:Name(IdentifierCI)" + return "(*Savepoint).Name" case RefOfSelectWith: - return "*Select:With(*With)" + return "(*Select).With" case RefOfSelectFrom8: - return "*Select:From(TableExpr)8" + return "(*Select).From8" case RefOfSelectFrom32: - return "*Select:From(TableExpr)32" + return "(*Select).From32" case RefOfSelectComments: - return "*Select:Comments(*ParsedComments)" + return "(*Select).Comments" case RefOfSelectSelectExprs: - return "*Select:SelectExprs(SelectExprs)" + return "(*Select).SelectExprs" case RefOfSelectWhere: - return "*Select:Where(*Where)" + return "(*Select).Where" case RefOfSelectGroupBy: - return "*Select:GroupBy(*GroupBy)" + return "(*Select).GroupBy" case RefOfSelectHaving: - return "*Select:Having(*Where)" + return "(*Select).Having" case RefOfSelectWindows: - return "*Select:Windows(NamedWindows)" + return "(*Select).Windows" case RefOfSelectOrderBy: - return "*Select:OrderBy(OrderBy)" + return "(*Select).OrderBy" case RefOfSelectLimit: - return "*Select:Limit(*Limit)" + return "(*Select).Limit" case RefOfSelectInto: - return "*Select:Into(*SelectInto)" + return "(*Select).Into" case SelectExprsOffset8: - return "SelectExprs:Offset(SelectExprs)8" + return "(SelectExprs).Offset8" case SelectExprsOffset32: - return "SelectExprs:Offset(SelectExprs)32" + return "(SelectExprs).Offset32" case RefOfSetComments: - return "*Set:Comments(*ParsedComments)" + return "(*Set).Comments" case RefOfSetExprs: - return "*Set:Exprs(SetExprs)" + return "(*Set).Exprs" case RefOfSetExprVar: - return "*SetExpr:Var(*Variable)" + return "(*SetExpr).Var" case RefOfSetExprExpr: - return "*SetExpr:Expr(Expr)" + return "(*SetExpr).Expr" case SetExprsOffset8: - return "SetExprs:Offset(SetExprs)8" + return "(SetExprs).Offset8" case SetExprsOffset32: - return "SetExprs:Offset(SetExprs)32" + return "(SetExprs).Offset32" case RefOfShowInternal: - return "*Show:Internal(ShowInternal)" + return "(*Show).Internal" case RefOfShowBasicTbl: - return "*ShowBasic:Tbl(TableName)" + return "(*ShowBasic).Tbl" case RefOfShowBasicDbName: - return "*ShowBasic:DbName(IdentifierCS)" + return "(*ShowBasic).DbName" case RefOfShowBasicFilter: - return "*ShowBasic:Filter(*ShowFilter)" + return "(*ShowBasic).Filter" case RefOfShowCreateOp: - return "*ShowCreate:Op(TableName)" + return "(*ShowCreate).Op" case RefOfShowFilterFilter: - return "*ShowFilter:Filter(Expr)" + return "(*ShowFilter).Filter" case RefOfShowMigrationLogsComments: - return "*ShowMigrationLogs:Comments(*ParsedComments)" + return "(*ShowMigrationLogs).Comments" case RefOfStarExprTableName: - return "*StarExpr:TableName(TableName)" + return "(*StarExpr).TableName" case RefOfStdArg: - return "*Std:Arg(Expr)" + return "(*Std).Arg" case RefOfStdOverClause: - return "*Std:OverClause(*OverClause)" + return "(*Std).OverClause" case RefOfStdDevArg: - return "*StdDev:Arg(Expr)" + return "(*StdDev).Arg" case RefOfStdDevOverClause: - return "*StdDev:OverClause(*OverClause)" + return "(*StdDev).OverClause" case RefOfStdPopArg: - return "*StdPop:Arg(Expr)" + return "(*StdPop).Arg" case RefOfStdPopOverClause: - return "*StdPop:OverClause(*OverClause)" + return "(*StdPop).OverClause" case RefOfStdSampArg: - return "*StdSamp:Arg(Expr)" + return "(*StdSamp).Arg" case RefOfStdSampOverClause: - return "*StdSamp:OverClause(*OverClause)" + return "(*StdSamp).OverClause" case RefOfStreamComments: - return "*Stream:Comments(*ParsedComments)" + return "(*Stream).Comments" case RefOfStreamSelectExpr: - return "*Stream:SelectExpr(SelectExpr)" + return "(*Stream).SelectExpr" case RefOfStreamTable: - return "*Stream:Table(TableName)" + return "(*Stream).Table" case RefOfSubPartitionColList: - return "*SubPartition:ColList(Columns)" + return "(*SubPartition).ColList" case RefOfSubPartitionExpr: - return "*SubPartition:Expr(Expr)" + return "(*SubPartition).Expr" case RefOfSubPartitionDefinitionName: - return "*SubPartitionDefinition:Name(IdentifierCI)" + return "(*SubPartitionDefinition).Name" case RefOfSubPartitionDefinitionOptions: - return "*SubPartitionDefinition:Options(*SubPartitionDefinitionOptions)" + return "(*SubPartitionDefinition).Options" case RefOfSubPartitionDefinitionOptionsComment: - return "*SubPartitionDefinitionOptions:Comment(*Literal)" + return "(*SubPartitionDefinitionOptions).Comment" case RefOfSubPartitionDefinitionOptionsEngine: - return "*SubPartitionDefinitionOptions:Engine(*PartitionEngine)" + return "(*SubPartitionDefinitionOptions).Engine" case RefOfSubPartitionDefinitionOptionsDataDirectory: - return "*SubPartitionDefinitionOptions:DataDirectory(*Literal)" + return "(*SubPartitionDefinitionOptions).DataDirectory" case RefOfSubPartitionDefinitionOptionsIndexDirectory: - return "*SubPartitionDefinitionOptions:IndexDirectory(*Literal)" + return "(*SubPartitionDefinitionOptions).IndexDirectory" case SubPartitionDefinitionsOffset8: - return "SubPartitionDefinitions:Offset(SubPartitionDefinitions)8" + return "(SubPartitionDefinitions).Offset8" case SubPartitionDefinitionsOffset32: - return "SubPartitionDefinitions:Offset(SubPartitionDefinitions)32" + return "(SubPartitionDefinitions).Offset32" case RefOfSubquerySelect: - return "*Subquery:Select(TableStatement)" + return "(*Subquery).Select" case RefOfSubstrExprName: - return "*SubstrExpr:Name(Expr)" + return "(*SubstrExpr).Name" case RefOfSubstrExprFrom: - return "*SubstrExpr:From(Expr)" + return "(*SubstrExpr).From" case RefOfSubstrExprTo: - return "*SubstrExpr:To(Expr)" + return "(*SubstrExpr).To" case RefOfSumArg: - return "*Sum:Arg(Expr)" + return "(*Sum).Arg" case RefOfSumOverClause: - return "*Sum:OverClause(*OverClause)" + return "(*Sum).OverClause" case TableExprsOffset8: - return "TableExprs:Offset(TableExprs)8" + return "(TableExprs).Offset8" case TableExprsOffset32: - return "TableExprs:Offset(TableExprs)32" + return "(TableExprs).Offset32" case TableNameName: - return "TableName:Name(IdentifierCS)" + return "(TableName).Name" case TableNameQualifier: - return "TableName:Qualifier(IdentifierCS)" + return "(TableName).Qualifier" case TableNamesOffset8: - return "TableNames:Offset(TableNames)8" + return "(TableNames).Offset8" case TableNamesOffset32: - return "TableNames:Offset(TableNames)32" + return "(TableNames).Offset32" case TableOptionsOffset8: - return "TableOptions:Offset(TableOptions)8" + return "(TableOptions).Offset8" case TableOptionsOffset32: - return "TableOptions:Offset(TableOptions)32" + return "(TableOptions).Offset32" case RefOfTableSpecColumns8: - return "*TableSpec:Columns(*ColumnDefinition)8" + return "(*TableSpec).Columns8" case RefOfTableSpecColumns32: - return "*TableSpec:Columns(*ColumnDefinition)32" + return "(*TableSpec).Columns32" case RefOfTableSpecIndexes8: - return "*TableSpec:Indexes(*IndexDefinition)8" + return "(*TableSpec).Indexes8" case RefOfTableSpecIndexes32: - return "*TableSpec:Indexes(*IndexDefinition)32" + return "(*TableSpec).Indexes32" case RefOfTableSpecConstraints8: - return "*TableSpec:Constraints(*ConstraintDefinition)8" + return "(*TableSpec).Constraints8" case RefOfTableSpecConstraints32: - return "*TableSpec:Constraints(*ConstraintDefinition)32" + return "(*TableSpec).Constraints32" case RefOfTableSpecOptions: - return "*TableSpec:Options(TableOptions)" + return "(*TableSpec).Options" case RefOfTableSpecPartitionOption: - return "*TableSpec:PartitionOption(*PartitionOption)" + return "(*TableSpec).PartitionOption" case RefOfTimestampDiffExprExpr1: - return "*TimestampDiffExpr:Expr1(Expr)" + return "(*TimestampDiffExpr).Expr1" case RefOfTimestampDiffExprExpr2: - return "*TimestampDiffExpr:Expr2(Expr)" + return "(*TimestampDiffExpr).Expr2" case RefOfTrimFuncExprTrimArg: - return "*TrimFuncExpr:TrimArg(Expr)" + return "(*TrimFuncExpr).TrimArg" case RefOfTrimFuncExprStringArg: - return "*TrimFuncExpr:StringArg(Expr)" + return "(*TrimFuncExpr).StringArg" case RefOfTruncateTableTable: - return "*TruncateTable:Table(TableName)" + return "(*TruncateTable).Table" case RefOfUnaryExprExpr: - return "*UnaryExpr:Expr(Expr)" + return "(*UnaryExpr).Expr" case RefOfUnionWith: - return "*Union:With(*With)" + return "(*Union).With" case RefOfUnionLeft: - return "*Union:Left(TableStatement)" + return "(*Union).Left" case RefOfUnionRight: - return "*Union:Right(TableStatement)" + return "(*Union).Right" case RefOfUnionOrderBy: - return "*Union:OrderBy(OrderBy)" + return "(*Union).OrderBy" case RefOfUnionLimit: - return "*Union:Limit(*Limit)" + return "(*Union).Limit" case RefOfUnionInto: - return "*Union:Into(*SelectInto)" + return "(*Union).Into" case RefOfUpdateWith: - return "*Update:With(*With)" + return "(*Update).With" case RefOfUpdateComments: - return "*Update:Comments(*ParsedComments)" + return "(*Update).Comments" case RefOfUpdateTableExprs8: - return "*Update:TableExprs(TableExpr)8" + return "(*Update).TableExprs8" case RefOfUpdateTableExprs32: - return "*Update:TableExprs(TableExpr)32" + return "(*Update).TableExprs32" case RefOfUpdateExprs: - return "*Update:Exprs(UpdateExprs)" + return "(*Update).Exprs" case RefOfUpdateWhere: - return "*Update:Where(*Where)" + return "(*Update).Where" case RefOfUpdateOrderBy: - return "*Update:OrderBy(OrderBy)" + return "(*Update).OrderBy" case RefOfUpdateLimit: - return "*Update:Limit(*Limit)" + return "(*Update).Limit" case RefOfUpdateExprName: - return "*UpdateExpr:Name(*ColName)" + return "(*UpdateExpr).Name" case RefOfUpdateExprExpr: - return "*UpdateExpr:Expr(Expr)" + return "(*UpdateExpr).Expr" case UpdateExprsOffset8: - return "UpdateExprs:Offset(UpdateExprs)8" + return "(UpdateExprs).Offset8" case UpdateExprsOffset32: - return "UpdateExprs:Offset(UpdateExprs)32" + return "(UpdateExprs).Offset32" case RefOfUpdateXMLExprTarget: - return "*UpdateXMLExpr:Target(Expr)" + return "(*UpdateXMLExpr).Target" case RefOfUpdateXMLExprXPathExpr: - return "*UpdateXMLExpr:XPathExpr(Expr)" + return "(*UpdateXMLExpr).XPathExpr" case RefOfUpdateXMLExprNewXML: - return "*UpdateXMLExpr:NewXML(Expr)" + return "(*UpdateXMLExpr).NewXML" case RefOfUseDBName: - return "*Use:DBName(IdentifierCS)" + return "(*Use).DBName" case RefOfVExplainStmtStatement: - return "*VExplainStmt:Statement(Statement)" + return "(*VExplainStmt).Statement" case RefOfVExplainStmtComments: - return "*VExplainStmt:Comments(*ParsedComments)" + return "(*VExplainStmt).Comments" case RefOfVStreamComments: - return "*VStream:Comments(*ParsedComments)" + return "(*VStream).Comments" case RefOfVStreamSelectExpr: - return "*VStream:SelectExpr(SelectExpr)" + return "(*VStream).SelectExpr" case RefOfVStreamTable: - return "*VStream:Table(TableName)" + return "(*VStream).Table" case RefOfVStreamWhere: - return "*VStream:Where(*Where)" + return "(*VStream).Where" case RefOfVStreamLimit: - return "*VStream:Limit(*Limit)" + return "(*VStream).Limit" case ValTupleOffset8: - return "ValTuple:Offset(ValTuple)8" + return "(ValTuple).Offset8" case ValTupleOffset32: - return "ValTuple:Offset(ValTuple)32" + return "(ValTuple).Offset32" case ValuesOffset8: - return "Values:Offset(Values)8" + return "(Values).Offset8" case ValuesOffset32: - return "Values:Offset(Values)32" + return "(Values).Offset32" case RefOfValuesFuncExprName: - return "*ValuesFuncExpr:Name(*ColName)" + return "(*ValuesFuncExpr).Name" case RefOfValuesStatementWith: - return "*ValuesStatement:With(*With)" + return "(*ValuesStatement).With" case RefOfValuesStatementRows: - return "*ValuesStatement:Rows(Values)" + return "(*ValuesStatement).Rows" case RefOfValuesStatementListArg: - return "*ValuesStatement:ListArg(ListArg)" + return "(*ValuesStatement).ListArg" case RefOfValuesStatementComments: - return "*ValuesStatement:Comments(*ParsedComments)" + return "(*ValuesStatement).Comments" case RefOfValuesStatementOrder: - return "*ValuesStatement:Order(OrderBy)" + return "(*ValuesStatement).Order" case RefOfValuesStatementLimit: - return "*ValuesStatement:Limit(*Limit)" + return "(*ValuesStatement).Limit" case RefOfVarPopArg: - return "*VarPop:Arg(Expr)" + return "(*VarPop).Arg" case RefOfVarPopOverClause: - return "*VarPop:OverClause(*OverClause)" + return "(*VarPop).OverClause" case RefOfVarSampArg: - return "*VarSamp:Arg(Expr)" + return "(*VarSamp).Arg" case RefOfVarSampOverClause: - return "*VarSamp:OverClause(*OverClause)" + return "(*VarSamp).OverClause" case RefOfVariableName: - return "*Variable:Name(IdentifierCI)" + return "(*Variable).Name" case RefOfVarianceArg: - return "*Variance:Arg(Expr)" + return "(*Variance).Arg" case RefOfVarianceOverClause: - return "*Variance:OverClause(*OverClause)" + return "(*Variance).OverClause" case VindexParamKey: - return "VindexParam:Key(IdentifierCI)" + return "(VindexParam).Key" case RefOfVindexSpecName: - return "*VindexSpec:Name(IdentifierCI)" + return "(*VindexSpec).Name" case RefOfVindexSpecType: - return "*VindexSpec:Type(IdentifierCI)" + return "(*VindexSpec).Type" case RefOfVindexSpecParams8: - return "*VindexSpec:Params(VindexParam)8" + return "(*VindexSpec).Params8" case RefOfVindexSpecParams32: - return "*VindexSpec:Params(VindexParam)32" + return "(*VindexSpec).Params32" case RefOfWeightStringFuncExprExpr: - return "*WeightStringFuncExpr:Expr(Expr)" + return "(*WeightStringFuncExpr).Expr" case RefOfWeightStringFuncExprAs: - return "*WeightStringFuncExpr:As(*ConvertType)" + return "(*WeightStringFuncExpr).As" case RefOfWhenCond: - return "*When:Cond(Expr)" + return "(*When).Cond" case RefOfWhenVal: - return "*When:Val(Expr)" + return "(*When).Val" case RefOfWhereExpr: - return "*Where:Expr(Expr)" + return "(*Where).Expr" case RefOfWindowDefinitionName: - return "*WindowDefinition:Name(IdentifierCI)" + return "(*WindowDefinition).Name" case RefOfWindowDefinitionWindowSpec: - return "*WindowDefinition:WindowSpec(*WindowSpecification)" + return "(*WindowDefinition).WindowSpec" case WindowDefinitionsOffset8: - return "WindowDefinitions:Offset(WindowDefinitions)8" + return "(WindowDefinitions).Offset8" case WindowDefinitionsOffset32: - return "WindowDefinitions:Offset(WindowDefinitions)32" + return "(WindowDefinitions).Offset32" case RefOfWindowSpecificationName: - return "*WindowSpecification:Name(IdentifierCI)" + return "(*WindowSpecification).Name" case RefOfWindowSpecificationPartitionClause: - return "*WindowSpecification:PartitionClause(Exprs)" + return "(*WindowSpecification).PartitionClause" case RefOfWindowSpecificationOrderClause: - return "*WindowSpecification:OrderClause(OrderBy)" + return "(*WindowSpecification).OrderClause" case RefOfWindowSpecificationFrameClause: - return "*WindowSpecification:FrameClause(*FrameClause)" + return "(*WindowSpecification).FrameClause" case RefOfWithCTEs8: - return "*With:CTEs(*CommonTableExpr)8" + return "(*With).CTEs8" case RefOfWithCTEs32: - return "*With:CTEs(*CommonTableExpr)32" + return "(*With).CTEs32" case RefOfXorExprLeft: - return "*XorExpr:Left(Expr)" + return "(*XorExpr).Left" case RefOfXorExprRight: - return "*XorExpr:Right(Expr)" + return "(*XorExpr).Right" case SliceOfRefOfColumnDefinitionOffset8: - return "[]*ColumnDefinition:Offset([]*ColumnDefinition)8" + return "([]*ColumnDefinition).Offset8" case SliceOfRefOfColumnDefinitionOffset32: - return "[]*ColumnDefinition:Offset([]*ColumnDefinition)32" + return "([]*ColumnDefinition).Offset32" case SliceOfDatabaseOptionOffset8: - return "[]DatabaseOption:Offset([]DatabaseOption)8" + return "([]DatabaseOption).Offset8" case SliceOfDatabaseOptionOffset32: - return "[]DatabaseOption:Offset([]DatabaseOption)32" + return "([]DatabaseOption).Offset32" case SliceOfAlterOptionOffset8: - return "[]AlterOption:Offset([]AlterOption)8" + return "([]AlterOption).Offset8" case SliceOfAlterOptionOffset32: - return "[]AlterOption:Offset([]AlterOption)32" + return "([]AlterOption).Offset32" case SliceOfIdentifierCIOffset8: - return "[]IdentifierCI:Offset([]IdentifierCI)8" + return "([]IdentifierCI).Offset8" case SliceOfIdentifierCIOffset32: - return "[]IdentifierCI:Offset([]IdentifierCI)32" + return "([]IdentifierCI).Offset32" case SliceOfTxAccessModeOffset8: - return "[]TxAccessMode:Offset([]TxAccessMode)8" + return "([]TxAccessMode).Offset8" case SliceOfTxAccessModeOffset32: - return "[]TxAccessMode:Offset([]TxAccessMode)32" + return "([]TxAccessMode).Offset32" case SliceOfRefOfWhenOffset8: - return "[]*When:Offset([]*When)8" + return "([]*When).Offset8" case SliceOfRefOfWhenOffset32: - return "[]*When:Offset([]*When)32" + return "([]*When).Offset32" case RefOfColumnTypeOptionsDefault: - return "*ColumnTypeOptions:Default(Expr)" + return "(*ColumnTypeOptions).Default" case RefOfColumnTypeOptionsOnUpdate: - return "*ColumnTypeOptions:OnUpdate(Expr)" + return "(*ColumnTypeOptions).OnUpdate" case RefOfColumnTypeOptionsAs: - return "*ColumnTypeOptions:As(Expr)" + return "(*ColumnTypeOptions).As" case RefOfColumnTypeOptionsComment: - return "*ColumnTypeOptions:Comment(*Literal)" + return "(*ColumnTypeOptions).Comment" case RefOfColumnTypeOptionsReference: - return "*ColumnTypeOptions:Reference(*ReferenceDefinition)" + return "(*ColumnTypeOptions).Reference" case RefOfColumnTypeOptionsEngineAttribute: - return "*ColumnTypeOptions:EngineAttribute(*Literal)" + return "(*ColumnTypeOptions).EngineAttribute" case RefOfColumnTypeOptionsSecondaryEngineAttribute: - return "*ColumnTypeOptions:SecondaryEngineAttribute(*Literal)" + return "(*ColumnTypeOptions).SecondaryEngineAttribute" case RefOfColumnTypeOptionsSRID: - return "*ColumnTypeOptions:SRID(*Literal)" + return "(*ColumnTypeOptions).SRID" case SliceOfStringOffset8: - return "[]string:Offset([]string)8" + return "([]string).Offset8" case SliceOfStringOffset32: - return "[]string:Offset([]string)32" + return "([]string).Offset32" case SliceOfTableExprOffset8: - return "[]TableExpr:Offset([]TableExpr)8" + return "([]TableExpr).Offset8" case SliceOfTableExprOffset32: - return "[]TableExpr:Offset([]TableExpr)32" + return "([]TableExpr).Offset32" case SliceOfRefOfVariableOffset8: - return "[]*Variable:Offset([]*Variable)8" + return "([]*Variable).Offset8" case SliceOfRefOfVariableOffset32: - return "[]*Variable:Offset([]*Variable)32" + return "([]*Variable).Offset32" case SliceOfExprOffset8: - return "[]Expr:Offset([]Expr)8" + return "([]Expr).Offset8" case SliceOfExprOffset32: - return "[]Expr:Offset([]Expr)32" + return "([]Expr).Offset32" case SliceOfRefOfIndexColumnOffset8: - return "[]*IndexColumn:Offset([]*IndexColumn)8" + return "([]*IndexColumn).Offset8" case SliceOfRefOfIndexColumnOffset32: - return "[]*IndexColumn:Offset([]*IndexColumn)32" + return "([]*IndexColumn).Offset32" case SliceOfRefOfIndexOptionOffset8: - return "[]*IndexOption:Offset([]*IndexOption)8" + return "([]*IndexOption).Offset8" case SliceOfRefOfIndexOptionOffset32: - return "[]*IndexOption:Offset([]*IndexOption)32" + return "([]*IndexOption).Offset32" case SliceOfRefOfJSONObjectParamOffset8: - return "[]*JSONObjectParam:Offset([]*JSONObjectParam)8" + return "([]*JSONObjectParam).Offset8" case SliceOfRefOfJSONObjectParamOffset32: - return "[]*JSONObjectParam:Offset([]*JSONObjectParam)32" + return "([]*JSONObjectParam).Offset32" case SliceOfRefOfJtColumnDefinitionOffset8: - return "[]*JtColumnDefinition:Offset([]*JtColumnDefinition)8" + return "([]*JtColumnDefinition).Offset8" case SliceOfRefOfJtColumnDefinitionOffset32: - return "[]*JtColumnDefinition:Offset([]*JtColumnDefinition)32" + return "([]*JtColumnDefinition).Offset32" case RefOfJtOrdinalColDefName: - return "*JtOrdinalColDef:Name(IdentifierCI)" + return "(*JtOrdinalColDef).Name" case RefOfJtPathColDefName: - return "*JtPathColDef:Name(IdentifierCI)" + return "(*JtPathColDef).Name" case RefOfJtPathColDefType: - return "*JtPathColDef:Type(*ColumnType)" + return "(*JtPathColDef).Type" case RefOfJtPathColDefPath: - return "*JtPathColDef:Path(Expr)" + return "(*JtPathColDef).Path" case RefOfJtPathColDefEmptyOnResponse: - return "*JtPathColDef:EmptyOnResponse(*JtOnResponse)" + return "(*JtPathColDef).EmptyOnResponse" case RefOfJtPathColDefErrorOnResponse: - return "*JtPathColDef:ErrorOnResponse(*JtOnResponse)" + return "(*JtPathColDef).ErrorOnResponse" case RefOfJtNestedPathColDefPath: - return "*JtNestedPathColDef:Path(Expr)" + return "(*JtNestedPathColDef).Path" case RefOfJtNestedPathColDefColumns8: - return "*JtNestedPathColDef:Columns(*JtColumnDefinition)8" + return "(*JtNestedPathColDef).Columns8" case RefOfJtNestedPathColDefColumns32: - return "*JtNestedPathColDef:Columns(*JtColumnDefinition)32" + return "(*JtNestedPathColDef).Columns32" case TableAndLockTypesOffset8: - return "TableAndLockTypes:Offset(TableAndLockTypes)8" + return "(TableAndLockTypes).Offset8" case TableAndLockTypesOffset32: - return "TableAndLockTypes:Offset(TableAndLockTypes)32" + return "(TableAndLockTypes).Offset32" case SliceOfRefOfColNameOffset8: - return "[]*ColName:Offset([]*ColName)8" + return "([]*ColName).Offset8" case SliceOfRefOfColNameOffset32: - return "[]*ColName:Offset([]*ColName)32" + return "([]*ColName).Offset32" case CommentsOffset8: - return "Comments:Offset(Comments)8" + return "(Comments).Offset8" case CommentsOffset32: - return "Comments:Offset(Comments)32" + return "(Comments).Offset32" case SliceOfRefOfPartitionDefinitionOffset8: - return "[]*PartitionDefinition:Offset([]*PartitionDefinition)8" + return "([]*PartitionDefinition).Offset8" case SliceOfRefOfPartitionDefinitionOffset32: - return "[]*PartitionDefinition:Offset([]*PartitionDefinition)32" + return "([]*PartitionDefinition).Offset32" case SliceOfRefOfRenameTablePairOffset8: - return "[]*RenameTablePair:Offset([]*RenameTablePair)8" + return "([]*RenameTablePair).Offset8" case SliceOfRefOfRenameTablePairOffset32: - return "[]*RenameTablePair:Offset([]*RenameTablePair)32" + return "([]*RenameTablePair).Offset32" case RefOfRootNodeSQLNode: - return "*RootNode:SQLNode(SQLNode)" + return "(*RootNode).SQLNode" case RefOfTableNameName: - return "*TableName:Name(IdentifierCS)" + return "(*TableName).Name" case RefOfTableNameQualifier: - return "*TableName:Qualifier(IdentifierCS)" + return "(*TableName).Qualifier" case RefOfTableOptionValue: - return "*TableOption:Value(*Literal)" + return "(*TableOption).Value" case RefOfTableOptionTables: - return "*TableOption:Tables(TableNames)" + return "(*TableOption).Tables" case SliceOfRefOfIndexDefinitionOffset8: - return "[]*IndexDefinition:Offset([]*IndexDefinition)8" + return "([]*IndexDefinition).Offset8" case SliceOfRefOfIndexDefinitionOffset32: - return "[]*IndexDefinition:Offset([]*IndexDefinition)32" + return "([]*IndexDefinition).Offset32" case SliceOfRefOfConstraintDefinitionOffset8: - return "[]*ConstraintDefinition:Offset([]*ConstraintDefinition)8" + return "([]*ConstraintDefinition).Offset8" case SliceOfRefOfConstraintDefinitionOffset32: - return "[]*ConstraintDefinition:Offset([]*ConstraintDefinition)32" + return "([]*ConstraintDefinition).Offset32" case RefOfVindexParamKey: - return "*VindexParam:Key(IdentifierCI)" + return "(*VindexParam).Key" case SliceOfVindexParamOffset8: - return "[]VindexParam:Offset([]VindexParam)8" + return "([]VindexParam).Offset8" case SliceOfVindexParamOffset32: - return "[]VindexParam:Offset([]VindexParam)32" + return "([]VindexParam).Offset32" case SliceOfRefOfCommonTableExprOffset8: - return "[]*CommonTableExpr:Offset([]*CommonTableExpr)8" + return "([]*CommonTableExpr).Offset8" case SliceOfRefOfCommonTableExprOffset32: - return "[]*CommonTableExpr:Offset([]*CommonTableExpr)32" + return "([]*CommonTableExpr).Offset32" case RefOfIndexColumnColumn: - return "*IndexColumn:Column(IdentifierCI)" + return "(*IndexColumn).Column" case RefOfIndexColumnExpression: - return "*IndexColumn:Expression(Expr)" + return "(*IndexColumn).Expression" case RefOfIndexOptionValue: - return "*IndexOption:Value(*Literal)" + return "(*IndexOption).Value" case RefOfTableAndLockTypeTable: - return "*TableAndLockType:Table(TableExpr)" + return "(*TableAndLockType).Table" case RefOfRenameTablePairFromTable: - return "*RenameTablePair:FromTable(TableName)" + return "(*RenameTablePair).FromTable" case RefOfRenameTablePairToTable: - return "*RenameTablePair:ToTable(TableName)" + return "(*RenameTablePair).ToTable" } panic("unknown ASTStep") } diff --git a/go/vt/sqlparser/paths.go b/go/vt/sqlparser/paths.go index 1a6e4af4493..332109b2b16 100644 --- a/go/vt/sqlparser/paths.go +++ b/go/vt/sqlparser/paths.go @@ -16,7 +16,11 @@ limitations under the License. package sqlparser -import "encoding/binary" +import ( + "encoding/binary" + "fmt" + "strings" +) // ASTPath is stored as a string. // Each 2 bytes => one step (big-endian). @@ -47,5 +51,57 @@ func AddStepWithSliceIndex(path ASTPath, step ASTStep, idx int) ASTPath { return path + ASTPath(b) } -// func (p ASTPath) DebugString() string { -// } +func (path ASTPath) DebugString() string { + var sb strings.Builder + + remaining := []byte(path) + stepCount := 0 + + for len(remaining) >= 2 { + // Read the step code (2 bytes) + stepVal := binary.BigEndian.Uint16(remaining[:2]) + remaining = remaining[2:] + + step := ASTStep(stepVal) + stepStr := step.DebugString() // e.g. "CaseExprWhens8" or "CaseExprWhens32" + + // If this isn't the very first step in the path, prepend a separator + if stepCount > 0 { + sb.WriteString("->") + } + stepCount++ + + // Write the step name + sb.WriteString(stepStr) + + // Check suffix to see if we need to read an offset + switch { + // 1-byte offset if stepStr ends with "8" + case strings.HasSuffix(stepStr, "8"): + if len(remaining) < 1 { + sb.WriteString("(ERR-no-offset-byte)") + return sb.String() + } + offsetByte := remaining[0] + remaining = remaining[1:] + sb.WriteString(fmt.Sprintf("(%d)", offsetByte)) + + // 4-byte offset if stepStr ends with "32" + case strings.HasSuffix(stepStr, "32"): + if len(remaining) < 4 { + sb.WriteString("(ERR-no-offset-uint32)") + return sb.String() + } + offsetVal := binary.BigEndian.Uint32(remaining[:4]) + remaining = remaining[4:] + sb.WriteString(fmt.Sprintf("(%d)", offsetVal)) + } + } + + // If there's leftover data that doesn't fit into 2 (or more) bytes, you could note it: + if len(remaining) != 0 { + sb.WriteString("->(ERR-unaligned-extra-bytes)") + } + + return sb.String() +} diff --git a/go/vt/sqlparser/paths_test.go b/go/vt/sqlparser/paths_test.go new file mode 100644 index 00000000000..75e537c3c15 --- /dev/null +++ b/go/vt/sqlparser/paths_test.go @@ -0,0 +1,34 @@ +/* +Copyright 2025 The Vitess Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package sqlparser + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestASTPathDebugString(t *testing.T) { + p := ASTPath("") + p = AddStep(p, RefOfSelectWhere) + p = AddStep(p, RefOfWhereExpr) + p = AddStep(p, RefOfBinaryExprLeft) + p = AddStep(p, RefOfFuncExprExprs) + p = AddStepWithSliceIndex(p, ExprsOffset8, 10) + expected := "(*Select).Where->(*Where).Expr->(*BinaryExpr).Left->(*FuncExpr).Exprs->(Exprs).Offset8(10)" + assert.Equal(t, expected, p.DebugString()) +} From 278a052c964d1beb574febd8de87992209bc86db Mon Sep 17 00:00:00 2001 From: Andres Taylor Date: Wed, 29 Jan 2025 17:56:07 +0100 Subject: [PATCH 06/13] wip --- bench.conf | 5 + go/tools/asthelpergen/asthelpergen_test.go | 2 +- .../asthelpergen/integration/ast_rewrite.go | 59 + go/tools/asthelpergen/integration/paths.go | 47 + .../asthelpergen/integration/test_helpers.go | 1 + go/tools/asthelpergen/integration/types.go | 5 +- go/tools/asthelpergen/rewrite_gen.go | 60 +- go/vt/sqlparser/ast_rewrite.go | 2397 +++++++++++++++++ go/vt/sqlparser/rewriter_api.go | 6 +- 9 files changed, 2556 insertions(+), 26 deletions(-) create mode 100644 bench.conf create mode 100644 go/tools/asthelpergen/integration/paths.go diff --git a/bench.conf b/bench.conf new file mode 100644 index 00000000000..74a2c8008c8 --- /dev/null +++ b/bench.conf @@ -0,0 +1,5 @@ +BENCH_PCKG=./go/vt/vtgate/planbuilder +BENCH_REGEX=Benchmark +BENCH_DIR=../benchmarks +BENCH_TIME=2s +BENCH_COUNT=6 \ No newline at end of file diff --git a/go/tools/asthelpergen/asthelpergen_test.go b/go/tools/asthelpergen/asthelpergen_test.go index f1f52b5b9c0..21774187abe 100644 --- a/go/tools/asthelpergen/asthelpergen_test.go +++ b/go/tools/asthelpergen/asthelpergen_test.go @@ -49,7 +49,7 @@ func TestFullGeneration(t *testing.T) { } func TestRecreateAllFiles(t *testing.T) { - t.Skip("This test recreates all files in the integration directory. It should only be run when the ASTHelperGen code has changed.") + // t.Skip("This test recreates all files in the integration directory. It should only be run when the ASTHelperGen code has changed.") result, err := GenerateASTHelpers(&Options{ Packages: []string{"./integration/..."}, RootInterface: "vitess.io/vitess/go/tools/asthelpergen/integration.AST", diff --git a/go/tools/asthelpergen/integration/ast_rewrite.go b/go/tools/asthelpergen/integration/ast_rewrite.go index 11f6e5bfb33..d4283711792 100644 --- a/go/tools/asthelpergen/integration/ast_rewrite.go +++ b/go/tools/asthelpergen/integration/ast_rewrite.go @@ -236,16 +236,27 @@ func (a *application) rewriteRefOfRefContainer(parent AST, node *RefContainer, r return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfRefContainerASTType) + } if !a.rewriteAST(node, node.ASTType, func(newNode, parent AST) { parent.(*RefContainer).ASTType = newNode.(AST) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfRefContainerASTImplementationType) + } if !a.rewriteRefOfLeaf(node, node.ASTImplementationType, func(newNode, parent AST) { parent.(*RefContainer).ASTImplementationType = newNode.(*Leaf) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -268,6 +279,7 @@ func (a *application) rewriteRefOfRefSliceContainer(parent AST, node *RefSliceCo return true } } + var path ASTPath for x, el := range node.ASTElements { if !a.rewriteAST(node, el, func(idx int) replacerFunc { return func(newNode, parent AST) { @@ -286,6 +298,9 @@ func (a *application) rewriteRefOfRefSliceContainer(parent AST, node *RefSliceCo return false } } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -308,11 +323,19 @@ func (a *application) rewriteRefOfSubImpl(parent AST, node *SubImpl, replacer re return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfSubImplinner) + } if !a.rewriteSubIface(node, node.inner, func(newNode, parent AST) { parent.(*SubImpl).inner = newNode.(SubIface) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -332,16 +355,27 @@ func (a *application) rewriteValueContainer(parent AST, node ValueContainer, rep return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, ValueContainerASTType) + } if !a.rewriteAST(node, node.ASTType, func(newNode, parent AST) { panic("[BUG] tried to replace 'ASTType' on 'ValueContainer'") }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, ValueContainerASTImplementationType) + } if !a.rewriteRefOfLeaf(node, node.ASTImplementationType, func(newNode, parent AST) { panic("[BUG] tried to replace 'ASTImplementationType' on 'ValueContainer'") }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -361,6 +395,7 @@ func (a *application) rewriteValueSliceContainer(parent AST, node ValueSliceCont return true } } + var path ASTPath for _, el := range node.ASTElements { if !a.rewriteAST(node, el, func(newNode, parent AST) { panic("[BUG] tried to replace 'ASTElements' on 'ValueSliceContainer'") @@ -368,11 +403,17 @@ func (a *application) rewriteValueSliceContainer(parent AST, node ValueSliceCont return false } } + if a.collectPaths { + a.cur.current = AddStep(path, ValueSliceContainerASTImplementationElements) + } if !a.rewriteLeafSlice(node, node.ASTImplementationElements, func(newNode, parent AST) { panic("[BUG] tried to replace 'ASTImplementationElements' on 'ValueSliceContainer'") }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -452,16 +493,27 @@ func (a *application) rewriteRefOfValueContainer(parent AST, node *ValueContaine return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfValueContainerASTType) + } if !a.rewriteAST(node, node.ASTType, func(newNode, parent AST) { parent.(*ValueContainer).ASTType = newNode.(AST) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfValueContainerASTImplementationType) + } if !a.rewriteRefOfLeaf(node, node.ASTImplementationType, func(newNode, parent AST) { parent.(*ValueContainer).ASTImplementationType = newNode.(*Leaf) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -484,6 +536,7 @@ func (a *application) rewriteRefOfValueSliceContainer(parent AST, node *ValueSli return true } } + var path ASTPath for x, el := range node.ASTElements { if !a.rewriteAST(node, el, func(idx int) replacerFunc { return func(newNode, parent AST) { @@ -493,11 +546,17 @@ func (a *application) rewriteRefOfValueSliceContainer(parent AST, node *ValueSli return false } } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfValueSliceContainerASTImplementationElements) + } if !a.rewriteLeafSlice(node, node.ASTImplementationElements, func(newNode, parent AST) { parent.(*ValueSliceContainer).ASTImplementationElements = newNode.(LeafSlice) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent diff --git a/go/tools/asthelpergen/integration/paths.go b/go/tools/asthelpergen/integration/paths.go new file mode 100644 index 00000000000..7a1fe0ed488 --- /dev/null +++ b/go/tools/asthelpergen/integration/paths.go @@ -0,0 +1,47 @@ +/* +Copyright 2025 The Vitess Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package integration + +import "encoding/binary" + +// This file is a copy of the file go/vt/sqlparser/paths.go +// We need it here to be able to test the path accumulation of the rewriter + +type ASTPath string + +func AddStep(path ASTPath, step ASTStep) ASTPath { + b := make([]byte, 2) + binary.BigEndian.PutUint16(b, uint16(step)) + return path + ASTPath(b) +} + +func AddStepWithSliceIndex(path ASTPath, step ASTStep, idx int) ASTPath { + if idx < 255 { + // 2 bytes for step code + 1 byte for index + b := make([]byte, 3) + binary.BigEndian.PutUint16(b[:2], uint16(step)) + b[2] = byte(idx) + return path + ASTPath(b) + } + + // 2 bytes for step code + 4 byte for index + b := make([]byte, 6) + longStep := step + 1 + binary.BigEndian.PutUint16(b[:2], uint16(longStep)) + binary.BigEndian.PutUint32(b[2:], uint32(idx)) + return path + ASTPath(b) +} diff --git a/go/tools/asthelpergen/integration/test_helpers.go b/go/tools/asthelpergen/integration/test_helpers.go index 67745f19687..64278f3c357 100644 --- a/go/tools/asthelpergen/integration/test_helpers.go +++ b/go/tools/asthelpergen/integration/test_helpers.go @@ -49,6 +49,7 @@ type Cursor struct { node AST // marks that the node has been replaced, and the new node should be visited revisit bool + current ASTPath } // Node returns the current Node. diff --git a/go/tools/asthelpergen/integration/types.go b/go/tools/asthelpergen/integration/types.go index 3e8fef6f81d..c090a1af327 100644 --- a/go/tools/asthelpergen/integration/types.go +++ b/go/tools/asthelpergen/integration/types.go @@ -160,8 +160,9 @@ func (r *NoCloneType) String() string { type Visit func(node AST) (bool, error) type application struct { - pre, post ApplyFunc - cur Cursor + pre, post ApplyFunc + cur Cursor + collectPaths bool } var Equals = &Comparator{} diff --git a/go/tools/asthelpergen/rewrite_gen.go b/go/tools/asthelpergen/rewrite_gen.go index cc8b18a78e9..951188e0a4e 100644 --- a/go/tools/asthelpergen/rewrite_gen.go +++ b/go/tools/asthelpergen/rewrite_gen.go @@ -102,18 +102,30 @@ func (r *rewriteGen) interfaceMethod(t types.Type, iface *types.Interface, spi g return nil } -func (r *rewriteGen) structMethod(t types.Type, strct *types.Struct, spi generatorSPI) error { - if !shouldAdd(t, spi.iface()) { - return nil +func (r *rewriteGen) visitStructFields(t types.Type, strct *types.Struct, spi generatorSPI, fail bool) (stmts []jen.Code) { + fields := r.rewriteAllStructFields(t, strct, spi, fail) + stmts = append(stmts, r.executePre(t)) + hasFields := len(fields) > 0 + if hasFields { + stmts = append(stmts, jen.Var().Id("path").Id("ASTPath")) } - fields := r.rewriteAllStructFields(t, strct, spi, true) - - stmts := []jen.Code{r.executePre(t)} stmts = append(stmts, fields...) + if hasFields { + stmts = append(stmts, jen.If(jen.Id("a.collectPaths").Block( + jen.Id("a.cur.current").Op("=").Id("path"), + ))) + } stmts = append(stmts, executePost(len(fields) > 0)) stmts = append(stmts, returnTrue()) + return +} - r.rewriteFunc(t, stmts) +func (r *rewriteGen) structMethod(t types.Type, strct *types.Struct, spi generatorSPI) error { + if !shouldAdd(t, spi.iface()) { + return nil + } + + r.rewriteFunc(t, r.visitStructFields(t, strct, spi, true)) return nil } @@ -127,17 +139,7 @@ func (r *rewriteGen) ptrToStructMethod(t types.Type, strct *types.Struct, spi ge if node == nil { return nil } */ stmts := []jen.Code{jen.If(jen.Id("node == nil").Block(returnTrue()))} - - /* - if !pre(&cur) { - return nil - } - */ - stmts = append(stmts, r.executePre(t)) - fields := r.rewriteAllStructFields(t, strct, spi, false) - stmts = append(stmts, fields...) - stmts = append(stmts, executePost(len(fields) > 0)) - stmts = append(stmts, returnTrue()) + stmts = append(stmts, r.visitStructFields(t, strct, spi, false)...) r.rewriteFunc(t, stmts) @@ -300,7 +302,8 @@ func (r *rewriteGen) rewriteAllStructFields(t types.Type, strct *types.Struct, s field := strct.Field(i) if types.Implements(field.Type(), spi.iface()) { spi.addType(field.Type()) - output = append(output, r.rewriteChild(t, field.Type(), field.Name(), jen.Id("node").Dot(field.Name()), jen.Dot(field.Name()), fail)) + rewriteLines := r.rewriteChild(t, field.Type(), field.Name(), jen.Id("node").Dot(field.Name()), jen.Dot(field.Name()), fail, i) + output = append(output, rewriteLines...) continue } slice, isSlice := field.Type().(*types.Slice) @@ -323,7 +326,7 @@ func failReplacer(t types.Type, f string) *jen.Statement { return jen.Panic(jen.Lit(fmt.Sprintf("[BUG] tried to replace '%s' on '%s'", f, typeString))) } -func (r *rewriteGen) rewriteChild(t, field types.Type, fieldName string, param jen.Code, replace jen.Code, fail bool) jen.Code { +func (r *rewriteGen) rewriteChild(t, field types.Type, fieldName string, param jen.Code, replace jen.Code, fail bool, offset int) []jen.Code { /* if errF := rewriteAST(node, node.ASTType, func(newNode, parent AST) { parent.(*RefContainer).ASTType = newNode.(AST) @@ -359,7 +362,22 @@ func (r *rewriteGen) rewriteChild(t, field types.Type, fieldName string, param j param, funcBlock).Block(returnFalse())) - return rewriteField + block := []jen.Code{ + jen.Id("a.cur.current").Op("=").Id("AddStep").Call(jen.Id("path"), jen.Id(printableTypeName(t)+fieldName)), + } + + if offset == 0 { + // if we are on the first field, we'll save the path + savePath := jen.Id("path").Op("=").Id("a.cur.current") + block = append([]jen.Code{savePath}, block...) + } + + ifCollectPath := jen.If(jen.Id("a.collectPaths")).Block(block...) + + return []jen.Code{ + ifCollectPath, + rewriteField, + } } func (r *rewriteGen) rewriteChildSlice(t, field types.Type, fieldName string, param jen.Code, replace jen.Code, fail bool) jen.Code { diff --git a/go/vt/sqlparser/ast_rewrite.go b/go/vt/sqlparser/ast_rewrite.go index 20883b914b5..aeeaf53388e 100644 --- a/go/vt/sqlparser/ast_rewrite.go +++ b/go/vt/sqlparser/ast_rewrite.go @@ -581,6 +581,7 @@ func (a *application) rewriteRefOfAddColumns(parent SQLNode, node *AddColumns, r return true } } + var path ASTPath for x, el := range node.Columns { if !a.rewriteRefOfColumnDefinition(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { @@ -590,11 +591,17 @@ func (a *application) rewriteRefOfAddColumns(parent SQLNode, node *AddColumns, r return false } } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfAddColumnsAfter) + } if !a.rewriteRefOfColName(node, node.After, func(newNode, parent SQLNode) { parent.(*AddColumns).After = newNode.(*ColName) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -617,11 +624,19 @@ func (a *application) rewriteRefOfAddConstraintDefinition(parent SQLNode, node * return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfAddConstraintDefinitionConstraintDefinition) + } if !a.rewriteRefOfConstraintDefinition(node, node.ConstraintDefinition, func(newNode, parent SQLNode) { parent.(*AddConstraintDefinition).ConstraintDefinition = newNode.(*ConstraintDefinition) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -644,11 +659,19 @@ func (a *application) rewriteRefOfAddIndexDefinition(parent SQLNode, node *AddIn return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfAddIndexDefinitionIndexDefinition) + } if !a.rewriteRefOfIndexDefinition(node, node.IndexDefinition, func(newNode, parent SQLNode) { parent.(*AddIndexDefinition).IndexDefinition = newNode.(*IndexDefinition) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -671,16 +694,27 @@ func (a *application) rewriteRefOfAliasedExpr(parent SQLNode, node *AliasedExpr, return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfAliasedExprExpr) + } if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { parent.(*AliasedExpr).Expr = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfAliasedExprAs) + } if !a.rewriteIdentifierCI(node, node.As, func(newNode, parent SQLNode) { parent.(*AliasedExpr).As = newNode.(IdentifierCI) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -703,31 +737,51 @@ func (a *application) rewriteRefOfAliasedTableExpr(parent SQLNode, node *Aliased return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfAliasedTableExprExpr) + } if !a.rewriteSimpleTableExpr(node, node.Expr, func(newNode, parent SQLNode) { parent.(*AliasedTableExpr).Expr = newNode.(SimpleTableExpr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfAliasedTableExprPartitions) + } if !a.rewritePartitions(node, node.Partitions, func(newNode, parent SQLNode) { parent.(*AliasedTableExpr).Partitions = newNode.(Partitions) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfAliasedTableExprAs) + } if !a.rewriteIdentifierCS(node, node.As, func(newNode, parent SQLNode) { parent.(*AliasedTableExpr).As = newNode.(IdentifierCS) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfAliasedTableExprHints) + } if !a.rewriteIndexHints(node, node.Hints, func(newNode, parent SQLNode) { parent.(*AliasedTableExpr).Hints = newNode.(IndexHints) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfAliasedTableExprColumns) + } if !a.rewriteColumns(node, node.Columns, func(newNode, parent SQLNode) { parent.(*AliasedTableExpr).Columns = newNode.(Columns) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -774,11 +828,19 @@ func (a *application) rewriteRefOfAlterCheck(parent SQLNode, node *AlterCheck, r return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfAlterCheckName) + } if !a.rewriteIdentifierCI(node, node.Name, func(newNode, parent SQLNode) { parent.(*AlterCheck).Name = newNode.(IdentifierCI) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -801,16 +863,27 @@ func (a *application) rewriteRefOfAlterColumn(parent SQLNode, node *AlterColumn, return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfAlterColumnColumn) + } if !a.rewriteRefOfColName(node, node.Column, func(newNode, parent SQLNode) { parent.(*AlterColumn).Column = newNode.(*ColName) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfAlterColumnDefaultVal) + } if !a.rewriteExpr(node, node.DefaultVal, func(newNode, parent SQLNode) { parent.(*AlterColumn).DefaultVal = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -833,16 +906,27 @@ func (a *application) rewriteRefOfAlterDatabase(parent SQLNode, node *AlterDatab return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfAlterDatabaseComments) + } if !a.rewriteRefOfParsedComments(node, node.Comments, func(newNode, parent SQLNode) { parent.(*AlterDatabase).Comments = newNode.(*ParsedComments) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfAlterDatabaseDBName) + } if !a.rewriteIdentifierCS(node, node.DBName, func(newNode, parent SQLNode) { parent.(*AlterDatabase).DBName = newNode.(IdentifierCS) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -865,11 +949,19 @@ func (a *application) rewriteRefOfAlterIndex(parent SQLNode, node *AlterIndex, r return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfAlterIndexName) + } if !a.rewriteIdentifierCI(node, node.Name, func(newNode, parent SQLNode) { parent.(*AlterIndex).Name = newNode.(IdentifierCI) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -892,11 +984,18 @@ func (a *application) rewriteRefOfAlterMigration(parent SQLNode, node *AlterMigr return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfAlterMigrationRatio) + } if !a.rewriteRefOfLiteral(node, node.Ratio, func(newNode, parent SQLNode) { parent.(*AlterMigration).Ratio = newNode.(*Literal) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -919,6 +1018,11 @@ func (a *application) rewriteRefOfAlterTable(parent SQLNode, node *AlterTable, r return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfAlterTableTable) + } if !a.rewriteTableName(node, node.Table, func(newNode, parent SQLNode) { parent.(*AlterTable).Table = newNode.(TableName) }) { @@ -933,21 +1037,33 @@ func (a *application) rewriteRefOfAlterTable(parent SQLNode, node *AlterTable, r return false } } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfAlterTablePartitionSpec) + } if !a.rewriteRefOfPartitionSpec(node, node.PartitionSpec, func(newNode, parent SQLNode) { parent.(*AlterTable).PartitionSpec = newNode.(*PartitionSpec) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfAlterTablePartitionOption) + } if !a.rewriteRefOfPartitionOption(node, node.PartitionOption, func(newNode, parent SQLNode) { parent.(*AlterTable).PartitionOption = newNode.(*PartitionOption) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfAlterTableComments) + } if !a.rewriteRefOfParsedComments(node, node.Comments, func(newNode, parent SQLNode) { parent.(*AlterTable).Comments = newNode.(*ParsedComments) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -970,31 +1086,51 @@ func (a *application) rewriteRefOfAlterView(parent SQLNode, node *AlterView, rep return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfAlterViewViewName) + } if !a.rewriteTableName(node, node.ViewName, func(newNode, parent SQLNode) { parent.(*AlterView).ViewName = newNode.(TableName) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfAlterViewDefiner) + } if !a.rewriteRefOfDefiner(node, node.Definer, func(newNode, parent SQLNode) { parent.(*AlterView).Definer = newNode.(*Definer) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfAlterViewColumns) + } if !a.rewriteColumns(node, node.Columns, func(newNode, parent SQLNode) { parent.(*AlterView).Columns = newNode.(Columns) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfAlterViewSelect) + } if !a.rewriteTableStatement(node, node.Select, func(newNode, parent SQLNode) { parent.(*AlterView).Select = newNode.(TableStatement) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfAlterViewComments) + } if !a.rewriteRefOfParsedComments(node, node.Comments, func(newNode, parent SQLNode) { parent.(*AlterView).Comments = newNode.(*ParsedComments) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -1017,11 +1153,18 @@ func (a *application) rewriteRefOfAlterVschema(parent SQLNode, node *AlterVschem return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfAlterVschemaTable) + } if !a.rewriteTableName(node, node.Table, func(newNode, parent SQLNode) { parent.(*AlterVschema).Table = newNode.(TableName) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfAlterVschemaVindexSpec) + } if !a.rewriteRefOfVindexSpec(node, node.VindexSpec, func(newNode, parent SQLNode) { parent.(*AlterVschema).VindexSpec = newNode.(*VindexSpec) }) { @@ -1036,11 +1179,17 @@ func (a *application) rewriteRefOfAlterVschema(parent SQLNode, node *AlterVschem return false } } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfAlterVschemaAutoIncSpec) + } if !a.rewriteRefOfAutoIncSpec(node, node.AutoIncSpec, func(newNode, parent SQLNode) { parent.(*AlterVschema).AutoIncSpec = newNode.(*AutoIncSpec) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -1063,11 +1212,18 @@ func (a *application) rewriteRefOfAnalyze(parent SQLNode, node *Analyze, replace return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfAnalyzeTable) + } if !a.rewriteTableName(node, node.Table, func(newNode, parent SQLNode) { parent.(*Analyze).Table = newNode.(TableName) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -1095,16 +1251,27 @@ func (a *application) rewriteRefOfAndExpr(parent SQLNode, node *AndExpr, replace return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfAndExprLeft) + } if !a.rewriteExpr(node, node.Left, func(newNode, parent SQLNode) { parent.(*AndExpr).Left = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfAndExprRight) + } if !a.rewriteExpr(node, node.Right, func(newNode, parent SQLNode) { parent.(*AndExpr).Right = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -1132,11 +1299,19 @@ func (a *application) rewriteRefOfAnyValue(parent SQLNode, node *AnyValue, repla return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfAnyValueArg) + } if !a.rewriteExpr(node, node.Arg, func(newNode, parent SQLNode) { parent.(*AnyValue).Arg = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -1193,11 +1368,18 @@ func (a *application) rewriteRefOfArgumentLessWindowExpr(parent SQLNode, node *A return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfArgumentLessWindowExprOverClause) + } if !a.rewriteRefOfOverClause(node, node.OverClause, func(newNode, parent SQLNode) { parent.(*ArgumentLessWindowExpr).OverClause = newNode.(*OverClause) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -1225,16 +1407,27 @@ func (a *application) rewriteRefOfAssignmentExpr(parent SQLNode, node *Assignmen return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfAssignmentExprLeft) + } if !a.rewriteExpr(node, node.Left, func(newNode, parent SQLNode) { parent.(*AssignmentExpr).Left = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfAssignmentExprRight) + } if !a.rewriteExpr(node, node.Right, func(newNode, parent SQLNode) { parent.(*AssignmentExpr).Right = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -1257,16 +1450,27 @@ func (a *application) rewriteRefOfAutoIncSpec(parent SQLNode, node *AutoIncSpec, return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfAutoIncSpecColumn) + } if !a.rewriteIdentifierCI(node, node.Column, func(newNode, parent SQLNode) { parent.(*AutoIncSpec).Column = newNode.(IdentifierCI) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfAutoIncSpecSequence) + } if !a.rewriteTableName(node, node.Sequence, func(newNode, parent SQLNode) { parent.(*AutoIncSpec).Sequence = newNode.(TableName) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -1294,16 +1498,27 @@ func (a *application) rewriteRefOfAvg(parent SQLNode, node *Avg, replacer replac return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfAvgArg) + } if !a.rewriteExpr(node, node.Arg, func(newNode, parent SQLNode) { parent.(*Avg).Arg = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfAvgOverClause) + } if !a.rewriteRefOfOverClause(node, node.OverClause, func(newNode, parent SQLNode) { parent.(*Avg).OverClause = newNode.(*OverClause) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -1355,21 +1570,34 @@ func (a *application) rewriteRefOfBetweenExpr(parent SQLNode, node *BetweenExpr, return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfBetweenExprLeft) + } if !a.rewriteExpr(node, node.Left, func(newNode, parent SQLNode) { parent.(*BetweenExpr).Left = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfBetweenExprFrom) + } if !a.rewriteExpr(node, node.From, func(newNode, parent SQLNode) { parent.(*BetweenExpr).From = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfBetweenExprTo) + } if !a.rewriteExpr(node, node.To, func(newNode, parent SQLNode) { parent.(*BetweenExpr).To = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -1397,16 +1625,26 @@ func (a *application) rewriteRefOfBinaryExpr(parent SQLNode, node *BinaryExpr, r return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfBinaryExprLeft) + } if !a.rewriteExpr(node, node.Left, func(newNode, parent SQLNode) { parent.(*BinaryExpr).Left = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfBinaryExprRight) + } if !a.rewriteExpr(node, node.Right, func(newNode, parent SQLNode) { parent.(*BinaryExpr).Right = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -1434,16 +1672,27 @@ func (a *application) rewriteRefOfBitAnd(parent SQLNode, node *BitAnd, replacer return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfBitAndArg) + } if !a.rewriteExpr(node, node.Arg, func(newNode, parent SQLNode) { parent.(*BitAnd).Arg = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfBitAndOverClause) + } if !a.rewriteRefOfOverClause(node, node.OverClause, func(newNode, parent SQLNode) { parent.(*BitAnd).OverClause = newNode.(*OverClause) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -1471,16 +1720,27 @@ func (a *application) rewriteRefOfBitOr(parent SQLNode, node *BitOr, replacer re return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfBitOrArg) + } if !a.rewriteExpr(node, node.Arg, func(newNode, parent SQLNode) { parent.(*BitOr).Arg = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfBitOrOverClause) + } if !a.rewriteRefOfOverClause(node, node.OverClause, func(newNode, parent SQLNode) { parent.(*BitOr).OverClause = newNode.(*OverClause) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -1508,16 +1768,27 @@ func (a *application) rewriteRefOfBitXor(parent SQLNode, node *BitXor, replacer return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfBitXorArg) + } if !a.rewriteExpr(node, node.Arg, func(newNode, parent SQLNode) { parent.(*BitXor).Arg = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfBitXorOverClause) + } if !a.rewriteRefOfOverClause(node, node.OverClause, func(newNode, parent SQLNode) { parent.(*BitXor).OverClause = newNode.(*OverClause) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -1540,16 +1811,27 @@ func (a *application) rewriteRefOfCallProc(parent SQLNode, node *CallProc, repla return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfCallProcName) + } if !a.rewriteTableName(node, node.Name, func(newNode, parent SQLNode) { parent.(*CallProc).Name = newNode.(TableName) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfCallProcParams) + } if !a.rewriteExprs(node, node.Params, func(newNode, parent SQLNode) { parent.(*CallProc).Params = newNode.(Exprs) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -1577,6 +1859,11 @@ func (a *application) rewriteRefOfCaseExpr(parent SQLNode, node *CaseExpr, repla return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfCaseExprExpr) + } if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { parent.(*CaseExpr).Expr = newNode.(Expr) }) { @@ -1591,11 +1878,17 @@ func (a *application) rewriteRefOfCaseExpr(parent SQLNode, node *CaseExpr, repla return false } } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfCaseExprElse) + } if !a.rewriteExpr(node, node.Else, func(newNode, parent SQLNode) { parent.(*CaseExpr).Else = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -1623,16 +1916,27 @@ func (a *application) rewriteRefOfCastExpr(parent SQLNode, node *CastExpr, repla return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfCastExprExpr) + } if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { parent.(*CastExpr).Expr = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfCastExprType) + } if !a.rewriteRefOfConvertType(node, node.Type, func(newNode, parent SQLNode) { parent.(*CastExpr).Type = newNode.(*ConvertType) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -1655,21 +1959,35 @@ func (a *application) rewriteRefOfChangeColumn(parent SQLNode, node *ChangeColum return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfChangeColumnOldColumn) + } if !a.rewriteRefOfColName(node, node.OldColumn, func(newNode, parent SQLNode) { parent.(*ChangeColumn).OldColumn = newNode.(*ColName) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfChangeColumnNewColDefinition) + } if !a.rewriteRefOfColumnDefinition(node, node.NewColDefinition, func(newNode, parent SQLNode) { parent.(*ChangeColumn).NewColDefinition = newNode.(*ColumnDefinition) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfChangeColumnAfter) + } if !a.rewriteRefOfColName(node, node.After, func(newNode, parent SQLNode) { parent.(*ChangeColumn).After = newNode.(*ColName) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -1697,11 +2015,19 @@ func (a *application) rewriteRefOfCharExpr(parent SQLNode, node *CharExpr, repla return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfCharExprExprs) + } if !a.rewriteExprs(node, node.Exprs, func(newNode, parent SQLNode) { parent.(*CharExpr).Exprs = newNode.(Exprs) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -1724,11 +2050,19 @@ func (a *application) rewriteRefOfCheckConstraintDefinition(parent SQLNode, node return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfCheckConstraintDefinitionExpr) + } if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { parent.(*CheckConstraintDefinition).Expr = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -1756,16 +2090,27 @@ func (a *application) rewriteRefOfColName(parent SQLNode, node *ColName, replace return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfColNameName) + } if !a.rewriteIdentifierCI(node, node.Name, func(newNode, parent SQLNode) { parent.(*ColName).Name = newNode.(IdentifierCI) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfColNameQualifier) + } if !a.rewriteTableName(node, node.Qualifier, func(newNode, parent SQLNode) { parent.(*ColName).Qualifier = newNode.(TableName) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -1793,11 +2138,19 @@ func (a *application) rewriteRefOfCollateExpr(parent SQLNode, node *CollateExpr, return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfCollateExprExpr) + } if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { parent.(*CollateExpr).Expr = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -1820,16 +2173,27 @@ func (a *application) rewriteRefOfColumnDefinition(parent SQLNode, node *ColumnD return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfColumnDefinitionName) + } if !a.rewriteIdentifierCI(node, node.Name, func(newNode, parent SQLNode) { parent.(*ColumnDefinition).Name = newNode.(IdentifierCI) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfColumnDefinitionType) + } if !a.rewriteRefOfColumnType(node, node.Type, func(newNode, parent SQLNode) { parent.(*ColumnDefinition).Type = newNode.(*ColumnType) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -1961,21 +2325,35 @@ func (a *application) rewriteRefOfCommonTableExpr(parent SQLNode, node *CommonTa return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfCommonTableExprID) + } if !a.rewriteIdentifierCS(node, node.ID, func(newNode, parent SQLNode) { parent.(*CommonTableExpr).ID = newNode.(IdentifierCS) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfCommonTableExprColumns) + } if !a.rewriteColumns(node, node.Columns, func(newNode, parent SQLNode) { parent.(*CommonTableExpr).Columns = newNode.(Columns) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfCommonTableExprSubquery) + } if !a.rewriteTableStatement(node, node.Subquery, func(newNode, parent SQLNode) { parent.(*CommonTableExpr).Subquery = newNode.(TableStatement) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -2003,21 +2381,34 @@ func (a *application) rewriteRefOfComparisonExpr(parent SQLNode, node *Compariso return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfComparisonExprLeft) + } if !a.rewriteExpr(node, node.Left, func(newNode, parent SQLNode) { parent.(*ComparisonExpr).Left = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfComparisonExprRight) + } if !a.rewriteExpr(node, node.Right, func(newNode, parent SQLNode) { parent.(*ComparisonExpr).Right = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfComparisonExprEscape) + } if !a.rewriteExpr(node, node.Escape, func(newNode, parent SQLNode) { parent.(*ComparisonExpr).Escape = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -2040,16 +2431,27 @@ func (a *application) rewriteRefOfConstraintDefinition(parent SQLNode, node *Con return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfConstraintDefinitionName) + } if !a.rewriteIdentifierCI(node, node.Name, func(newNode, parent SQLNode) { parent.(*ConstraintDefinition).Name = newNode.(IdentifierCI) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfConstraintDefinitionDetails) + } if !a.rewriteConstraintInfo(node, node.Details, func(newNode, parent SQLNode) { parent.(*ConstraintDefinition).Details = newNode.(ConstraintInfo) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -2077,16 +2479,27 @@ func (a *application) rewriteRefOfConvertExpr(parent SQLNode, node *ConvertExpr, return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfConvertExprExpr) + } if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { parent.(*ConvertExpr).Expr = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfConvertExprType) + } if !a.rewriteRefOfConvertType(node, node.Type, func(newNode, parent SQLNode) { parent.(*ConvertExpr).Type = newNode.(*ConvertType) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -2138,11 +2551,19 @@ func (a *application) rewriteRefOfConvertUsingExpr(parent SQLNode, node *Convert return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfConvertUsingExprExpr) + } if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { parent.(*ConvertUsingExpr).Expr = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -2170,16 +2591,27 @@ func (a *application) rewriteRefOfCount(parent SQLNode, node *Count, replacer re return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfCountArgs) + } if !a.rewriteExprs(node, node.Args, func(newNode, parent SQLNode) { parent.(*Count).Args = newNode.(Exprs) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfCountOverClause) + } if !a.rewriteRefOfOverClause(node, node.OverClause, func(newNode, parent SQLNode) { parent.(*Count).OverClause = newNode.(*OverClause) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -2207,11 +2639,18 @@ func (a *application) rewriteRefOfCountStar(parent SQLNode, node *CountStar, rep return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfCountStarOverClause) + } if !a.rewriteRefOfOverClause(node, node.OverClause, func(newNode, parent SQLNode) { parent.(*CountStar).OverClause = newNode.(*OverClause) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -2234,16 +2673,27 @@ func (a *application) rewriteRefOfCreateDatabase(parent SQLNode, node *CreateDat return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfCreateDatabaseComments) + } if !a.rewriteRefOfParsedComments(node, node.Comments, func(newNode, parent SQLNode) { parent.(*CreateDatabase).Comments = newNode.(*ParsedComments) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfCreateDatabaseDBName) + } if !a.rewriteIdentifierCS(node, node.DBName, func(newNode, parent SQLNode) { parent.(*CreateDatabase).DBName = newNode.(IdentifierCS) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -2266,26 +2716,42 @@ func (a *application) rewriteRefOfCreateTable(parent SQLNode, node *CreateTable, return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfCreateTableTable) + } if !a.rewriteTableName(node, node.Table, func(newNode, parent SQLNode) { parent.(*CreateTable).Table = newNode.(TableName) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfCreateTableTableSpec) + } if !a.rewriteRefOfTableSpec(node, node.TableSpec, func(newNode, parent SQLNode) { parent.(*CreateTable).TableSpec = newNode.(*TableSpec) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfCreateTableOptLike) + } if !a.rewriteRefOfOptLike(node, node.OptLike, func(newNode, parent SQLNode) { parent.(*CreateTable).OptLike = newNode.(*OptLike) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfCreateTableComments) + } if !a.rewriteRefOfParsedComments(node, node.Comments, func(newNode, parent SQLNode) { parent.(*CreateTable).Comments = newNode.(*ParsedComments) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -2308,31 +2774,51 @@ func (a *application) rewriteRefOfCreateView(parent SQLNode, node *CreateView, r return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfCreateViewViewName) + } if !a.rewriteTableName(node, node.ViewName, func(newNode, parent SQLNode) { parent.(*CreateView).ViewName = newNode.(TableName) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfCreateViewDefiner) + } if !a.rewriteRefOfDefiner(node, node.Definer, func(newNode, parent SQLNode) { parent.(*CreateView).Definer = newNode.(*Definer) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfCreateViewColumns) + } if !a.rewriteColumns(node, node.Columns, func(newNode, parent SQLNode) { parent.(*CreateView).Columns = newNode.(Columns) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfCreateViewSelect) + } if !a.rewriteTableStatement(node, node.Select, func(newNode, parent SQLNode) { parent.(*CreateView).Select = newNode.(TableStatement) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfCreateViewComments) + } if !a.rewriteRefOfParsedComments(node, node.Comments, func(newNode, parent SQLNode) { parent.(*CreateView).Comments = newNode.(*ParsedComments) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -2360,11 +2846,19 @@ func (a *application) rewriteRefOfCurTimeFuncExpr(parent SQLNode, node *CurTimeF return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfCurTimeFuncExprName) + } if !a.rewriteIdentifierCI(node, node.Name, func(newNode, parent SQLNode) { parent.(*CurTimeFuncExpr).Name = newNode.(IdentifierCI) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -2387,16 +2881,27 @@ func (a *application) rewriteRefOfDeallocateStmt(parent SQLNode, node *Deallocat return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfDeallocateStmtComments) + } if !a.rewriteRefOfParsedComments(node, node.Comments, func(newNode, parent SQLNode) { parent.(*DeallocateStmt).Comments = newNode.(*ParsedComments) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfDeallocateStmtName) + } if !a.rewriteIdentifierCI(node, node.Name, func(newNode, parent SQLNode) { parent.(*DeallocateStmt).Name = newNode.(IdentifierCI) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -2472,11 +2977,19 @@ func (a *application) rewriteRefOfDelete(parent SQLNode, node *Delete, replacer return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfDeleteWith) + } if !a.rewriteRefOfWith(node, node.With, func(newNode, parent SQLNode) { parent.(*Delete).With = newNode.(*With) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfDeleteComments) + } if !a.rewriteRefOfParsedComments(node, node.Comments, func(newNode, parent SQLNode) { parent.(*Delete).Comments = newNode.(*ParsedComments) }) { @@ -2491,31 +3004,49 @@ func (a *application) rewriteRefOfDelete(parent SQLNode, node *Delete, replacer return false } } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfDeleteTargets) + } if !a.rewriteTableNames(node, node.Targets, func(newNode, parent SQLNode) { parent.(*Delete).Targets = newNode.(TableNames) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfDeletePartitions) + } if !a.rewritePartitions(node, node.Partitions, func(newNode, parent SQLNode) { parent.(*Delete).Partitions = newNode.(Partitions) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfDeleteWhere) + } if !a.rewriteRefOfWhere(node, node.Where, func(newNode, parent SQLNode) { parent.(*Delete).Where = newNode.(*Where) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfDeleteOrderBy) + } if !a.rewriteOrderBy(node, node.OrderBy, func(newNode, parent SQLNode) { parent.(*Delete).OrderBy = newNode.(OrderBy) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfDeleteLimit) + } if !a.rewriteRefOfLimit(node, node.Limit, func(newNode, parent SQLNode) { parent.(*Delete).Limit = newNode.(*Limit) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -2538,11 +3069,18 @@ func (a *application) rewriteRefOfDerivedTable(parent SQLNode, node *DerivedTabl return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfDerivedTableSelect) + } if !a.rewriteTableStatement(node, node.Select, func(newNode, parent SQLNode) { parent.(*DerivedTable).Select = newNode.(TableStatement) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -2565,11 +3103,19 @@ func (a *application) rewriteRefOfDropColumn(parent SQLNode, node *DropColumn, r return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfDropColumnName) + } if !a.rewriteRefOfColName(node, node.Name, func(newNode, parent SQLNode) { parent.(*DropColumn).Name = newNode.(*ColName) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -2592,16 +3138,27 @@ func (a *application) rewriteRefOfDropDatabase(parent SQLNode, node *DropDatabas return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfDropDatabaseComments) + } if !a.rewriteRefOfParsedComments(node, node.Comments, func(newNode, parent SQLNode) { parent.(*DropDatabase).Comments = newNode.(*ParsedComments) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfDropDatabaseDBName) + } if !a.rewriteIdentifierCS(node, node.DBName, func(newNode, parent SQLNode) { parent.(*DropDatabase).DBName = newNode.(IdentifierCS) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -2624,11 +3181,18 @@ func (a *application) rewriteRefOfDropKey(parent SQLNode, node *DropKey, replace return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfDropKeyName) + } if !a.rewriteIdentifierCI(node, node.Name, func(newNode, parent SQLNode) { parent.(*DropKey).Name = newNode.(IdentifierCI) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -2651,16 +3215,26 @@ func (a *application) rewriteRefOfDropTable(parent SQLNode, node *DropTable, rep return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfDropTableFromTables) + } if !a.rewriteTableNames(node, node.FromTables, func(newNode, parent SQLNode) { parent.(*DropTable).FromTables = newNode.(TableNames) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfDropTableComments) + } if !a.rewriteRefOfParsedComments(node, node.Comments, func(newNode, parent SQLNode) { parent.(*DropTable).Comments = newNode.(*ParsedComments) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -2683,16 +3257,27 @@ func (a *application) rewriteRefOfDropView(parent SQLNode, node *DropView, repla return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfDropViewFromTables) + } if !a.rewriteTableNames(node, node.FromTables, func(newNode, parent SQLNode) { parent.(*DropView).FromTables = newNode.(TableNames) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfDropViewComments) + } if !a.rewriteRefOfParsedComments(node, node.Comments, func(newNode, parent SQLNode) { parent.(*DropView).Comments = newNode.(*ParsedComments) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -2715,11 +3300,19 @@ func (a *application) rewriteRefOfExecuteStmt(parent SQLNode, node *ExecuteStmt, return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfExecuteStmtName) + } if !a.rewriteIdentifierCI(node, node.Name, func(newNode, parent SQLNode) { parent.(*ExecuteStmt).Name = newNode.(IdentifierCI) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfExecuteStmtComments) + } if !a.rewriteRefOfParsedComments(node, node.Comments, func(newNode, parent SQLNode) { parent.(*ExecuteStmt).Comments = newNode.(*ParsedComments) }) { @@ -2734,6 +3327,9 @@ func (a *application) rewriteRefOfExecuteStmt(parent SQLNode, node *ExecuteStmt, return false } } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -2761,11 +3357,19 @@ func (a *application) rewriteRefOfExistsExpr(parent SQLNode, node *ExistsExpr, r return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfExistsExprSubquery) + } if !a.rewriteRefOfSubquery(node, node.Subquery, func(newNode, parent SQLNode) { parent.(*ExistsExpr).Subquery = newNode.(*Subquery) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -2788,16 +3392,26 @@ func (a *application) rewriteRefOfExplainStmt(parent SQLNode, node *ExplainStmt, return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfExplainStmtStatement) + } if !a.rewriteStatement(node, node.Statement, func(newNode, parent SQLNode) { parent.(*ExplainStmt).Statement = newNode.(Statement) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfExplainStmtComments) + } if !a.rewriteRefOfParsedComments(node, node.Comments, func(newNode, parent SQLNode) { parent.(*ExplainStmt).Comments = newNode.(*ParsedComments) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -2820,11 +3434,19 @@ func (a *application) rewriteRefOfExplainTab(parent SQLNode, node *ExplainTab, r return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfExplainTabTable) + } if !a.rewriteTableName(node, node.Table, func(newNode, parent SQLNode) { parent.(*ExplainTab).Table = newNode.(TableName) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -2889,11 +3511,18 @@ func (a *application) rewriteRefOfExtractFuncExpr(parent SQLNode, node *ExtractF return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfExtractFuncExprExpr) + } if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { parent.(*ExtractFuncExpr).Expr = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -2921,16 +3550,27 @@ func (a *application) rewriteRefOfExtractValueExpr(parent SQLNode, node *Extract return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfExtractValueExprFragment) + } if !a.rewriteExpr(node, node.Fragment, func(newNode, parent SQLNode) { parent.(*ExtractValueExpr).Fragment = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfExtractValueExprXPathExpr) + } if !a.rewriteExpr(node, node.XPathExpr, func(newNode, parent SQLNode) { parent.(*ExtractValueExpr).XPathExpr = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -2958,21 +3598,34 @@ func (a *application) rewriteRefOfFirstOrLastValueExpr(parent SQLNode, node *Fir return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfFirstOrLastValueExprExpr) + } if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { parent.(*FirstOrLastValueExpr).Expr = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfFirstOrLastValueExprNullTreatmentClause) + } if !a.rewriteRefOfNullTreatmentClause(node, node.NullTreatmentClause, func(newNode, parent SQLNode) { parent.(*FirstOrLastValueExpr).NullTreatmentClause = newNode.(*NullTreatmentClause) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfFirstOrLastValueExprOverClause) + } if !a.rewriteRefOfOverClause(node, node.OverClause, func(newNode, parent SQLNode) { parent.(*FirstOrLastValueExpr).OverClause = newNode.(*OverClause) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -2995,11 +3648,18 @@ func (a *application) rewriteRefOfFlush(parent SQLNode, node *Flush, replacer re return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfFlushTableNames) + } if !a.rewriteTableNames(node, node.TableNames, func(newNode, parent SQLNode) { parent.(*Flush).TableNames = newNode.(TableNames) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -3046,21 +3706,35 @@ func (a *application) rewriteRefOfForeignKeyDefinition(parent SQLNode, node *For return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfForeignKeyDefinitionSource) + } if !a.rewriteColumns(node, node.Source, func(newNode, parent SQLNode) { parent.(*ForeignKeyDefinition).Source = newNode.(Columns) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfForeignKeyDefinitionIndexName) + } if !a.rewriteIdentifierCI(node, node.IndexName, func(newNode, parent SQLNode) { parent.(*ForeignKeyDefinition).IndexName = newNode.(IdentifierCI) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfForeignKeyDefinitionReferenceDefinition) + } if !a.rewriteRefOfReferenceDefinition(node, node.ReferenceDefinition, func(newNode, parent SQLNode) { parent.(*ForeignKeyDefinition).ReferenceDefinition = newNode.(*ReferenceDefinition) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -3083,16 +3757,26 @@ func (a *application) rewriteRefOfFrameClause(parent SQLNode, node *FrameClause, return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfFrameClauseStart) + } if !a.rewriteRefOfFramePoint(node, node.Start, func(newNode, parent SQLNode) { parent.(*FrameClause).Start = newNode.(*FramePoint) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfFrameClauseEnd) + } if !a.rewriteRefOfFramePoint(node, node.End, func(newNode, parent SQLNode) { parent.(*FrameClause).End = newNode.(*FramePoint) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -3115,11 +3799,18 @@ func (a *application) rewriteRefOfFramePoint(parent SQLNode, node *FramePoint, r return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfFramePointExpr) + } if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { parent.(*FramePoint).Expr = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -3171,21 +3862,35 @@ func (a *application) rewriteRefOfFuncExpr(parent SQLNode, node *FuncExpr, repla return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfFuncExprQualifier) + } if !a.rewriteIdentifierCS(node, node.Qualifier, func(newNode, parent SQLNode) { parent.(*FuncExpr).Qualifier = newNode.(IdentifierCS) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfFuncExprName) + } if !a.rewriteIdentifierCI(node, node.Name, func(newNode, parent SQLNode) { parent.(*FuncExpr).Name = newNode.(IdentifierCI) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfFuncExprExprs) + } if !a.rewriteExprs(node, node.Exprs, func(newNode, parent SQLNode) { parent.(*FuncExpr).Exprs = newNode.(Exprs) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -3213,26 +3918,42 @@ func (a *application) rewriteRefOfGTIDFuncExpr(parent SQLNode, node *GTIDFuncExp return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfGTIDFuncExprSet1) + } if !a.rewriteExpr(node, node.Set1, func(newNode, parent SQLNode) { parent.(*GTIDFuncExpr).Set1 = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfGTIDFuncExprSet2) + } if !a.rewriteExpr(node, node.Set2, func(newNode, parent SQLNode) { parent.(*GTIDFuncExpr).Set2 = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfGTIDFuncExprTimeout) + } if !a.rewriteExpr(node, node.Timeout, func(newNode, parent SQLNode) { parent.(*GTIDFuncExpr).Timeout = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfGTIDFuncExprChannel) + } if !a.rewriteExpr(node, node.Channel, func(newNode, parent SQLNode) { parent.(*GTIDFuncExpr).Channel = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -3260,21 +3981,35 @@ func (a *application) rewriteRefOfGeoHashFromLatLongExpr(parent SQLNode, node *G return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfGeoHashFromLatLongExprLatitude) + } if !a.rewriteExpr(node, node.Latitude, func(newNode, parent SQLNode) { parent.(*GeoHashFromLatLongExpr).Latitude = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfGeoHashFromLatLongExprLongitude) + } if !a.rewriteExpr(node, node.Longitude, func(newNode, parent SQLNode) { parent.(*GeoHashFromLatLongExpr).Longitude = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfGeoHashFromLatLongExprMaxLength) + } if !a.rewriteExpr(node, node.MaxLength, func(newNode, parent SQLNode) { parent.(*GeoHashFromLatLongExpr).MaxLength = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -3302,16 +4037,27 @@ func (a *application) rewriteRefOfGeoHashFromPointExpr(parent SQLNode, node *Geo return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfGeoHashFromPointExprPoint) + } if !a.rewriteExpr(node, node.Point, func(newNode, parent SQLNode) { parent.(*GeoHashFromPointExpr).Point = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfGeoHashFromPointExprMaxLength) + } if !a.rewriteExpr(node, node.MaxLength, func(newNode, parent SQLNode) { parent.(*GeoHashFromPointExpr).MaxLength = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -3339,21 +4085,35 @@ func (a *application) rewriteRefOfGeoJSONFromGeomExpr(parent SQLNode, node *GeoJ return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfGeoJSONFromGeomExprGeom) + } if !a.rewriteExpr(node, node.Geom, func(newNode, parent SQLNode) { parent.(*GeoJSONFromGeomExpr).Geom = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfGeoJSONFromGeomExprMaxDecimalDigits) + } if !a.rewriteExpr(node, node.MaxDecimalDigits, func(newNode, parent SQLNode) { parent.(*GeoJSONFromGeomExpr).MaxDecimalDigits = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfGeoJSONFromGeomExprBitmask) + } if !a.rewriteExpr(node, node.Bitmask, func(newNode, parent SQLNode) { parent.(*GeoJSONFromGeomExpr).Bitmask = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -3381,16 +4141,26 @@ func (a *application) rewriteRefOfGeomCollPropertyFuncExpr(parent SQLNode, node return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfGeomCollPropertyFuncExprGeomColl) + } if !a.rewriteExpr(node, node.GeomColl, func(newNode, parent SQLNode) { parent.(*GeomCollPropertyFuncExpr).GeomColl = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfGeomCollPropertyFuncExprPropertyDefArg) + } if !a.rewriteExpr(node, node.PropertyDefArg, func(newNode, parent SQLNode) { parent.(*GeomCollPropertyFuncExpr).PropertyDefArg = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -3418,16 +4188,26 @@ func (a *application) rewriteRefOfGeomFormatExpr(parent SQLNode, node *GeomForma return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfGeomFormatExprGeom) + } if !a.rewriteExpr(node, node.Geom, func(newNode, parent SQLNode) { parent.(*GeomFormatExpr).Geom = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfGeomFormatExprAxisOrderOpt) + } if !a.rewriteExpr(node, node.AxisOrderOpt, func(newNode, parent SQLNode) { parent.(*GeomFormatExpr).AxisOrderOpt = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -3455,16 +4235,26 @@ func (a *application) rewriteRefOfGeomFromGeoHashExpr(parent SQLNode, node *Geom return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfGeomFromGeoHashExprGeoHash) + } if !a.rewriteExpr(node, node.GeoHash, func(newNode, parent SQLNode) { parent.(*GeomFromGeoHashExpr).GeoHash = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfGeomFromGeoHashExprSridOpt) + } if !a.rewriteExpr(node, node.SridOpt, func(newNode, parent SQLNode) { parent.(*GeomFromGeoHashExpr).SridOpt = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -3492,21 +4282,35 @@ func (a *application) rewriteRefOfGeomFromGeoJSONExpr(parent SQLNode, node *Geom return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfGeomFromGeoJSONExprGeoJSON) + } if !a.rewriteExpr(node, node.GeoJSON, func(newNode, parent SQLNode) { parent.(*GeomFromGeoJSONExpr).GeoJSON = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfGeomFromGeoJSONExprHigherDimHandlerOpt) + } if !a.rewriteExpr(node, node.HigherDimHandlerOpt, func(newNode, parent SQLNode) { parent.(*GeomFromGeoJSONExpr).HigherDimHandlerOpt = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfGeomFromGeoJSONExprSrid) + } if !a.rewriteExpr(node, node.Srid, func(newNode, parent SQLNode) { parent.(*GeomFromGeoJSONExpr).Srid = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -3534,21 +4338,34 @@ func (a *application) rewriteRefOfGeomFromTextExpr(parent SQLNode, node *GeomFro return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfGeomFromTextExprWktText) + } if !a.rewriteExpr(node, node.WktText, func(newNode, parent SQLNode) { parent.(*GeomFromTextExpr).WktText = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfGeomFromTextExprSrid) + } if !a.rewriteExpr(node, node.Srid, func(newNode, parent SQLNode) { parent.(*GeomFromTextExpr).Srid = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfGeomFromTextExprAxisOrderOpt) + } if !a.rewriteExpr(node, node.AxisOrderOpt, func(newNode, parent SQLNode) { parent.(*GeomFromTextExpr).AxisOrderOpt = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -3576,21 +4393,34 @@ func (a *application) rewriteRefOfGeomFromWKBExpr(parent SQLNode, node *GeomFrom return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfGeomFromWKBExprWkbBlob) + } if !a.rewriteExpr(node, node.WkbBlob, func(newNode, parent SQLNode) { parent.(*GeomFromWKBExpr).WkbBlob = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfGeomFromWKBExprSrid) + } if !a.rewriteExpr(node, node.Srid, func(newNode, parent SQLNode) { parent.(*GeomFromWKBExpr).Srid = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfGeomFromWKBExprAxisOrderOpt) + } if !a.rewriteExpr(node, node.AxisOrderOpt, func(newNode, parent SQLNode) { parent.(*GeomFromWKBExpr).AxisOrderOpt = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -3618,11 +4448,18 @@ func (a *application) rewriteRefOfGeomPropertyFuncExpr(parent SQLNode, node *Geo return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfGeomPropertyFuncExprGeom) + } if !a.rewriteExpr(node, node.Geom, func(newNode, parent SQLNode) { parent.(*GeomPropertyFuncExpr).Geom = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -3645,6 +4482,7 @@ func (a *application) rewriteRefOfGroupBy(parent SQLNode, node *GroupBy, replace return true } } + var path ASTPath for x, el := range node.Exprs { if !a.rewriteExpr(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { @@ -3654,6 +4492,9 @@ func (a *application) rewriteRefOfGroupBy(parent SQLNode, node *GroupBy, replace return false } } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -3681,21 +4522,34 @@ func (a *application) rewriteRefOfGroupConcatExpr(parent SQLNode, node *GroupCon return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfGroupConcatExprExprs) + } if !a.rewriteExprs(node, node.Exprs, func(newNode, parent SQLNode) { parent.(*GroupConcatExpr).Exprs = newNode.(Exprs) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfGroupConcatExprOrderBy) + } if !a.rewriteOrderBy(node, node.OrderBy, func(newNode, parent SQLNode) { parent.(*GroupConcatExpr).OrderBy = newNode.(OrderBy) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfGroupConcatExprLimit) + } if !a.rewriteRefOfLimit(node, node.Limit, func(newNode, parent SQLNode) { parent.(*GroupConcatExpr).Limit = newNode.(*Limit) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -3760,11 +4614,19 @@ func (a *application) rewriteRefOfIndexDefinition(parent SQLNode, node *IndexDef return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfIndexDefinitionInfo) + } if !a.rewriteRefOfIndexInfo(node, node.Info, func(newNode, parent SQLNode) { parent.(*IndexDefinition).Info = newNode.(*IndexInfo) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -3787,6 +4649,7 @@ func (a *application) rewriteRefOfIndexHint(parent SQLNode, node *IndexHint, rep return true } } + var path ASTPath for x, el := range node.Indexes { if !a.rewriteIdentifierCI(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { @@ -3796,6 +4659,9 @@ func (a *application) rewriteRefOfIndexHint(parent SQLNode, node *IndexHint, rep return false } } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -3855,16 +4721,26 @@ func (a *application) rewriteRefOfIndexInfo(parent SQLNode, node *IndexInfo, rep return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfIndexInfoName) + } if !a.rewriteIdentifierCI(node, node.Name, func(newNode, parent SQLNode) { parent.(*IndexInfo).Name = newNode.(IdentifierCI) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfIndexInfoConstraintName) + } if !a.rewriteIdentifierCI(node, node.ConstraintName, func(newNode, parent SQLNode) { parent.(*IndexInfo).ConstraintName = newNode.(IdentifierCI) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -3887,41 +4763,66 @@ func (a *application) rewriteRefOfInsert(parent SQLNode, node *Insert, replacer return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfInsertComments) + } if !a.rewriteRefOfParsedComments(node, node.Comments, func(newNode, parent SQLNode) { parent.(*Insert).Comments = newNode.(*ParsedComments) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfInsertTable) + } if !a.rewriteRefOfAliasedTableExpr(node, node.Table, func(newNode, parent SQLNode) { parent.(*Insert).Table = newNode.(*AliasedTableExpr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfInsertPartitions) + } if !a.rewritePartitions(node, node.Partitions, func(newNode, parent SQLNode) { parent.(*Insert).Partitions = newNode.(Partitions) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfInsertColumns) + } if !a.rewriteColumns(node, node.Columns, func(newNode, parent SQLNode) { parent.(*Insert).Columns = newNode.(Columns) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfInsertRows) + } if !a.rewriteInsertRows(node, node.Rows, func(newNode, parent SQLNode) { parent.(*Insert).Rows = newNode.(InsertRows) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfInsertRowAlias) + } if !a.rewriteRefOfRowAlias(node, node.RowAlias, func(newNode, parent SQLNode) { parent.(*Insert).RowAlias = newNode.(*RowAlias) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfInsertOnDup) + } if !a.rewriteOnDup(node, node.OnDup, func(newNode, parent SQLNode) { parent.(*Insert).OnDup = newNode.(OnDup) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -3949,26 +4850,43 @@ func (a *application) rewriteRefOfInsertExpr(parent SQLNode, node *InsertExpr, r return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfInsertExprStr) + } if !a.rewriteExpr(node, node.Str, func(newNode, parent SQLNode) { parent.(*InsertExpr).Str = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfInsertExprPos) + } if !a.rewriteExpr(node, node.Pos, func(newNode, parent SQLNode) { parent.(*InsertExpr).Pos = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfInsertExprLen) + } if !a.rewriteExpr(node, node.Len, func(newNode, parent SQLNode) { parent.(*InsertExpr).Len = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfInsertExprNewStr) + } if !a.rewriteExpr(node, node.NewStr, func(newNode, parent SQLNode) { parent.(*InsertExpr).NewStr = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -3996,16 +4914,26 @@ func (a *application) rewriteRefOfIntervalDateExpr(parent SQLNode, node *Interva return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfIntervalDateExprDate) + } if !a.rewriteExpr(node, node.Date, func(newNode, parent SQLNode) { parent.(*IntervalDateExpr).Date = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfIntervalDateExprInterval) + } if !a.rewriteExpr(node, node.Interval, func(newNode, parent SQLNode) { parent.(*IntervalDateExpr).Interval = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -4033,16 +4961,27 @@ func (a *application) rewriteRefOfIntervalFuncExpr(parent SQLNode, node *Interva return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfIntervalFuncExprExpr) + } if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { parent.(*IntervalFuncExpr).Expr = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfIntervalFuncExprExprs) + } if !a.rewriteExprs(node, node.Exprs, func(newNode, parent SQLNode) { parent.(*IntervalFuncExpr).Exprs = newNode.(Exprs) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -4070,11 +5009,18 @@ func (a *application) rewriteRefOfIntroducerExpr(parent SQLNode, node *Introduce return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfIntroducerExprExpr) + } if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { parent.(*IntroducerExpr).Expr = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -4102,11 +5048,19 @@ func (a *application) rewriteRefOfIsExpr(parent SQLNode, node *IsExpr, replacer return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfIsExprLeft) + } if !a.rewriteExpr(node, node.Left, func(newNode, parent SQLNode) { parent.(*IsExpr).Left = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -4134,16 +5088,27 @@ func (a *application) rewriteRefOfJSONArrayAgg(parent SQLNode, node *JSONArrayAg return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfJSONArrayAggExpr) + } if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { parent.(*JSONArrayAgg).Expr = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfJSONArrayAggOverClause) + } if !a.rewriteRefOfOverClause(node, node.OverClause, func(newNode, parent SQLNode) { parent.(*JSONArrayAgg).OverClause = newNode.(*OverClause) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -4171,11 +5136,19 @@ func (a *application) rewriteRefOfJSONArrayExpr(parent SQLNode, node *JSONArrayE return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfJSONArrayExprParams) + } if !a.rewriteExprs(node, node.Params, func(newNode, parent SQLNode) { parent.(*JSONArrayExpr).Params = newNode.(Exprs) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -4203,16 +5176,26 @@ func (a *application) rewriteRefOfJSONAttributesExpr(parent SQLNode, node *JSONA return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfJSONAttributesExprJSONDoc) + } if !a.rewriteExpr(node, node.JSONDoc, func(newNode, parent SQLNode) { parent.(*JSONAttributesExpr).JSONDoc = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfJSONAttributesExprPath) + } if !a.rewriteExpr(node, node.Path, func(newNode, parent SQLNode) { parent.(*JSONAttributesExpr).Path = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -4240,11 +5223,19 @@ func (a *application) rewriteRefOfJSONContainsExpr(parent SQLNode, node *JSONCon return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfJSONContainsExprTarget) + } if !a.rewriteExpr(node, node.Target, func(newNode, parent SQLNode) { parent.(*JSONContainsExpr).Target = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfJSONContainsExprCandidate) + } if !a.rewriteExpr(node, node.Candidate, func(newNode, parent SQLNode) { parent.(*JSONContainsExpr).Candidate = newNode.(Expr) }) { @@ -4259,6 +5250,9 @@ func (a *application) rewriteRefOfJSONContainsExpr(parent SQLNode, node *JSONCon return false } } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -4286,11 +5280,19 @@ func (a *application) rewriteRefOfJSONContainsPathExpr(parent SQLNode, node *JSO return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfJSONContainsPathExprJSONDoc) + } if !a.rewriteExpr(node, node.JSONDoc, func(newNode, parent SQLNode) { parent.(*JSONContainsPathExpr).JSONDoc = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfJSONContainsPathExprOneOrAll) + } if !a.rewriteExpr(node, node.OneOrAll, func(newNode, parent SQLNode) { parent.(*JSONContainsPathExpr).OneOrAll = newNode.(Expr) }) { @@ -4305,6 +5307,9 @@ func (a *application) rewriteRefOfJSONContainsPathExpr(parent SQLNode, node *JSO return false } } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -4332,6 +5337,11 @@ func (a *application) rewriteRefOfJSONExtractExpr(parent SQLNode, node *JSONExtr return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfJSONExtractExprJSONDoc) + } if !a.rewriteExpr(node, node.JSONDoc, func(newNode, parent SQLNode) { parent.(*JSONExtractExpr).JSONDoc = newNode.(Expr) }) { @@ -4346,6 +5356,9 @@ func (a *application) rewriteRefOfJSONExtractExpr(parent SQLNode, node *JSONExtr return false } } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -4373,16 +5386,27 @@ func (a *application) rewriteRefOfJSONKeysExpr(parent SQLNode, node *JSONKeysExp return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfJSONKeysExprJSONDoc) + } if !a.rewriteExpr(node, node.JSONDoc, func(newNode, parent SQLNode) { parent.(*JSONKeysExpr).JSONDoc = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfJSONKeysExprPath) + } if !a.rewriteExpr(node, node.Path, func(newNode, parent SQLNode) { parent.(*JSONKeysExpr).Path = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -4410,21 +5434,35 @@ func (a *application) rewriteRefOfJSONObjectAgg(parent SQLNode, node *JSONObject return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfJSONObjectAggKey) + } if !a.rewriteExpr(node, node.Key, func(newNode, parent SQLNode) { parent.(*JSONObjectAgg).Key = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfJSONObjectAggValue) + } if !a.rewriteExpr(node, node.Value, func(newNode, parent SQLNode) { parent.(*JSONObjectAgg).Value = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfJSONObjectAggOverClause) + } if !a.rewriteRefOfOverClause(node, node.OverClause, func(newNode, parent SQLNode) { parent.(*JSONObjectAgg).OverClause = newNode.(*OverClause) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -4452,6 +5490,7 @@ func (a *application) rewriteRefOfJSONObjectExpr(parent SQLNode, node *JSONObjec return true } } + var path ASTPath for x, el := range node.Params { if !a.rewriteRefOfJSONObjectParam(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { @@ -4461,6 +5500,9 @@ func (a *application) rewriteRefOfJSONObjectExpr(parent SQLNode, node *JSONObjec return false } } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -4483,16 +5525,27 @@ func (a *application) rewriteRefOfJSONObjectParam(parent SQLNode, node *JSONObje return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfJSONObjectParamKey) + } if !a.rewriteExpr(node, node.Key, func(newNode, parent SQLNode) { parent.(*JSONObjectParam).Key = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfJSONObjectParamValue) + } if !a.rewriteExpr(node, node.Value, func(newNode, parent SQLNode) { parent.(*JSONObjectParam).Value = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -4520,16 +5573,27 @@ func (a *application) rewriteRefOfJSONOverlapsExpr(parent SQLNode, node *JSONOve return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfJSONOverlapsExprJSONDoc1) + } if !a.rewriteExpr(node, node.JSONDoc1, func(newNode, parent SQLNode) { parent.(*JSONOverlapsExpr).JSONDoc1 = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfJSONOverlapsExprJSONDoc2) + } if !a.rewriteExpr(node, node.JSONDoc2, func(newNode, parent SQLNode) { parent.(*JSONOverlapsExpr).JSONDoc2 = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -4557,11 +5621,19 @@ func (a *application) rewriteRefOfJSONPrettyExpr(parent SQLNode, node *JSONPrett return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfJSONPrettyExprJSONVal) + } if !a.rewriteExpr(node, node.JSONVal, func(newNode, parent SQLNode) { parent.(*JSONPrettyExpr).JSONVal = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -4589,11 +5661,19 @@ func (a *application) rewriteRefOfJSONQuoteExpr(parent SQLNode, node *JSONQuoteE return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfJSONQuoteExprStringArg) + } if !a.rewriteExpr(node, node.StringArg, func(newNode, parent SQLNode) { parent.(*JSONQuoteExpr).StringArg = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -4621,16 +5701,27 @@ func (a *application) rewriteRefOfJSONRemoveExpr(parent SQLNode, node *JSONRemov return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfJSONRemoveExprJSONDoc) + } if !a.rewriteExpr(node, node.JSONDoc, func(newNode, parent SQLNode) { parent.(*JSONRemoveExpr).JSONDoc = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfJSONRemoveExprPathList) + } if !a.rewriteExprs(node, node.PathList, func(newNode, parent SQLNode) { parent.(*JSONRemoveExpr).PathList = newNode.(Exprs) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -4658,16 +5749,27 @@ func (a *application) rewriteRefOfJSONSchemaValidFuncExpr(parent SQLNode, node * return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfJSONSchemaValidFuncExprSchema) + } if !a.rewriteExpr(node, node.Schema, func(newNode, parent SQLNode) { parent.(*JSONSchemaValidFuncExpr).Schema = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfJSONSchemaValidFuncExprDocument) + } if !a.rewriteExpr(node, node.Document, func(newNode, parent SQLNode) { parent.(*JSONSchemaValidFuncExpr).Document = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -4695,16 +5797,27 @@ func (a *application) rewriteRefOfJSONSchemaValidationReportFuncExpr(parent SQLN return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfJSONSchemaValidationReportFuncExprSchema) + } if !a.rewriteExpr(node, node.Schema, func(newNode, parent SQLNode) { parent.(*JSONSchemaValidationReportFuncExpr).Schema = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfJSONSchemaValidationReportFuncExprDocument) + } if !a.rewriteExpr(node, node.Document, func(newNode, parent SQLNode) { parent.(*JSONSchemaValidationReportFuncExpr).Document = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -4732,21 +5845,35 @@ func (a *application) rewriteRefOfJSONSearchExpr(parent SQLNode, node *JSONSearc return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfJSONSearchExprJSONDoc) + } if !a.rewriteExpr(node, node.JSONDoc, func(newNode, parent SQLNode) { parent.(*JSONSearchExpr).JSONDoc = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfJSONSearchExprOneOrAll) + } if !a.rewriteExpr(node, node.OneOrAll, func(newNode, parent SQLNode) { parent.(*JSONSearchExpr).OneOrAll = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfJSONSearchExprSearchStr) + } if !a.rewriteExpr(node, node.SearchStr, func(newNode, parent SQLNode) { parent.(*JSONSearchExpr).SearchStr = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfJSONSearchExprEscapeChar) + } if !a.rewriteExpr(node, node.EscapeChar, func(newNode, parent SQLNode) { parent.(*JSONSearchExpr).EscapeChar = newNode.(Expr) }) { @@ -4761,6 +5888,9 @@ func (a *application) rewriteRefOfJSONSearchExpr(parent SQLNode, node *JSONSearc return false } } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -4788,11 +5918,19 @@ func (a *application) rewriteRefOfJSONStorageFreeExpr(parent SQLNode, node *JSON return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfJSONStorageFreeExprJSONVal) + } if !a.rewriteExpr(node, node.JSONVal, func(newNode, parent SQLNode) { parent.(*JSONStorageFreeExpr).JSONVal = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -4820,11 +5958,19 @@ func (a *application) rewriteRefOfJSONStorageSizeExpr(parent SQLNode, node *JSON return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfJSONStorageSizeExprJSONVal) + } if !a.rewriteExpr(node, node.JSONVal, func(newNode, parent SQLNode) { parent.(*JSONStorageSizeExpr).JSONVal = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -4847,16 +5993,27 @@ func (a *application) rewriteRefOfJSONTableExpr(parent SQLNode, node *JSONTableE return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfJSONTableExprExpr) + } if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { parent.(*JSONTableExpr).Expr = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfJSONTableExprAlias) + } if !a.rewriteIdentifierCS(node, node.Alias, func(newNode, parent SQLNode) { parent.(*JSONTableExpr).Alias = newNode.(IdentifierCS) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfJSONTableExprFilter) + } if !a.rewriteExpr(node, node.Filter, func(newNode, parent SQLNode) { parent.(*JSONTableExpr).Filter = newNode.(Expr) }) { @@ -4871,6 +6028,9 @@ func (a *application) rewriteRefOfJSONTableExpr(parent SQLNode, node *JSONTableE return false } } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -4898,11 +6058,19 @@ func (a *application) rewriteRefOfJSONUnquoteExpr(parent SQLNode, node *JSONUnqu return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfJSONUnquoteExprJSONValue) + } if !a.rewriteExpr(node, node.JSONValue, func(newNode, parent SQLNode) { parent.(*JSONUnquoteExpr).JSONValue = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -4930,31 +6098,51 @@ func (a *application) rewriteRefOfJSONValueExpr(parent SQLNode, node *JSONValueE return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfJSONValueExprJSONDoc) + } if !a.rewriteExpr(node, node.JSONDoc, func(newNode, parent SQLNode) { parent.(*JSONValueExpr).JSONDoc = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfJSONValueExprPath) + } if !a.rewriteExpr(node, node.Path, func(newNode, parent SQLNode) { parent.(*JSONValueExpr).Path = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfJSONValueExprReturningType) + } if !a.rewriteRefOfConvertType(node, node.ReturningType, func(newNode, parent SQLNode) { parent.(*JSONValueExpr).ReturningType = newNode.(*ConvertType) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfJSONValueExprEmptyOnResponse) + } if !a.rewriteRefOfJtOnResponse(node, node.EmptyOnResponse, func(newNode, parent SQLNode) { parent.(*JSONValueExpr).EmptyOnResponse = newNode.(*JtOnResponse) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfJSONValueExprErrorOnResponse) + } if !a.rewriteRefOfJtOnResponse(node, node.ErrorOnResponse, func(newNode, parent SQLNode) { parent.(*JSONValueExpr).ErrorOnResponse = newNode.(*JtOnResponse) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -4982,16 +6170,26 @@ func (a *application) rewriteRefOfJSONValueMergeExpr(parent SQLNode, node *JSONV return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfJSONValueMergeExprJSONDoc) + } if !a.rewriteExpr(node, node.JSONDoc, func(newNode, parent SQLNode) { parent.(*JSONValueMergeExpr).JSONDoc = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfJSONValueMergeExprJSONDocList) + } if !a.rewriteExprs(node, node.JSONDocList, func(newNode, parent SQLNode) { parent.(*JSONValueMergeExpr).JSONDocList = newNode.(Exprs) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -5019,6 +6217,10 @@ func (a *application) rewriteRefOfJSONValueModifierExpr(parent SQLNode, node *JS return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfJSONValueModifierExprJSONDoc) + } if !a.rewriteExpr(node, node.JSONDoc, func(newNode, parent SQLNode) { parent.(*JSONValueModifierExpr).JSONDoc = newNode.(Expr) }) { @@ -5033,6 +6235,9 @@ func (a *application) rewriteRefOfJSONValueModifierExpr(parent SQLNode, node *JS return false } } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -5055,16 +6260,27 @@ func (a *application) rewriteRefOfJoinCondition(parent SQLNode, node *JoinCondit return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfJoinConditionOn) + } if !a.rewriteExpr(node, node.On, func(newNode, parent SQLNode) { parent.(*JoinCondition).On = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfJoinConditionUsing) + } if !a.rewriteColumns(node, node.Using, func(newNode, parent SQLNode) { parent.(*JoinCondition).Using = newNode.(Columns) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -5087,21 +6303,35 @@ func (a *application) rewriteRefOfJoinTableExpr(parent SQLNode, node *JoinTableE return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfJoinTableExprLeftExpr) + } if !a.rewriteTableExpr(node, node.LeftExpr, func(newNode, parent SQLNode) { parent.(*JoinTableExpr).LeftExpr = newNode.(TableExpr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfJoinTableExprRightExpr) + } if !a.rewriteTableExpr(node, node.RightExpr, func(newNode, parent SQLNode) { parent.(*JoinTableExpr).RightExpr = newNode.(TableExpr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfJoinTableExprCondition) + } if !a.rewriteRefOfJoinCondition(node, node.Condition, func(newNode, parent SQLNode) { parent.(*JoinTableExpr).Condition = newNode.(*JoinCondition) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -5148,11 +6378,18 @@ func (a *application) rewriteRefOfJtOnResponse(parent SQLNode, node *JtOnRespons return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfJtOnResponseExpr) + } if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { parent.(*JtOnResponse).Expr = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -5228,31 +6465,50 @@ func (a *application) rewriteRefOfLagLeadExpr(parent SQLNode, node *LagLeadExpr, return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfLagLeadExprExpr) + } if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { parent.(*LagLeadExpr).Expr = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfLagLeadExprN) + } if !a.rewriteExpr(node, node.N, func(newNode, parent SQLNode) { parent.(*LagLeadExpr).N = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfLagLeadExprDefault) + } if !a.rewriteExpr(node, node.Default, func(newNode, parent SQLNode) { parent.(*LagLeadExpr).Default = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfLagLeadExprOverClause) + } if !a.rewriteRefOfOverClause(node, node.OverClause, func(newNode, parent SQLNode) { parent.(*LagLeadExpr).OverClause = newNode.(*OverClause) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfLagLeadExprNullTreatmentClause) + } if !a.rewriteRefOfNullTreatmentClause(node, node.NullTreatmentClause, func(newNode, parent SQLNode) { parent.(*LagLeadExpr).NullTreatmentClause = newNode.(*NullTreatmentClause) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -5275,16 +6531,27 @@ func (a *application) rewriteRefOfLimit(parent SQLNode, node *Limit, replacer re return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfLimitOffset) + } if !a.rewriteExpr(node, node.Offset, func(newNode, parent SQLNode) { parent.(*Limit).Offset = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfLimitRowcount) + } if !a.rewriteExpr(node, node.Rowcount, func(newNode, parent SQLNode) { parent.(*Limit).Rowcount = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -5312,11 +6579,19 @@ func (a *application) rewriteRefOfLineStringExpr(parent SQLNode, node *LineStrin return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfLineStringExprPointParams) + } if !a.rewriteExprs(node, node.PointParams, func(newNode, parent SQLNode) { parent.(*LineStringExpr).PointParams = newNode.(Exprs) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -5344,16 +6619,26 @@ func (a *application) rewriteRefOfLinestrPropertyFuncExpr(parent SQLNode, node * return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfLinestrPropertyFuncExprLinestring) + } if !a.rewriteExpr(node, node.Linestring, func(newNode, parent SQLNode) { parent.(*LinestrPropertyFuncExpr).Linestring = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfLinestrPropertyFuncExprPropertyDefArg) + } if !a.rewriteExpr(node, node.PropertyDefArg, func(newNode, parent SQLNode) { parent.(*LinestrPropertyFuncExpr).PropertyDefArg = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -5434,21 +6719,35 @@ func (a *application) rewriteRefOfLocateExpr(parent SQLNode, node *LocateExpr, r return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfLocateExprSubStr) + } if !a.rewriteExpr(node, node.SubStr, func(newNode, parent SQLNode) { parent.(*LocateExpr).SubStr = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfLocateExprStr) + } if !a.rewriteExpr(node, node.Str, func(newNode, parent SQLNode) { parent.(*LocateExpr).Str = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfLocateExprPos) + } if !a.rewriteExpr(node, node.Pos, func(newNode, parent SQLNode) { parent.(*LocateExpr).Pos = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -5524,16 +6823,26 @@ func (a *application) rewriteRefOfLockingFunc(parent SQLNode, node *LockingFunc, return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfLockingFuncName) + } if !a.rewriteExpr(node, node.Name, func(newNode, parent SQLNode) { parent.(*LockingFunc).Name = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfLockingFuncTimeout) + } if !a.rewriteExpr(node, node.Timeout, func(newNode, parent SQLNode) { parent.(*LockingFunc).Timeout = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -5561,6 +6870,7 @@ func (a *application) rewriteRefOfMatchExpr(parent SQLNode, node *MatchExpr, rep return true } } + var path ASTPath for x, el := range node.Columns { if !a.rewriteRefOfColName(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { @@ -5570,11 +6880,17 @@ func (a *application) rewriteRefOfMatchExpr(parent SQLNode, node *MatchExpr, rep return false } } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfMatchExprExpr) + } if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { parent.(*MatchExpr).Expr = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -5602,16 +6918,27 @@ func (a *application) rewriteRefOfMax(parent SQLNode, node *Max, replacer replac return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfMaxArg) + } if !a.rewriteExpr(node, node.Arg, func(newNode, parent SQLNode) { parent.(*Max).Arg = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfMaxOverClause) + } if !a.rewriteRefOfOverClause(node, node.OverClause, func(newNode, parent SQLNode) { parent.(*Max).OverClause = newNode.(*OverClause) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -5639,16 +6966,27 @@ func (a *application) rewriteRefOfMemberOfExpr(parent SQLNode, node *MemberOfExp return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfMemberOfExprValue) + } if !a.rewriteExpr(node, node.Value, func(newNode, parent SQLNode) { parent.(*MemberOfExpr).Value = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfMemberOfExprJSONArr) + } if !a.rewriteExpr(node, node.JSONArr, func(newNode, parent SQLNode) { parent.(*MemberOfExpr).JSONArr = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -5676,16 +7014,27 @@ func (a *application) rewriteRefOfMin(parent SQLNode, node *Min, replacer replac return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfMinArg) + } if !a.rewriteExpr(node, node.Arg, func(newNode, parent SQLNode) { parent.(*Min).Arg = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfMinOverClause) + } if !a.rewriteRefOfOverClause(node, node.OverClause, func(newNode, parent SQLNode) { parent.(*Min).OverClause = newNode.(*OverClause) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -5708,16 +7057,27 @@ func (a *application) rewriteRefOfModifyColumn(parent SQLNode, node *ModifyColum return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfModifyColumnNewColDefinition) + } if !a.rewriteRefOfColumnDefinition(node, node.NewColDefinition, func(newNode, parent SQLNode) { parent.(*ModifyColumn).NewColDefinition = newNode.(*ColumnDefinition) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfModifyColumnAfter) + } if !a.rewriteRefOfColName(node, node.After, func(newNode, parent SQLNode) { parent.(*ModifyColumn).After = newNode.(*ColName) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -5745,11 +7105,19 @@ func (a *application) rewriteRefOfMultiLinestringExpr(parent SQLNode, node *Mult return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfMultiLinestringExprLinestringParams) + } if !a.rewriteExprs(node, node.LinestringParams, func(newNode, parent SQLNode) { parent.(*MultiLinestringExpr).LinestringParams = newNode.(Exprs) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -5777,11 +7145,19 @@ func (a *application) rewriteRefOfMultiPointExpr(parent SQLNode, node *MultiPoin return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfMultiPointExprPointParams) + } if !a.rewriteExprs(node, node.PointParams, func(newNode, parent SQLNode) { parent.(*MultiPointExpr).PointParams = newNode.(Exprs) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -5809,11 +7185,19 @@ func (a *application) rewriteRefOfMultiPolygonExpr(parent SQLNode, node *MultiPo return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfMultiPolygonExprPolygonParams) + } if !a.rewriteExprs(node, node.PolygonParams, func(newNode, parent SQLNode) { parent.(*MultiPolygonExpr).PolygonParams = newNode.(Exprs) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -5841,31 +7225,51 @@ func (a *application) rewriteRefOfNTHValueExpr(parent SQLNode, node *NTHValueExp return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfNTHValueExprExpr) + } if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { parent.(*NTHValueExpr).Expr = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfNTHValueExprN) + } if !a.rewriteExpr(node, node.N, func(newNode, parent SQLNode) { parent.(*NTHValueExpr).N = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfNTHValueExprOverClause) + } if !a.rewriteRefOfOverClause(node, node.OverClause, func(newNode, parent SQLNode) { parent.(*NTHValueExpr).OverClause = newNode.(*OverClause) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfNTHValueExprFromFirstLastClause) + } if !a.rewriteRefOfFromFirstLastClause(node, node.FromFirstLastClause, func(newNode, parent SQLNode) { parent.(*NTHValueExpr).FromFirstLastClause = newNode.(*FromFirstLastClause) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfNTHValueExprNullTreatmentClause) + } if !a.rewriteRefOfNullTreatmentClause(node, node.NullTreatmentClause, func(newNode, parent SQLNode) { parent.(*NTHValueExpr).NullTreatmentClause = newNode.(*NullTreatmentClause) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -5893,11 +7297,19 @@ func (a *application) rewriteRefOfNamedWindow(parent SQLNode, node *NamedWindow, return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfNamedWindowWindows) + } if !a.rewriteWindowDefinitions(node, node.Windows, func(newNode, parent SQLNode) { parent.(*NamedWindow).Windows = newNode.(WindowDefinitions) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -5957,11 +7369,19 @@ func (a *application) rewriteRefOfNextval(parent SQLNode, node *Nextval, replace return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfNextvalExpr) + } if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { parent.(*Nextval).Expr = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -5989,11 +7409,19 @@ func (a *application) rewriteRefOfNotExpr(parent SQLNode, node *NotExpr, replace return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfNotExprExpr) + } if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { parent.(*NotExpr).Expr = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -6021,16 +7449,27 @@ func (a *application) rewriteRefOfNtileExpr(parent SQLNode, node *NtileExpr, rep return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfNtileExprN) + } if !a.rewriteExpr(node, node.N, func(newNode, parent SQLNode) { parent.(*NtileExpr).N = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfNtileExprOverClause) + } if !a.rewriteRefOfOverClause(node, node.OverClause, func(newNode, parent SQLNode) { parent.(*NtileExpr).OverClause = newNode.(*OverClause) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -6111,11 +7550,18 @@ func (a *application) rewriteRefOfOffset(parent SQLNode, node *Offset, replacer return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfOffsetOriginal) + } if !a.rewriteExpr(node, node.Original, func(newNode, parent SQLNode) { parent.(*Offset).Original = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -6175,11 +7621,19 @@ func (a *application) rewriteRefOfOptLike(parent SQLNode, node *OptLike, replace return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfOptLikeLikeTable) + } if !a.rewriteTableName(node, node.LikeTable, func(newNode, parent SQLNode) { parent.(*OptLike).LikeTable = newNode.(TableName) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -6207,16 +7661,27 @@ func (a *application) rewriteRefOfOrExpr(parent SQLNode, node *OrExpr, replacer return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfOrExprLeft) + } if !a.rewriteExpr(node, node.Left, func(newNode, parent SQLNode) { parent.(*OrExpr).Left = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfOrExprRight) + } if !a.rewriteExpr(node, node.Right, func(newNode, parent SQLNode) { parent.(*OrExpr).Right = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -6239,11 +7704,19 @@ func (a *application) rewriteRefOfOrder(parent SQLNode, node *Order, replacer re return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfOrderExpr) + } if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { parent.(*Order).Expr = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -6303,11 +7776,19 @@ func (a *application) rewriteRefOfOrderByOption(parent SQLNode, node *OrderByOpt return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfOrderByOptionCols) + } if !a.rewriteColumns(node, node.Cols, func(newNode, parent SQLNode) { parent.(*OrderByOption).Cols = newNode.(Columns) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -6354,16 +7835,27 @@ func (a *application) rewriteRefOfOverClause(parent SQLNode, node *OverClause, r return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfOverClauseWindowName) + } if !a.rewriteIdentifierCI(node, node.WindowName, func(newNode, parent SQLNode) { parent.(*OverClause).WindowName = newNode.(IdentifierCI) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfOverClauseWindowSpec) + } if !a.rewriteRefOfWindowSpecification(node, node.WindowSpec, func(newNode, parent SQLNode) { parent.(*OverClause).WindowSpec = newNode.(*WindowSpecification) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -6386,11 +7878,19 @@ func (a *application) rewriteRefOfParenTableExpr(parent SQLNode, node *ParenTabl return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfParenTableExprExprs) + } if !a.rewriteTableExprs(node, node.Exprs, func(newNode, parent SQLNode) { parent.(*ParenTableExpr).Exprs = newNode.(TableExprs) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -6437,16 +7937,27 @@ func (a *application) rewriteRefOfPartitionDefinition(parent SQLNode, node *Part return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfPartitionDefinitionName) + } if !a.rewriteIdentifierCI(node, node.Name, func(newNode, parent SQLNode) { parent.(*PartitionDefinition).Name = newNode.(IdentifierCI) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfPartitionDefinitionOptions) + } if !a.rewriteRefOfPartitionDefinitionOptions(node, node.Options, func(newNode, parent SQLNode) { parent.(*PartitionDefinition).Options = newNode.(*PartitionDefinitionOptions) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -6469,36 +7980,59 @@ func (a *application) rewriteRefOfPartitionDefinitionOptions(parent SQLNode, nod return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfPartitionDefinitionOptionsValueRange) + } if !a.rewriteRefOfPartitionValueRange(node, node.ValueRange, func(newNode, parent SQLNode) { parent.(*PartitionDefinitionOptions).ValueRange = newNode.(*PartitionValueRange) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfPartitionDefinitionOptionsComment) + } if !a.rewriteRefOfLiteral(node, node.Comment, func(newNode, parent SQLNode) { parent.(*PartitionDefinitionOptions).Comment = newNode.(*Literal) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfPartitionDefinitionOptionsEngine) + } if !a.rewriteRefOfPartitionEngine(node, node.Engine, func(newNode, parent SQLNode) { parent.(*PartitionDefinitionOptions).Engine = newNode.(*PartitionEngine) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfPartitionDefinitionOptionsDataDirectory) + } if !a.rewriteRefOfLiteral(node, node.DataDirectory, func(newNode, parent SQLNode) { parent.(*PartitionDefinitionOptions).DataDirectory = newNode.(*Literal) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfPartitionDefinitionOptionsIndexDirectory) + } if !a.rewriteRefOfLiteral(node, node.IndexDirectory, func(newNode, parent SQLNode) { parent.(*PartitionDefinitionOptions).IndexDirectory = newNode.(*Literal) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfPartitionDefinitionOptionsSubPartitionDefinitions) + } if !a.rewriteSubPartitionDefinitions(node, node.SubPartitionDefinitions, func(newNode, parent SQLNode) { parent.(*PartitionDefinitionOptions).SubPartitionDefinitions = newNode.(SubPartitionDefinitions) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -6545,16 +8079,26 @@ func (a *application) rewriteRefOfPartitionOption(parent SQLNode, node *Partitio return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfPartitionOptionColList) + } if !a.rewriteColumns(node, node.ColList, func(newNode, parent SQLNode) { parent.(*PartitionOption).ColList = newNode.(Columns) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfPartitionOptionExpr) + } if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { parent.(*PartitionOption).Expr = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfPartitionOptionSubPartition) + } if !a.rewriteRefOfSubPartition(node, node.SubPartition, func(newNode, parent SQLNode) { parent.(*PartitionOption).SubPartition = newNode.(*SubPartition) }) { @@ -6569,6 +8113,9 @@ func (a *application) rewriteRefOfPartitionOption(parent SQLNode, node *Partitio return false } } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -6591,16 +8138,26 @@ func (a *application) rewriteRefOfPartitionSpec(parent SQLNode, node *PartitionS return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfPartitionSpecNames) + } if !a.rewritePartitions(node, node.Names, func(newNode, parent SQLNode) { parent.(*PartitionSpec).Names = newNode.(Partitions) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfPartitionSpecNumber) + } if !a.rewriteRefOfLiteral(node, node.Number, func(newNode, parent SQLNode) { parent.(*PartitionSpec).Number = newNode.(*Literal) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfPartitionSpecTableName) + } if !a.rewriteTableName(node, node.TableName, func(newNode, parent SQLNode) { parent.(*PartitionSpec).TableName = newNode.(TableName) }) { @@ -6615,6 +8172,9 @@ func (a *application) rewriteRefOfPartitionSpec(parent SQLNode, node *PartitionS return false } } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -6637,11 +8197,18 @@ func (a *application) rewriteRefOfPartitionValueRange(parent SQLNode, node *Part return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfPartitionValueRangeRange) + } if !a.rewriteValTuple(node, node.Range, func(newNode, parent SQLNode) { parent.(*PartitionValueRange).Range = newNode.(ValTuple) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -6706,11 +8273,18 @@ func (a *application) rewriteRefOfPerformanceSchemaFuncExpr(parent SQLNode, node return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfPerformanceSchemaFuncExprArgument) + } if !a.rewriteExpr(node, node.Argument, func(newNode, parent SQLNode) { parent.(*PerformanceSchemaFuncExpr).Argument = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -6738,16 +8312,27 @@ func (a *application) rewriteRefOfPointExpr(parent SQLNode, node *PointExpr, rep return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfPointExprXCordinate) + } if !a.rewriteExpr(node, node.XCordinate, func(newNode, parent SQLNode) { parent.(*PointExpr).XCordinate = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfPointExprYCordinate) + } if !a.rewriteExpr(node, node.YCordinate, func(newNode, parent SQLNode) { parent.(*PointExpr).YCordinate = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -6775,16 +8360,26 @@ func (a *application) rewriteRefOfPointPropertyFuncExpr(parent SQLNode, node *Po return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfPointPropertyFuncExprPoint) + } if !a.rewriteExpr(node, node.Point, func(newNode, parent SQLNode) { parent.(*PointPropertyFuncExpr).Point = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfPointPropertyFuncExprValueToSet) + } if !a.rewriteExpr(node, node.ValueToSet, func(newNode, parent SQLNode) { parent.(*PointPropertyFuncExpr).ValueToSet = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -6812,11 +8407,19 @@ func (a *application) rewriteRefOfPolygonExpr(parent SQLNode, node *PolygonExpr, return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfPolygonExprLinestringParams) + } if !a.rewriteExprs(node, node.LinestringParams, func(newNode, parent SQLNode) { parent.(*PolygonExpr).LinestringParams = newNode.(Exprs) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -6844,16 +8447,26 @@ func (a *application) rewriteRefOfPolygonPropertyFuncExpr(parent SQLNode, node * return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfPolygonPropertyFuncExprPolygon) + } if !a.rewriteExpr(node, node.Polygon, func(newNode, parent SQLNode) { parent.(*PolygonPropertyFuncExpr).Polygon = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfPolygonPropertyFuncExprPropertyDefArg) + } if !a.rewriteExpr(node, node.PropertyDefArg, func(newNode, parent SQLNode) { parent.(*PolygonPropertyFuncExpr).PropertyDefArg = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -6876,21 +8489,35 @@ func (a *application) rewriteRefOfPrepareStmt(parent SQLNode, node *PrepareStmt, return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfPrepareStmtName) + } if !a.rewriteIdentifierCI(node, node.Name, func(newNode, parent SQLNode) { parent.(*PrepareStmt).Name = newNode.(IdentifierCI) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfPrepareStmtStatement) + } if !a.rewriteExpr(node, node.Statement, func(newNode, parent SQLNode) { parent.(*PrepareStmt).Statement = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfPrepareStmtComments) + } if !a.rewriteRefOfParsedComments(node, node.Comments, func(newNode, parent SQLNode) { parent.(*PrepareStmt).Comments = newNode.(*ParsedComments) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -6937,31 +8564,51 @@ func (a *application) rewriteRefOfReferenceDefinition(parent SQLNode, node *Refe return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfReferenceDefinitionReferencedTable) + } if !a.rewriteTableName(node, node.ReferencedTable, func(newNode, parent SQLNode) { parent.(*ReferenceDefinition).ReferencedTable = newNode.(TableName) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfReferenceDefinitionReferencedColumns) + } if !a.rewriteColumns(node, node.ReferencedColumns, func(newNode, parent SQLNode) { parent.(*ReferenceDefinition).ReferencedColumns = newNode.(Columns) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfReferenceDefinitionMatch) + } if !a.rewriteMatchAction(node, node.Match, func(newNode, parent SQLNode) { parent.(*ReferenceDefinition).Match = newNode.(MatchAction) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfReferenceDefinitionOnDelete) + } if !a.rewriteReferenceAction(node, node.OnDelete, func(newNode, parent SQLNode) { parent.(*ReferenceDefinition).OnDelete = newNode.(ReferenceAction) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfReferenceDefinitionOnUpdate) + } if !a.rewriteReferenceAction(node, node.OnUpdate, func(newNode, parent SQLNode) { parent.(*ReferenceDefinition).OnUpdate = newNode.(ReferenceAction) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -6989,36 +8636,59 @@ func (a *application) rewriteRefOfRegexpInstrExpr(parent SQLNode, node *RegexpIn return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfRegexpInstrExprExpr) + } if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { parent.(*RegexpInstrExpr).Expr = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfRegexpInstrExprPattern) + } if !a.rewriteExpr(node, node.Pattern, func(newNode, parent SQLNode) { parent.(*RegexpInstrExpr).Pattern = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfRegexpInstrExprPosition) + } if !a.rewriteExpr(node, node.Position, func(newNode, parent SQLNode) { parent.(*RegexpInstrExpr).Position = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfRegexpInstrExprOccurrence) + } if !a.rewriteExpr(node, node.Occurrence, func(newNode, parent SQLNode) { parent.(*RegexpInstrExpr).Occurrence = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfRegexpInstrExprReturnOption) + } if !a.rewriteExpr(node, node.ReturnOption, func(newNode, parent SQLNode) { parent.(*RegexpInstrExpr).ReturnOption = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfRegexpInstrExprMatchType) + } if !a.rewriteExpr(node, node.MatchType, func(newNode, parent SQLNode) { parent.(*RegexpInstrExpr).MatchType = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -7046,21 +8716,35 @@ func (a *application) rewriteRefOfRegexpLikeExpr(parent SQLNode, node *RegexpLik return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfRegexpLikeExprExpr) + } if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { parent.(*RegexpLikeExpr).Expr = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfRegexpLikeExprPattern) + } if !a.rewriteExpr(node, node.Pattern, func(newNode, parent SQLNode) { parent.(*RegexpLikeExpr).Pattern = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfRegexpLikeExprMatchType) + } if !a.rewriteExpr(node, node.MatchType, func(newNode, parent SQLNode) { parent.(*RegexpLikeExpr).MatchType = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -7088,36 +8772,59 @@ func (a *application) rewriteRefOfRegexpReplaceExpr(parent SQLNode, node *Regexp return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfRegexpReplaceExprExpr) + } if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { parent.(*RegexpReplaceExpr).Expr = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfRegexpReplaceExprPattern) + } if !a.rewriteExpr(node, node.Pattern, func(newNode, parent SQLNode) { parent.(*RegexpReplaceExpr).Pattern = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfRegexpReplaceExprRepl) + } if !a.rewriteExpr(node, node.Repl, func(newNode, parent SQLNode) { parent.(*RegexpReplaceExpr).Repl = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfRegexpReplaceExprOccurrence) + } if !a.rewriteExpr(node, node.Occurrence, func(newNode, parent SQLNode) { parent.(*RegexpReplaceExpr).Occurrence = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfRegexpReplaceExprPosition) + } if !a.rewriteExpr(node, node.Position, func(newNode, parent SQLNode) { parent.(*RegexpReplaceExpr).Position = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfRegexpReplaceExprMatchType) + } if !a.rewriteExpr(node, node.MatchType, func(newNode, parent SQLNode) { parent.(*RegexpReplaceExpr).MatchType = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -7145,31 +8852,51 @@ func (a *application) rewriteRefOfRegexpSubstrExpr(parent SQLNode, node *RegexpS return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfRegexpSubstrExprExpr) + } if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { parent.(*RegexpSubstrExpr).Expr = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfRegexpSubstrExprPattern) + } if !a.rewriteExpr(node, node.Pattern, func(newNode, parent SQLNode) { parent.(*RegexpSubstrExpr).Pattern = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfRegexpSubstrExprOccurrence) + } if !a.rewriteExpr(node, node.Occurrence, func(newNode, parent SQLNode) { parent.(*RegexpSubstrExpr).Occurrence = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfRegexpSubstrExprPosition) + } if !a.rewriteExpr(node, node.Position, func(newNode, parent SQLNode) { parent.(*RegexpSubstrExpr).Position = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfRegexpSubstrExprMatchType) + } if !a.rewriteExpr(node, node.MatchType, func(newNode, parent SQLNode) { parent.(*RegexpSubstrExpr).MatchType = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -7192,11 +8919,19 @@ func (a *application) rewriteRefOfRelease(parent SQLNode, node *Release, replace return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfReleaseName) + } if !a.rewriteIdentifierCI(node, node.Name, func(newNode, parent SQLNode) { parent.(*Release).Name = newNode.(IdentifierCI) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -7219,16 +8954,27 @@ func (a *application) rewriteRefOfRenameColumn(parent SQLNode, node *RenameColum return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfRenameColumnOldName) + } if !a.rewriteRefOfColName(node, node.OldName, func(newNode, parent SQLNode) { parent.(*RenameColumn).OldName = newNode.(*ColName) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfRenameColumnNewName) + } if !a.rewriteRefOfColName(node, node.NewName, func(newNode, parent SQLNode) { parent.(*RenameColumn).NewName = newNode.(*ColName) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -7251,16 +8997,27 @@ func (a *application) rewriteRefOfRenameIndex(parent SQLNode, node *RenameIndex, return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfRenameIndexOldName) + } if !a.rewriteIdentifierCI(node, node.OldName, func(newNode, parent SQLNode) { parent.(*RenameIndex).OldName = newNode.(IdentifierCI) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfRenameIndexNewName) + } if !a.rewriteIdentifierCI(node, node.NewName, func(newNode, parent SQLNode) { parent.(*RenameIndex).NewName = newNode.(IdentifierCI) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -7307,11 +9064,19 @@ func (a *application) rewriteRefOfRenameTableName(parent SQLNode, node *RenameTa return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfRenameTableNameTable) + } if !a.rewriteTableName(node, node.Table, func(newNode, parent SQLNode) { parent.(*RenameTableName).Table = newNode.(TableName) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -7334,11 +9099,18 @@ func (a *application) rewriteRefOfRevertMigration(parent SQLNode, node *RevertMi return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfRevertMigrationComments) + } if !a.rewriteRefOfParsedComments(node, node.Comments, func(newNode, parent SQLNode) { parent.(*RevertMigration).Comments = newNode.(*ParsedComments) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -7382,11 +9154,19 @@ func (a *application) rewriteRootNode(parent SQLNode, node RootNode, replacer re return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RootNodeSQLNode) + } if !a.rewriteSQLNode(node, node.SQLNode, func(newNode, parent SQLNode) { panic("[BUG] tried to replace 'SQLNode' on 'RootNode'") }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -7409,16 +9189,27 @@ func (a *application) rewriteRefOfRowAlias(parent SQLNode, node *RowAlias, repla return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfRowAliasTableName) + } if !a.rewriteIdentifierCS(node, node.TableName, func(newNode, parent SQLNode) { parent.(*RowAlias).TableName = newNode.(IdentifierCS) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfRowAliasColumns) + } if !a.rewriteColumns(node, node.Columns, func(newNode, parent SQLNode) { parent.(*RowAlias).Columns = newNode.(Columns) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -7441,11 +9232,19 @@ func (a *application) rewriteRefOfSRollback(parent SQLNode, node *SRollback, rep return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfSRollbackName) + } if !a.rewriteIdentifierCI(node, node.Name, func(newNode, parent SQLNode) { parent.(*SRollback).Name = newNode.(IdentifierCI) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -7468,11 +9267,19 @@ func (a *application) rewriteRefOfSavepoint(parent SQLNode, node *Savepoint, rep return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfSavepointName) + } if !a.rewriteIdentifierCI(node, node.Name, func(newNode, parent SQLNode) { parent.(*Savepoint).Name = newNode.(IdentifierCI) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -7495,6 +9302,10 @@ func (a *application) rewriteRefOfSelect(parent SQLNode, node *Select, replacer return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfSelectWith) + } if !a.rewriteRefOfWith(node, node.With, func(newNode, parent SQLNode) { parent.(*Select).With = newNode.(*With) }) { @@ -7509,51 +9320,81 @@ func (a *application) rewriteRefOfSelect(parent SQLNode, node *Select, replacer return false } } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfSelectComments) + } if !a.rewriteRefOfParsedComments(node, node.Comments, func(newNode, parent SQLNode) { parent.(*Select).Comments = newNode.(*ParsedComments) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfSelectSelectExprs) + } if !a.rewriteSelectExprs(node, node.SelectExprs, func(newNode, parent SQLNode) { parent.(*Select).SelectExprs = newNode.(SelectExprs) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfSelectWhere) + } if !a.rewriteRefOfWhere(node, node.Where, func(newNode, parent SQLNode) { parent.(*Select).Where = newNode.(*Where) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfSelectGroupBy) + } if !a.rewriteRefOfGroupBy(node, node.GroupBy, func(newNode, parent SQLNode) { parent.(*Select).GroupBy = newNode.(*GroupBy) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfSelectHaving) + } if !a.rewriteRefOfWhere(node, node.Having, func(newNode, parent SQLNode) { parent.(*Select).Having = newNode.(*Where) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfSelectWindows) + } if !a.rewriteNamedWindows(node, node.Windows, func(newNode, parent SQLNode) { parent.(*Select).Windows = newNode.(NamedWindows) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfSelectOrderBy) + } if !a.rewriteOrderBy(node, node.OrderBy, func(newNode, parent SQLNode) { parent.(*Select).OrderBy = newNode.(OrderBy) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfSelectLimit) + } if !a.rewriteRefOfLimit(node, node.Limit, func(newNode, parent SQLNode) { parent.(*Select).Limit = newNode.(*Limit) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfSelectInto) + } if !a.rewriteRefOfSelectInto(node, node.Into, func(newNode, parent SQLNode) { parent.(*Select).Into = newNode.(*SelectInto) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -7637,16 +9478,27 @@ func (a *application) rewriteRefOfSet(parent SQLNode, node *Set, replacer replac return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfSetComments) + } if !a.rewriteRefOfParsedComments(node, node.Comments, func(newNode, parent SQLNode) { parent.(*Set).Comments = newNode.(*ParsedComments) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfSetExprs) + } if !a.rewriteSetExprs(node, node.Exprs, func(newNode, parent SQLNode) { parent.(*Set).Exprs = newNode.(SetExprs) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -7669,16 +9521,27 @@ func (a *application) rewriteRefOfSetExpr(parent SQLNode, node *SetExpr, replace return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfSetExprVar) + } if !a.rewriteRefOfVariable(node, node.Var, func(newNode, parent SQLNode) { parent.(*SetExpr).Var = newNode.(*Variable) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfSetExprExpr) + } if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { parent.(*SetExpr).Expr = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -7738,11 +9601,19 @@ func (a *application) rewriteRefOfShow(parent SQLNode, node *Show, replacer repl return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfShowInternal) + } if !a.rewriteShowInternal(node, node.Internal, func(newNode, parent SQLNode) { parent.(*Show).Internal = newNode.(ShowInternal) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -7765,21 +9636,34 @@ func (a *application) rewriteRefOfShowBasic(parent SQLNode, node *ShowBasic, rep return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfShowBasicTbl) + } if !a.rewriteTableName(node, node.Tbl, func(newNode, parent SQLNode) { parent.(*ShowBasic).Tbl = newNode.(TableName) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfShowBasicDbName) + } if !a.rewriteIdentifierCS(node, node.DbName, func(newNode, parent SQLNode) { parent.(*ShowBasic).DbName = newNode.(IdentifierCS) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfShowBasicFilter) + } if !a.rewriteRefOfShowFilter(node, node.Filter, func(newNode, parent SQLNode) { parent.(*ShowBasic).Filter = newNode.(*ShowFilter) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -7802,11 +9686,18 @@ func (a *application) rewriteRefOfShowCreate(parent SQLNode, node *ShowCreate, r return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfShowCreateOp) + } if !a.rewriteTableName(node, node.Op, func(newNode, parent SQLNode) { parent.(*ShowCreate).Op = newNode.(TableName) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -7829,11 +9720,18 @@ func (a *application) rewriteRefOfShowFilter(parent SQLNode, node *ShowFilter, r return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfShowFilterFilter) + } if !a.rewriteExpr(node, node.Filter, func(newNode, parent SQLNode) { parent.(*ShowFilter).Filter = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -7856,11 +9754,18 @@ func (a *application) rewriteRefOfShowMigrationLogs(parent SQLNode, node *ShowMi return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfShowMigrationLogsComments) + } if !a.rewriteRefOfParsedComments(node, node.Comments, func(newNode, parent SQLNode) { parent.(*ShowMigrationLogs).Comments = newNode.(*ParsedComments) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -7979,11 +9884,19 @@ func (a *application) rewriteRefOfStarExpr(parent SQLNode, node *StarExpr, repla return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfStarExprTableName) + } if !a.rewriteTableName(node, node.TableName, func(newNode, parent SQLNode) { parent.(*StarExpr).TableName = newNode.(TableName) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -8011,16 +9924,27 @@ func (a *application) rewriteRefOfStd(parent SQLNode, node *Std, replacer replac return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfStdArg) + } if !a.rewriteExpr(node, node.Arg, func(newNode, parent SQLNode) { parent.(*Std).Arg = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfStdOverClause) + } if !a.rewriteRefOfOverClause(node, node.OverClause, func(newNode, parent SQLNode) { parent.(*Std).OverClause = newNode.(*OverClause) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -8048,16 +9972,27 @@ func (a *application) rewriteRefOfStdDev(parent SQLNode, node *StdDev, replacer return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfStdDevArg) + } if !a.rewriteExpr(node, node.Arg, func(newNode, parent SQLNode) { parent.(*StdDev).Arg = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfStdDevOverClause) + } if !a.rewriteRefOfOverClause(node, node.OverClause, func(newNode, parent SQLNode) { parent.(*StdDev).OverClause = newNode.(*OverClause) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -8085,16 +10020,27 @@ func (a *application) rewriteRefOfStdPop(parent SQLNode, node *StdPop, replacer return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfStdPopArg) + } if !a.rewriteExpr(node, node.Arg, func(newNode, parent SQLNode) { parent.(*StdPop).Arg = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfStdPopOverClause) + } if !a.rewriteRefOfOverClause(node, node.OverClause, func(newNode, parent SQLNode) { parent.(*StdPop).OverClause = newNode.(*OverClause) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -8122,16 +10068,27 @@ func (a *application) rewriteRefOfStdSamp(parent SQLNode, node *StdSamp, replace return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfStdSampArg) + } if !a.rewriteExpr(node, node.Arg, func(newNode, parent SQLNode) { parent.(*StdSamp).Arg = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfStdSampOverClause) + } if !a.rewriteRefOfOverClause(node, node.OverClause, func(newNode, parent SQLNode) { parent.(*StdSamp).OverClause = newNode.(*OverClause) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -8154,21 +10111,35 @@ func (a *application) rewriteRefOfStream(parent SQLNode, node *Stream, replacer return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfStreamComments) + } if !a.rewriteRefOfParsedComments(node, node.Comments, func(newNode, parent SQLNode) { parent.(*Stream).Comments = newNode.(*ParsedComments) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfStreamSelectExpr) + } if !a.rewriteSelectExpr(node, node.SelectExpr, func(newNode, parent SQLNode) { parent.(*Stream).SelectExpr = newNode.(SelectExpr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfStreamTable) + } if !a.rewriteTableName(node, node.Table, func(newNode, parent SQLNode) { parent.(*Stream).Table = newNode.(TableName) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -8191,16 +10162,26 @@ func (a *application) rewriteRefOfSubPartition(parent SQLNode, node *SubPartitio return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfSubPartitionColList) + } if !a.rewriteColumns(node, node.ColList, func(newNode, parent SQLNode) { parent.(*SubPartition).ColList = newNode.(Columns) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfSubPartitionExpr) + } if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { parent.(*SubPartition).Expr = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -8223,16 +10204,27 @@ func (a *application) rewriteRefOfSubPartitionDefinition(parent SQLNode, node *S return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfSubPartitionDefinitionName) + } if !a.rewriteIdentifierCI(node, node.Name, func(newNode, parent SQLNode) { parent.(*SubPartitionDefinition).Name = newNode.(IdentifierCI) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfSubPartitionDefinitionOptions) + } if !a.rewriteRefOfSubPartitionDefinitionOptions(node, node.Options, func(newNode, parent SQLNode) { parent.(*SubPartitionDefinition).Options = newNode.(*SubPartitionDefinitionOptions) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -8255,26 +10247,43 @@ func (a *application) rewriteRefOfSubPartitionDefinitionOptions(parent SQLNode, return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfSubPartitionDefinitionOptionsComment) + } if !a.rewriteRefOfLiteral(node, node.Comment, func(newNode, parent SQLNode) { parent.(*SubPartitionDefinitionOptions).Comment = newNode.(*Literal) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfSubPartitionDefinitionOptionsEngine) + } if !a.rewriteRefOfPartitionEngine(node, node.Engine, func(newNode, parent SQLNode) { parent.(*SubPartitionDefinitionOptions).Engine = newNode.(*PartitionEngine) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfSubPartitionDefinitionOptionsDataDirectory) + } if !a.rewriteRefOfLiteral(node, node.DataDirectory, func(newNode, parent SQLNode) { parent.(*SubPartitionDefinitionOptions).DataDirectory = newNode.(*Literal) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfSubPartitionDefinitionOptionsIndexDirectory) + } if !a.rewriteRefOfLiteral(node, node.IndexDirectory, func(newNode, parent SQLNode) { parent.(*SubPartitionDefinitionOptions).IndexDirectory = newNode.(*Literal) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -8339,11 +10348,19 @@ func (a *application) rewriteRefOfSubquery(parent SQLNode, node *Subquery, repla return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfSubquerySelect) + } if !a.rewriteTableStatement(node, node.Select, func(newNode, parent SQLNode) { parent.(*Subquery).Select = newNode.(TableStatement) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -8371,21 +10388,35 @@ func (a *application) rewriteRefOfSubstrExpr(parent SQLNode, node *SubstrExpr, r return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfSubstrExprName) + } if !a.rewriteExpr(node, node.Name, func(newNode, parent SQLNode) { parent.(*SubstrExpr).Name = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfSubstrExprFrom) + } if !a.rewriteExpr(node, node.From, func(newNode, parent SQLNode) { parent.(*SubstrExpr).From = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfSubstrExprTo) + } if !a.rewriteExpr(node, node.To, func(newNode, parent SQLNode) { parent.(*SubstrExpr).To = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -8413,16 +10444,27 @@ func (a *application) rewriteRefOfSum(parent SQLNode, node *Sum, replacer replac return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfSumArg) + } if !a.rewriteExpr(node, node.Arg, func(newNode, parent SQLNode) { parent.(*Sum).Arg = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfSumOverClause) + } if !a.rewriteRefOfOverClause(node, node.OverClause, func(newNode, parent SQLNode) { parent.(*Sum).OverClause = newNode.(*OverClause) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -8479,16 +10521,27 @@ func (a *application) rewriteTableName(parent SQLNode, node TableName, replacer return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, TableNameName) + } if !a.rewriteIdentifierCS(node, node.Name, func(newNode, parent SQLNode) { panic("[BUG] tried to replace 'Name' on 'TableName'") }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, TableNameQualifier) + } if !a.rewriteIdentifierCS(node, node.Qualifier, func(newNode, parent SQLNode) { panic("[BUG] tried to replace 'Qualifier' on 'TableName'") }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -8578,6 +10631,7 @@ func (a *application) rewriteRefOfTableSpec(parent SQLNode, node *TableSpec, rep return true } } + var path ASTPath for x, el := range node.Columns { if !a.rewriteRefOfColumnDefinition(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { @@ -8605,16 +10659,25 @@ func (a *application) rewriteRefOfTableSpec(parent SQLNode, node *TableSpec, rep return false } } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfTableSpecOptions) + } if !a.rewriteTableOptions(node, node.Options, func(newNode, parent SQLNode) { parent.(*TableSpec).Options = newNode.(TableOptions) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfTableSpecPartitionOption) + } if !a.rewriteRefOfPartitionOption(node, node.PartitionOption, func(newNode, parent SQLNode) { parent.(*TableSpec).PartitionOption = newNode.(*PartitionOption) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -8666,16 +10729,27 @@ func (a *application) rewriteRefOfTimestampDiffExpr(parent SQLNode, node *Timest return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfTimestampDiffExprExpr1) + } if !a.rewriteExpr(node, node.Expr1, func(newNode, parent SQLNode) { parent.(*TimestampDiffExpr).Expr1 = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfTimestampDiffExprExpr2) + } if !a.rewriteExpr(node, node.Expr2, func(newNode, parent SQLNode) { parent.(*TimestampDiffExpr).Expr2 = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -8703,16 +10777,26 @@ func (a *application) rewriteRefOfTrimFuncExpr(parent SQLNode, node *TrimFuncExp return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfTrimFuncExprTrimArg) + } if !a.rewriteExpr(node, node.TrimArg, func(newNode, parent SQLNode) { parent.(*TrimFuncExpr).TrimArg = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfTrimFuncExprStringArg) + } if !a.rewriteExpr(node, node.StringArg, func(newNode, parent SQLNode) { parent.(*TrimFuncExpr).StringArg = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -8735,11 +10819,19 @@ func (a *application) rewriteRefOfTruncateTable(parent SQLNode, node *TruncateTa return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfTruncateTableTable) + } if !a.rewriteTableName(node, node.Table, func(newNode, parent SQLNode) { parent.(*TruncateTable).Table = newNode.(TableName) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -8767,11 +10859,18 @@ func (a *application) rewriteRefOfUnaryExpr(parent SQLNode, node *UnaryExpr, rep return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfUnaryExprExpr) + } if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { parent.(*UnaryExpr).Expr = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -8794,36 +10893,59 @@ func (a *application) rewriteRefOfUnion(parent SQLNode, node *Union, replacer re return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfUnionWith) + } if !a.rewriteRefOfWith(node, node.With, func(newNode, parent SQLNode) { parent.(*Union).With = newNode.(*With) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfUnionLeft) + } if !a.rewriteTableStatement(node, node.Left, func(newNode, parent SQLNode) { parent.(*Union).Left = newNode.(TableStatement) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfUnionRight) + } if !a.rewriteTableStatement(node, node.Right, func(newNode, parent SQLNode) { parent.(*Union).Right = newNode.(TableStatement) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfUnionOrderBy) + } if !a.rewriteOrderBy(node, node.OrderBy, func(newNode, parent SQLNode) { parent.(*Union).OrderBy = newNode.(OrderBy) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfUnionLimit) + } if !a.rewriteRefOfLimit(node, node.Limit, func(newNode, parent SQLNode) { parent.(*Union).Limit = newNode.(*Limit) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfUnionInto) + } if !a.rewriteRefOfSelectInto(node, node.Into, func(newNode, parent SQLNode) { parent.(*Union).Into = newNode.(*SelectInto) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -8870,11 +10992,19 @@ func (a *application) rewriteRefOfUpdate(parent SQLNode, node *Update, replacer return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfUpdateWith) + } if !a.rewriteRefOfWith(node, node.With, func(newNode, parent SQLNode) { parent.(*Update).With = newNode.(*With) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfUpdateComments) + } if !a.rewriteRefOfParsedComments(node, node.Comments, func(newNode, parent SQLNode) { parent.(*Update).Comments = newNode.(*ParsedComments) }) { @@ -8889,26 +11019,41 @@ func (a *application) rewriteRefOfUpdate(parent SQLNode, node *Update, replacer return false } } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfUpdateExprs) + } if !a.rewriteUpdateExprs(node, node.Exprs, func(newNode, parent SQLNode) { parent.(*Update).Exprs = newNode.(UpdateExprs) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfUpdateWhere) + } if !a.rewriteRefOfWhere(node, node.Where, func(newNode, parent SQLNode) { parent.(*Update).Where = newNode.(*Where) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfUpdateOrderBy) + } if !a.rewriteOrderBy(node, node.OrderBy, func(newNode, parent SQLNode) { parent.(*Update).OrderBy = newNode.(OrderBy) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfUpdateLimit) + } if !a.rewriteRefOfLimit(node, node.Limit, func(newNode, parent SQLNode) { parent.(*Update).Limit = newNode.(*Limit) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -8931,16 +11076,27 @@ func (a *application) rewriteRefOfUpdateExpr(parent SQLNode, node *UpdateExpr, r return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfUpdateExprName) + } if !a.rewriteRefOfColName(node, node.Name, func(newNode, parent SQLNode) { parent.(*UpdateExpr).Name = newNode.(*ColName) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfUpdateExprExpr) + } if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { parent.(*UpdateExpr).Expr = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -9005,21 +11161,35 @@ func (a *application) rewriteRefOfUpdateXMLExpr(parent SQLNode, node *UpdateXMLE return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfUpdateXMLExprTarget) + } if !a.rewriteExpr(node, node.Target, func(newNode, parent SQLNode) { parent.(*UpdateXMLExpr).Target = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfUpdateXMLExprXPathExpr) + } if !a.rewriteExpr(node, node.XPathExpr, func(newNode, parent SQLNode) { parent.(*UpdateXMLExpr).XPathExpr = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfUpdateXMLExprNewXML) + } if !a.rewriteExpr(node, node.NewXML, func(newNode, parent SQLNode) { parent.(*UpdateXMLExpr).NewXML = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -9042,11 +11212,19 @@ func (a *application) rewriteRefOfUse(parent SQLNode, node *Use, replacer replac return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfUseDBName) + } if !a.rewriteIdentifierCS(node, node.DBName, func(newNode, parent SQLNode) { parent.(*Use).DBName = newNode.(IdentifierCS) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -9069,16 +11247,26 @@ func (a *application) rewriteRefOfVExplainStmt(parent SQLNode, node *VExplainStm return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfVExplainStmtStatement) + } if !a.rewriteStatement(node, node.Statement, func(newNode, parent SQLNode) { parent.(*VExplainStmt).Statement = newNode.(Statement) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfVExplainStmtComments) + } if !a.rewriteRefOfParsedComments(node, node.Comments, func(newNode, parent SQLNode) { parent.(*VExplainStmt).Comments = newNode.(*ParsedComments) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -9101,31 +11289,51 @@ func (a *application) rewriteRefOfVStream(parent SQLNode, node *VStream, replace return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfVStreamComments) + } if !a.rewriteRefOfParsedComments(node, node.Comments, func(newNode, parent SQLNode) { parent.(*VStream).Comments = newNode.(*ParsedComments) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfVStreamSelectExpr) + } if !a.rewriteSelectExpr(node, node.SelectExpr, func(newNode, parent SQLNode) { parent.(*VStream).SelectExpr = newNode.(SelectExpr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfVStreamTable) + } if !a.rewriteTableName(node, node.Table, func(newNode, parent SQLNode) { parent.(*VStream).Table = newNode.(TableName) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfVStreamWhere) + } if !a.rewriteRefOfWhere(node, node.Where, func(newNode, parent SQLNode) { parent.(*VStream).Where = newNode.(*Where) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfVStreamLimit) + } if !a.rewriteRefOfLimit(node, node.Limit, func(newNode, parent SQLNode) { parent.(*VStream).Limit = newNode.(*Limit) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -9251,11 +11459,19 @@ func (a *application) rewriteRefOfValuesFuncExpr(parent SQLNode, node *ValuesFun return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfValuesFuncExprName) + } if !a.rewriteRefOfColName(node, node.Name, func(newNode, parent SQLNode) { parent.(*ValuesFuncExpr).Name = newNode.(*ColName) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -9278,36 +11494,59 @@ func (a *application) rewriteRefOfValuesStatement(parent SQLNode, node *ValuesSt return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfValuesStatementWith) + } if !a.rewriteRefOfWith(node, node.With, func(newNode, parent SQLNode) { parent.(*ValuesStatement).With = newNode.(*With) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfValuesStatementRows) + } if !a.rewriteValues(node, node.Rows, func(newNode, parent SQLNode) { parent.(*ValuesStatement).Rows = newNode.(Values) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfValuesStatementListArg) + } if !a.rewriteListArg(node, node.ListArg, func(newNode, parent SQLNode) { parent.(*ValuesStatement).ListArg = newNode.(ListArg) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfValuesStatementComments) + } if !a.rewriteRefOfParsedComments(node, node.Comments, func(newNode, parent SQLNode) { parent.(*ValuesStatement).Comments = newNode.(*ParsedComments) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfValuesStatementOrder) + } if !a.rewriteOrderBy(node, node.Order, func(newNode, parent SQLNode) { parent.(*ValuesStatement).Order = newNode.(OrderBy) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfValuesStatementLimit) + } if !a.rewriteRefOfLimit(node, node.Limit, func(newNode, parent SQLNode) { parent.(*ValuesStatement).Limit = newNode.(*Limit) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -9335,16 +11574,27 @@ func (a *application) rewriteRefOfVarPop(parent SQLNode, node *VarPop, replacer return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfVarPopArg) + } if !a.rewriteExpr(node, node.Arg, func(newNode, parent SQLNode) { parent.(*VarPop).Arg = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfVarPopOverClause) + } if !a.rewriteRefOfOverClause(node, node.OverClause, func(newNode, parent SQLNode) { parent.(*VarPop).OverClause = newNode.(*OverClause) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -9372,16 +11622,27 @@ func (a *application) rewriteRefOfVarSamp(parent SQLNode, node *VarSamp, replace return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfVarSampArg) + } if !a.rewriteExpr(node, node.Arg, func(newNode, parent SQLNode) { parent.(*VarSamp).Arg = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfVarSampOverClause) + } if !a.rewriteRefOfOverClause(node, node.OverClause, func(newNode, parent SQLNode) { parent.(*VarSamp).OverClause = newNode.(*OverClause) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -9409,11 +11670,18 @@ func (a *application) rewriteRefOfVariable(parent SQLNode, node *Variable, repla return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfVariableName) + } if !a.rewriteIdentifierCI(node, node.Name, func(newNode, parent SQLNode) { parent.(*Variable).Name = newNode.(IdentifierCI) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -9441,16 +11709,27 @@ func (a *application) rewriteRefOfVariance(parent SQLNode, node *Variance, repla return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfVarianceArg) + } if !a.rewriteExpr(node, node.Arg, func(newNode, parent SQLNode) { parent.(*Variance).Arg = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfVarianceOverClause) + } if !a.rewriteRefOfOverClause(node, node.OverClause, func(newNode, parent SQLNode) { parent.(*Variance).OverClause = newNode.(*OverClause) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -9470,11 +11749,19 @@ func (a *application) rewriteVindexParam(parent SQLNode, node VindexParam, repla return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, VindexParamKey) + } if !a.rewriteIdentifierCI(node, node.Key, func(newNode, parent SQLNode) { panic("[BUG] tried to replace 'Key' on 'VindexParam'") }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -9497,11 +11784,19 @@ func (a *application) rewriteRefOfVindexSpec(parent SQLNode, node *VindexSpec, r return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfVindexSpecName) + } if !a.rewriteIdentifierCI(node, node.Name, func(newNode, parent SQLNode) { parent.(*VindexSpec).Name = newNode.(IdentifierCI) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfVindexSpecType) + } if !a.rewriteIdentifierCI(node, node.Type, func(newNode, parent SQLNode) { parent.(*VindexSpec).Type = newNode.(IdentifierCI) }) { @@ -9516,6 +11811,9 @@ func (a *application) rewriteRefOfVindexSpec(parent SQLNode, node *VindexSpec, r return false } } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -9543,16 +11841,27 @@ func (a *application) rewriteRefOfWeightStringFuncExpr(parent SQLNode, node *Wei return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfWeightStringFuncExprExpr) + } if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { parent.(*WeightStringFuncExpr).Expr = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfWeightStringFuncExprAs) + } if !a.rewriteRefOfConvertType(node, node.As, func(newNode, parent SQLNode) { parent.(*WeightStringFuncExpr).As = newNode.(*ConvertType) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -9575,16 +11884,27 @@ func (a *application) rewriteRefOfWhen(parent SQLNode, node *When, replacer repl return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfWhenCond) + } if !a.rewriteExpr(node, node.Cond, func(newNode, parent SQLNode) { parent.(*When).Cond = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfWhenVal) + } if !a.rewriteExpr(node, node.Val, func(newNode, parent SQLNode) { parent.(*When).Val = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -9607,11 +11927,18 @@ func (a *application) rewriteRefOfWhere(parent SQLNode, node *Where, replacer re return true } } + var path ASTPath + if a.collectPaths { + a.cur.current = AddStep(path, RefOfWhereExpr) + } if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { parent.(*Where).Expr = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -9634,16 +11961,27 @@ func (a *application) rewriteRefOfWindowDefinition(parent SQLNode, node *WindowD return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfWindowDefinitionName) + } if !a.rewriteIdentifierCI(node, node.Name, func(newNode, parent SQLNode) { parent.(*WindowDefinition).Name = newNode.(IdentifierCI) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfWindowDefinitionWindowSpec) + } if !a.rewriteRefOfWindowSpecification(node, node.WindowSpec, func(newNode, parent SQLNode) { parent.(*WindowDefinition).WindowSpec = newNode.(*WindowSpecification) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -9703,26 +12041,43 @@ func (a *application) rewriteRefOfWindowSpecification(parent SQLNode, node *Wind return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfWindowSpecificationName) + } if !a.rewriteIdentifierCI(node, node.Name, func(newNode, parent SQLNode) { parent.(*WindowSpecification).Name = newNode.(IdentifierCI) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfWindowSpecificationPartitionClause) + } if !a.rewriteExprs(node, node.PartitionClause, func(newNode, parent SQLNode) { parent.(*WindowSpecification).PartitionClause = newNode.(Exprs) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfWindowSpecificationOrderClause) + } if !a.rewriteOrderBy(node, node.OrderClause, func(newNode, parent SQLNode) { parent.(*WindowSpecification).OrderClause = newNode.(OrderBy) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfWindowSpecificationFrameClause) + } if !a.rewriteRefOfFrameClause(node, node.FrameClause, func(newNode, parent SQLNode) { parent.(*WindowSpecification).FrameClause = newNode.(*FrameClause) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -9745,6 +12100,7 @@ func (a *application) rewriteRefOfWith(parent SQLNode, node *With, replacer repl return true } } + var path ASTPath for x, el := range node.CTEs { if !a.rewriteRefOfCommonTableExpr(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { @@ -9754,6 +12110,9 @@ func (a *application) rewriteRefOfWith(parent SQLNode, node *With, replacer repl return false } } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -9781,16 +12140,27 @@ func (a *application) rewriteRefOfXorExpr(parent SQLNode, node *XorExpr, replace return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfXorExprLeft) + } if !a.rewriteExpr(node, node.Left, func(newNode, parent SQLNode) { parent.(*XorExpr).Left = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfXorExprRight) + } if !a.rewriteExpr(node, node.Right, func(newNode, parent SQLNode) { parent.(*XorExpr).Right = newNode.(Expr) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -10800,11 +13170,19 @@ func (a *application) rewriteRefOfRootNode(parent SQLNode, node *RootNode, repla return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfRootNodeSQLNode) + } if !a.rewriteSQLNode(node, node.SQLNode, func(newNode, parent SQLNode) { parent.(*RootNode).SQLNode = newNode.(SQLNode) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -10827,16 +13205,27 @@ func (a *application) rewriteRefOfTableName(parent SQLNode, node *TableName, rep return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfTableNameName) + } if !a.rewriteIdentifierCS(node, node.Name, func(newNode, parent SQLNode) { parent.(*TableName).Name = newNode.(IdentifierCS) }) { return false } + if a.collectPaths { + a.cur.current = AddStep(path, RefOfTableNameQualifier) + } if !a.rewriteIdentifierCS(node, node.Qualifier, func(newNode, parent SQLNode) { parent.(*TableName).Qualifier = newNode.(IdentifierCS) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -10859,11 +13248,19 @@ func (a *application) rewriteRefOfVindexParam(parent SQLNode, node *VindexParam, return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + a.cur.current = AddStep(path, RefOfVindexParamKey) + } if !a.rewriteIdentifierCI(node, node.Key, func(newNode, parent SQLNode) { parent.(*VindexParam).Key = newNode.(IdentifierCI) }) { return false } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent diff --git a/go/vt/sqlparser/rewriter_api.go b/go/vt/sqlparser/rewriter_api.go index cfcf75fa0f9..260089dd202 100644 --- a/go/vt/sqlparser/rewriter_api.go +++ b/go/vt/sqlparser/rewriter_api.go @@ -97,6 +97,7 @@ type Cursor struct { // marks that the node has been replaced, and the new node should be visited revisit bool + current ASTPath } // Node returns the current Node. @@ -142,6 +143,7 @@ type replacerFunc func(newNode, parent SQLNode) // application carries all the shared data so we can pass it around cheaply. type application struct { - pre, post ApplyFunc - cur Cursor + pre, post ApplyFunc + cur Cursor + collectPaths bool } From 557f4ea18f3648f0d3efc8dd4bafd66be63f4a36 Mon Sep 17 00:00:00 2001 From: Andres Taylor Date: Thu, 30 Jan 2025 07:47:59 +0100 Subject: [PATCH 07/13] add API and test for the path walking Signed-off-by: Andres Taylor --- go/vt/sqlparser/rewriter_api.go | 19 +++++++++++++++++-- go/vt/sqlparser/rewriter_test.go | 15 +++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/go/vt/sqlparser/rewriter_api.go b/go/vt/sqlparser/rewriter_api.go index 260089dd202..ec448162f27 100644 --- a/go/vt/sqlparser/rewriter_api.go +++ b/go/vt/sqlparser/rewriter_api.go @@ -34,6 +34,10 @@ package sqlparser // Only fields that refer to AST nodes are considered children; // i.e., fields of basic types (strings, []byte, etc.) are ignored. func Rewrite(node SQLNode, pre, post ApplyFunc) (result SQLNode) { + return rewriteNode(node, pre, post, false) +} + +func rewriteNode(node SQLNode, pre ApplyFunc, post ApplyFunc, collectPaths bool) SQLNode { parent := &RootNode{node} // this is the root-replacer, used when the user replaces the root of the ast @@ -42,8 +46,9 @@ func Rewrite(node SQLNode, pre, post ApplyFunc) (result SQLNode) { } a := &application{ - pre: pre, - post: post, + pre: pre, + post: post, + collectPaths: collectPaths, } a.rewriteSQLNode(parent, node, replacer) @@ -51,6 +56,10 @@ func Rewrite(node SQLNode, pre, post ApplyFunc) (result SQLNode) { return parent.SQLNode } +func RewriteWithPath(node SQLNode, pre, post ApplyFunc) (result SQLNode) { + return rewriteNode(node, pre, post, true) +} + // SafeRewrite does not allow replacing nodes on the down walk of the tree walking // Long term this is the only Rewrite functionality we want func SafeRewrite( @@ -139,6 +148,12 @@ func (c *Cursor) ReplaceAndRevisit(newNode SQLNode) { c.revisit = true } +// CurrentPath returns the current path that got us to the current location in the AST +// Only works if the AST walk was configured to collect path as walking +func (c *Cursor) CurrentPath() ASTPath { + return c.current +} + type replacerFunc func(newNode, parent SQLNode) // application carries all the shared data so we can pass it around cheaply. diff --git a/go/vt/sqlparser/rewriter_test.go b/go/vt/sqlparser/rewriter_test.go index 628d6fbd0a4..89dfc25cac9 100644 --- a/go/vt/sqlparser/rewriter_test.go +++ b/go/vt/sqlparser/rewriter_test.go @@ -17,6 +17,7 @@ limitations under the License. package sqlparser import ( + "fmt" "testing" "github.com/stretchr/testify/assert" @@ -65,6 +66,20 @@ func TestReplaceWorksInLaterCalls(t *testing.T) { assert.Equal(t, 2, count) } +func TestFindColNames(t *testing.T) { + // this is the tpch query #1 + q := "select l_returnflag, l_linestatus, sum(l_quantity) as sum_qty, sum(l_extendedprice) as sum_base_price, sum(l_extendedprice * (1 - l_discount)) as sum_disc_price, sum(l_extendedprice * (1 - l_discount) * (1 + l_tax)) as sum_charge, avg(l_quantity) as avg_qty, avg(l_extendedprice) as avg_price, avg(l_discount) as avg_disc, count(*) as count_order from lineitem where l_shipdate <= '1998-12-01' - interval '108' day group by l_returnflag, l_linestatus order by l_returnflag, l_linestatus" + ast, err := NewTestParser().Parse(q) + require.NoError(t, err) + RewriteWithPath(ast, nil, func(cursor *Cursor) bool { + if _, isColName := cursor.Node().(*ColName); isColName { + // TODO: actually assert something here + fmt.Println(cursor.CurrentPath().DebugString()) + } + return true + }) +} + func TestReplaceAndRevisitWorksInLaterCalls(t *testing.T) { q := "select * from tbl1" parser := NewTestParser() From 15b87f33ac7204cd2820a593b4d32021ce7af34b Mon Sep 17 00:00:00 2001 From: Andres Taylor Date: Thu, 30 Jan 2025 08:52:26 +0100 Subject: [PATCH 08/13] handle init of path variable for slices Signed-off-by: Andres Taylor --- .../asthelpergen/integration/ast_equals.go | 3 +- .../asthelpergen/integration/ast_rewrite.go | 23 +++ go/tools/asthelpergen/integration/types.go | 1 + go/tools/asthelpergen/rewrite_gen.go | 54 +++-- go/vt/sqlparser/ast_rewrite.go | 189 ++++++++++++++++++ go/vt/sqlparser/rewriter_test.go | 2 +- 6 files changed, 258 insertions(+), 14 deletions(-) diff --git a/go/tools/asthelpergen/integration/ast_equals.go b/go/tools/asthelpergen/integration/ast_equals.go index 5e7b068671c..f3a4b6da9de 100644 --- a/go/tools/asthelpergen/integration/ast_equals.go +++ b/go/tools/asthelpergen/integration/ast_equals.go @@ -191,7 +191,8 @@ func (cmp *Comparator) RefOfRefSliceContainer(a, b *RefSliceContainer) bool { if a == nil || b == nil { return false } - return cmp.SliceOfAST(a.ASTElements, b.ASTElements) && + return a.something == b.something && + cmp.SliceOfAST(a.ASTElements, b.ASTElements) && cmp.SliceOfInt(a.NotASTElements, b.NotASTElements) && cmp.SliceOfRefOfLeaf(a.ASTImplementationElements, b.ASTImplementationElements) } diff --git a/go/tools/asthelpergen/integration/ast_rewrite.go b/go/tools/asthelpergen/integration/ast_rewrite.go index d4283711792..3f14d19d814 100644 --- a/go/tools/asthelpergen/integration/ast_rewrite.go +++ b/go/tools/asthelpergen/integration/ast_rewrite.go @@ -120,6 +120,10 @@ func (a *application) rewriteInterfaceSlice(parent AST, node InterfaceSlice, rep return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + } for x, el := range node { if !a.rewriteAST(node, el, func(idx int) replacerFunc { return func(newNode, parent AST) { @@ -129,6 +133,9 @@ func (a *application) rewriteInterfaceSlice(parent AST, node InterfaceSlice, rep return false } } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -181,6 +188,10 @@ func (a *application) rewriteLeafSlice(parent AST, node LeafSlice, replacer repl return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + } for x, el := range node { if !a.rewriteRefOfLeaf(node, el, func(idx int) replacerFunc { return func(newNode, parent AST) { @@ -190,6 +201,9 @@ func (a *application) rewriteLeafSlice(parent AST, node LeafSlice, replacer repl return false } } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -280,6 +294,9 @@ func (a *application) rewriteRefOfRefSliceContainer(parent AST, node *RefSliceCo } } var path ASTPath + if a.collectPaths { + path = a.cur.current + } for x, el := range node.ASTElements { if !a.rewriteAST(node, el, func(idx int) replacerFunc { return func(newNode, parent AST) { @@ -396,6 +413,9 @@ func (a *application) rewriteValueSliceContainer(parent AST, node ValueSliceCont } } var path ASTPath + if a.collectPaths { + path = a.cur.current + } for _, el := range node.ASTElements { if !a.rewriteAST(node, el, func(newNode, parent AST) { panic("[BUG] tried to replace 'ASTElements' on 'ValueSliceContainer'") @@ -537,6 +557,9 @@ func (a *application) rewriteRefOfValueSliceContainer(parent AST, node *ValueSli } } var path ASTPath + if a.collectPaths { + path = a.cur.current + } for x, el := range node.ASTElements { if !a.rewriteAST(node, el, func(idx int) replacerFunc { return func(newNode, parent AST) { diff --git a/go/tools/asthelpergen/integration/types.go b/go/tools/asthelpergen/integration/types.go index c090a1af327..0f3e9a146db 100644 --- a/go/tools/asthelpergen/integration/types.go +++ b/go/tools/asthelpergen/integration/types.go @@ -41,6 +41,7 @@ type ( } // Container implements the interface ByRef RefSliceContainer struct { + something int // want a non-AST field first ASTElements []AST NotASTElements []int ASTImplementationElements []*Leaf diff --git a/go/tools/asthelpergen/rewrite_gen.go b/go/tools/asthelpergen/rewrite_gen.go index 951188e0a4e..d7774bb7454 100644 --- a/go/tools/asthelpergen/rewrite_gen.go +++ b/go/tools/asthelpergen/rewrite_gen.go @@ -197,23 +197,40 @@ func (r *rewriteGen) sliceMethod(t types.Type, slice *types.Slice, spi generator jen.If(jen.Id("kontinue").Block(jen.Return(jen.True()))), ) - stmts = append(stmts, jen.If(jen.Id("a.pre!= nil").Block(preStmts...))) + stmts = append(stmts, jen.If(jen.Id("a.pre != nil").Block(preStmts...))) haveChildren := false if shouldAdd(slice.Elem(), spi.iface()) { /* + var path ASTPath + if a.collectPaths { + path = a.cur.current + } for i, el := range node { - if err := rewriteRefOfLeaf(node, el, func(newNode, parent AST) { - parent.(LeafSlice)[i] = newNode.(*Leaf) - }, pre, post); err != nil { - return err - } - } + if err := rewriteRefOfLeaf(node, el, func(newNode, parent AST) { + parent.(LeafSlice)[i] = newNode.(*Leaf) + }, pre, post); err != nil { + return err + } + } */ haveChildren = true + forBlock := []jen.Code{ + jen.Var().Id("path").Id("ASTPath"), + jen.If(jen.Id("a.collectPaths")).Block( + jen.Id("path").Op("=").Id("a.cur.current"), + ), + } + stmts = append(stmts, forBlock...) + rewriteChild := r.rewriteChildSlice(t, slice.Elem(), "notUsed", jen.Id("el"), jen.Index(jen.Id("idx")), false, 0) + stmts = append(stmts, jen.For(jen.Id("x, el").Op(":=").Id("range node")). - Block(r.rewriteChildSlice(t, slice.Elem(), "notUsed", jen.Id("el"), jen.Index(jen.Id("idx")), false))) + Block(rewriteChild...)) + + stmts = append(stmts, jen.If(jen.Id("a.collectPaths")).Block( + jen.Id("a.cur.current").Op("=").Id("path"), + )) } stmts = append(stmts, executePost(haveChildren)) @@ -298,16 +315,26 @@ func (r *rewriteGen) rewriteAllStructFields(t types.Type, strct *types.Struct, s */ var output []jen.Code + fieldNumber := 0 for i := 0; i < strct.NumFields(); i++ { field := strct.Field(i) if types.Implements(field.Type(), spi.iface()) { spi.addType(field.Type()) - rewriteLines := r.rewriteChild(t, field.Type(), field.Name(), jen.Id("node").Dot(field.Name()), jen.Dot(field.Name()), fail, i) + rewriteLines := r.rewriteChild(t, field.Type(), field.Name(), jen.Id("node").Dot(field.Name()), jen.Dot(field.Name()), fail, fieldNumber) + fieldNumber++ output = append(output, rewriteLines...) continue } slice, isSlice := field.Type().(*types.Slice) if isSlice && types.Implements(slice.Elem(), spi.iface()) { + if fieldNumber == 0 { + // if this is the first field we are dealing with, we need to store the incoming + // path into the local variable first of all + // if a.collectPaths { path = a.cur.current } + output = append(output, + jen.If(jen.Id("a.collectPaths")).Block(jen.Id("path").Op("=").Id("a.cur.current"))) + } + spi.addType(slice.Elem()) id := jen.Id("x") if fail { @@ -315,7 +342,8 @@ func (r *rewriteGen) rewriteAllStructFields(t types.Type, strct *types.Struct, s } output = append(output, jen.For(jen.List(id, jen.Id("el")).Op(":=").Id("range node."+field.Name())). - Block(r.rewriteChildSlice(t, slice.Elem(), field.Name(), jen.Id("el"), jen.Dot(field.Name()).Index(jen.Id("idx")), fail))) + Block(r.rewriteChildSlice(t, slice.Elem(), field.Name(), jen.Id("el"), jen.Dot(field.Name()).Index(jen.Id("idx")), fail, fieldNumber)...)) + fieldNumber++ } } return output @@ -380,7 +408,7 @@ func (r *rewriteGen) rewriteChild(t, field types.Type, fieldName string, param j } } -func (r *rewriteGen) rewriteChildSlice(t, field types.Type, fieldName string, param jen.Code, replace jen.Code, fail bool) jen.Code { +func (r *rewriteGen) rewriteChildSlice(t, field types.Type, fieldName string, param jen.Code, replace jen.Code, fail bool, fieldOffset int) []jen.Code { /* if errF := a.rewriteAST(node, el, func(idx int) replacerFunc { return func(newNode, parent AST) { @@ -416,7 +444,9 @@ func (r *rewriteGen) rewriteChildSlice(t, field types.Type, fieldName string, pa param, funcBlock).Block(returnFalse())) - return rewriteField + return []jen.Code{ + rewriteField, + } } var noQualifier = func(p *types.Package) string { diff --git a/go/vt/sqlparser/ast_rewrite.go b/go/vt/sqlparser/ast_rewrite.go index aeeaf53388e..1f06fb1b1db 100644 --- a/go/vt/sqlparser/ast_rewrite.go +++ b/go/vt/sqlparser/ast_rewrite.go @@ -582,6 +582,9 @@ func (a *application) rewriteRefOfAddColumns(parent SQLNode, node *AddColumns, r } } var path ASTPath + if a.collectPaths { + path = a.cur.current + } for x, el := range node.Columns { if !a.rewriteRefOfColumnDefinition(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { @@ -986,6 +989,7 @@ func (a *application) rewriteRefOfAlterMigration(parent SQLNode, node *AlterMigr } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfAlterMigrationRatio) } if !a.rewriteRefOfLiteral(node, node.Ratio, func(newNode, parent SQLNode) { @@ -1155,6 +1159,7 @@ func (a *application) rewriteRefOfAlterVschema(parent SQLNode, node *AlterVschem } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfAlterVschemaTable) } if !a.rewriteTableName(node, node.Table, func(newNode, parent SQLNode) { @@ -1214,6 +1219,7 @@ func (a *application) rewriteRefOfAnalyze(parent SQLNode, node *Analyze, replace } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfAnalyzeTable) } if !a.rewriteTableName(node, node.Table, func(newNode, parent SQLNode) { @@ -1370,6 +1376,7 @@ func (a *application) rewriteRefOfArgumentLessWindowExpr(parent SQLNode, node *A } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfArgumentLessWindowExprOverClause) } if !a.rewriteRefOfOverClause(node, node.OverClause, func(newNode, parent SQLNode) { @@ -1572,6 +1579,7 @@ func (a *application) rewriteRefOfBetweenExpr(parent SQLNode, node *BetweenExpr, } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfBetweenExprLeft) } if !a.rewriteExpr(node, node.Left, func(newNode, parent SQLNode) { @@ -1627,6 +1635,7 @@ func (a *application) rewriteRefOfBinaryExpr(parent SQLNode, node *BinaryExpr, r } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfBinaryExprLeft) } if !a.rewriteExpr(node, node.Left, func(newNode, parent SQLNode) { @@ -2246,6 +2255,10 @@ func (a *application) rewriteColumns(parent SQLNode, node Columns, replacer repl return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + } for x, el := range node { if !a.rewriteIdentifierCI(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { @@ -2255,6 +2268,9 @@ func (a *application) rewriteColumns(parent SQLNode, node Columns, replacer repl return false } } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -2383,6 +2399,7 @@ func (a *application) rewriteRefOfComparisonExpr(parent SQLNode, node *Compariso } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfComparisonExprLeft) } if !a.rewriteExpr(node, node.Left, func(newNode, parent SQLNode) { @@ -2641,6 +2658,7 @@ func (a *application) rewriteRefOfCountStar(parent SQLNode, node *CountStar, rep } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfCountStarOverClause) } if !a.rewriteRefOfOverClause(node, node.OverClause, func(newNode, parent SQLNode) { @@ -2718,6 +2736,7 @@ func (a *application) rewriteRefOfCreateTable(parent SQLNode, node *CreateTable, } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfCreateTableTable) } if !a.rewriteTableName(node, node.Table, func(newNode, parent SQLNode) { @@ -3071,6 +3090,7 @@ func (a *application) rewriteRefOfDerivedTable(parent SQLNode, node *DerivedTabl } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfDerivedTableSelect) } if !a.rewriteTableStatement(node, node.Select, func(newNode, parent SQLNode) { @@ -3183,6 +3203,7 @@ func (a *application) rewriteRefOfDropKey(parent SQLNode, node *DropKey, replace } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfDropKeyName) } if !a.rewriteIdentifierCI(node, node.Name, func(newNode, parent SQLNode) { @@ -3217,6 +3238,7 @@ func (a *application) rewriteRefOfDropTable(parent SQLNode, node *DropTable, rep } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfDropTableFromTables) } if !a.rewriteTableNames(node, node.FromTables, func(newNode, parent SQLNode) { @@ -3394,6 +3416,7 @@ func (a *application) rewriteRefOfExplainStmt(parent SQLNode, node *ExplainStmt, } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfExplainStmtStatement) } if !a.rewriteStatement(node, node.Statement, func(newNode, parent SQLNode) { @@ -3475,6 +3498,10 @@ func (a *application) rewriteExprs(parent SQLNode, node Exprs, replacer replacer return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + } for x, el := range node { if !a.rewriteExpr(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { @@ -3484,6 +3511,9 @@ func (a *application) rewriteExprs(parent SQLNode, node Exprs, replacer replacer return false } } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -3513,6 +3543,7 @@ func (a *application) rewriteRefOfExtractFuncExpr(parent SQLNode, node *ExtractF } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfExtractFuncExprExpr) } if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { @@ -3600,6 +3631,7 @@ func (a *application) rewriteRefOfFirstOrLastValueExpr(parent SQLNode, node *Fir } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfFirstOrLastValueExprExpr) } if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { @@ -3650,6 +3682,7 @@ func (a *application) rewriteRefOfFlush(parent SQLNode, node *Flush, replacer re } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfFlushTableNames) } if !a.rewriteTableNames(node, node.TableNames, func(newNode, parent SQLNode) { @@ -3759,6 +3792,7 @@ func (a *application) rewriteRefOfFrameClause(parent SQLNode, node *FrameClause, } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfFrameClauseStart) } if !a.rewriteRefOfFramePoint(node, node.Start, func(newNode, parent SQLNode) { @@ -3801,6 +3835,7 @@ func (a *application) rewriteRefOfFramePoint(parent SQLNode, node *FramePoint, r } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfFramePointExpr) } if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { @@ -3920,6 +3955,7 @@ func (a *application) rewriteRefOfGTIDFuncExpr(parent SQLNode, node *GTIDFuncExp } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfGTIDFuncExprSet1) } if !a.rewriteExpr(node, node.Set1, func(newNode, parent SQLNode) { @@ -4143,6 +4179,7 @@ func (a *application) rewriteRefOfGeomCollPropertyFuncExpr(parent SQLNode, node } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfGeomCollPropertyFuncExprGeomColl) } if !a.rewriteExpr(node, node.GeomColl, func(newNode, parent SQLNode) { @@ -4190,6 +4227,7 @@ func (a *application) rewriteRefOfGeomFormatExpr(parent SQLNode, node *GeomForma } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfGeomFormatExprGeom) } if !a.rewriteExpr(node, node.Geom, func(newNode, parent SQLNode) { @@ -4237,6 +4275,7 @@ func (a *application) rewriteRefOfGeomFromGeoHashExpr(parent SQLNode, node *Geom } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfGeomFromGeoHashExprGeoHash) } if !a.rewriteExpr(node, node.GeoHash, func(newNode, parent SQLNode) { @@ -4340,6 +4379,7 @@ func (a *application) rewriteRefOfGeomFromTextExpr(parent SQLNode, node *GeomFro } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfGeomFromTextExprWktText) } if !a.rewriteExpr(node, node.WktText, func(newNode, parent SQLNode) { @@ -4395,6 +4435,7 @@ func (a *application) rewriteRefOfGeomFromWKBExpr(parent SQLNode, node *GeomFrom } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfGeomFromWKBExprWkbBlob) } if !a.rewriteExpr(node, node.WkbBlob, func(newNode, parent SQLNode) { @@ -4450,6 +4491,7 @@ func (a *application) rewriteRefOfGeomPropertyFuncExpr(parent SQLNode, node *Geo } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfGeomPropertyFuncExprGeom) } if !a.rewriteExpr(node, node.Geom, func(newNode, parent SQLNode) { @@ -4483,6 +4525,9 @@ func (a *application) rewriteRefOfGroupBy(parent SQLNode, node *GroupBy, replace } } var path ASTPath + if a.collectPaths { + path = a.cur.current + } for x, el := range node.Exprs { if !a.rewriteExpr(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { @@ -4524,6 +4569,7 @@ func (a *application) rewriteRefOfGroupConcatExpr(parent SQLNode, node *GroupCon } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfGroupConcatExprExprs) } if !a.rewriteExprs(node, node.Exprs, func(newNode, parent SQLNode) { @@ -4650,6 +4696,9 @@ func (a *application) rewriteRefOfIndexHint(parent SQLNode, node *IndexHint, rep } } var path ASTPath + if a.collectPaths { + path = a.cur.current + } for x, el := range node.Indexes { if !a.rewriteIdentifierCI(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { @@ -4690,6 +4739,10 @@ func (a *application) rewriteIndexHints(parent SQLNode, node IndexHints, replace return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + } for x, el := range node { if !a.rewriteRefOfIndexHint(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { @@ -4699,6 +4752,9 @@ func (a *application) rewriteIndexHints(parent SQLNode, node IndexHints, replace return false } } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -4723,6 +4779,7 @@ func (a *application) rewriteRefOfIndexInfo(parent SQLNode, node *IndexInfo, rep } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfIndexInfoName) } if !a.rewriteIdentifierCI(node, node.Name, func(newNode, parent SQLNode) { @@ -4765,6 +4822,7 @@ func (a *application) rewriteRefOfInsert(parent SQLNode, node *Insert, replacer } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfInsertComments) } if !a.rewriteRefOfParsedComments(node, node.Comments, func(newNode, parent SQLNode) { @@ -4916,6 +4974,7 @@ func (a *application) rewriteRefOfIntervalDateExpr(parent SQLNode, node *Interva } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfIntervalDateExprDate) } if !a.rewriteExpr(node, node.Date, func(newNode, parent SQLNode) { @@ -5011,6 +5070,7 @@ func (a *application) rewriteRefOfIntroducerExpr(parent SQLNode, node *Introduce } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfIntroducerExprExpr) } if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { @@ -5178,6 +5238,7 @@ func (a *application) rewriteRefOfJSONAttributesExpr(parent SQLNode, node *JSONA } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfJSONAttributesExprJSONDoc) } if !a.rewriteExpr(node, node.JSONDoc, func(newNode, parent SQLNode) { @@ -5491,6 +5552,9 @@ func (a *application) rewriteRefOfJSONObjectExpr(parent SQLNode, node *JSONObjec } } var path ASTPath + if a.collectPaths { + path = a.cur.current + } for x, el := range node.Params { if !a.rewriteRefOfJSONObjectParam(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { @@ -6172,6 +6236,7 @@ func (a *application) rewriteRefOfJSONValueMergeExpr(parent SQLNode, node *JSONV } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfJSONValueMergeExprJSONDoc) } if !a.rewriteExpr(node, node.JSONDoc, func(newNode, parent SQLNode) { @@ -6219,6 +6284,7 @@ func (a *application) rewriteRefOfJSONValueModifierExpr(parent SQLNode, node *JS } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfJSONValueModifierExprJSONDoc) } if !a.rewriteExpr(node, node.JSONDoc, func(newNode, parent SQLNode) { @@ -6380,6 +6446,7 @@ func (a *application) rewriteRefOfJtOnResponse(parent SQLNode, node *JtOnRespons } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfJtOnResponseExpr) } if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { @@ -6467,6 +6534,7 @@ func (a *application) rewriteRefOfLagLeadExpr(parent SQLNode, node *LagLeadExpr, } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfLagLeadExprExpr) } if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { @@ -6621,6 +6689,7 @@ func (a *application) rewriteRefOfLinestrPropertyFuncExpr(parent SQLNode, node * } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfLinestrPropertyFuncExprLinestring) } if !a.rewriteExpr(node, node.Linestring, func(newNode, parent SQLNode) { @@ -6825,6 +6894,7 @@ func (a *application) rewriteRefOfLockingFunc(parent SQLNode, node *LockingFunc, } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfLockingFuncName) } if !a.rewriteExpr(node, node.Name, func(newNode, parent SQLNode) { @@ -6871,6 +6941,9 @@ func (a *application) rewriteRefOfMatchExpr(parent SQLNode, node *MatchExpr, rep } } var path ASTPath + if a.collectPaths { + path = a.cur.current + } for x, el := range node.Columns { if !a.rewriteRefOfColName(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { @@ -7338,6 +7411,10 @@ func (a *application) rewriteNamedWindows(parent SQLNode, node NamedWindows, rep return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + } for x, el := range node { if !a.rewriteRefOfNamedWindow(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { @@ -7347,6 +7424,9 @@ func (a *application) rewriteNamedWindows(parent SQLNode, node NamedWindows, rep return false } } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -7552,6 +7632,7 @@ func (a *application) rewriteRefOfOffset(parent SQLNode, node *Offset, replacer } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfOffsetOriginal) } if !a.rewriteExpr(node, node.Original, func(newNode, parent SQLNode) { @@ -7590,6 +7671,10 @@ func (a *application) rewriteOnDup(parent SQLNode, node OnDup, replacer replacer return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + } for x, el := range node { if !a.rewriteRefOfUpdateExpr(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { @@ -7599,6 +7684,9 @@ func (a *application) rewriteOnDup(parent SQLNode, node OnDup, replacer replacer return false } } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -7745,6 +7833,10 @@ func (a *application) rewriteOrderBy(parent SQLNode, node OrderBy, replacer repl return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + } for x, el := range node { if !a.rewriteRefOfOrder(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { @@ -7754,6 +7846,9 @@ func (a *application) rewriteOrderBy(parent SQLNode, node OrderBy, replacer repl return false } } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -8081,6 +8176,7 @@ func (a *application) rewriteRefOfPartitionOption(parent SQLNode, node *Partitio } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfPartitionOptionColList) } if !a.rewriteColumns(node, node.ColList, func(newNode, parent SQLNode) { @@ -8140,6 +8236,7 @@ func (a *application) rewriteRefOfPartitionSpec(parent SQLNode, node *PartitionS } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfPartitionSpecNames) } if !a.rewritePartitions(node, node.Names, func(newNode, parent SQLNode) { @@ -8199,6 +8296,7 @@ func (a *application) rewriteRefOfPartitionValueRange(parent SQLNode, node *Part } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfPartitionValueRangeRange) } if !a.rewriteValTuple(node, node.Range, func(newNode, parent SQLNode) { @@ -8237,6 +8335,10 @@ func (a *application) rewritePartitions(parent SQLNode, node Partitions, replace return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + } for x, el := range node { if !a.rewriteIdentifierCI(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { @@ -8246,6 +8348,9 @@ func (a *application) rewritePartitions(parent SQLNode, node Partitions, replace return false } } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -8275,6 +8380,7 @@ func (a *application) rewriteRefOfPerformanceSchemaFuncExpr(parent SQLNode, node } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfPerformanceSchemaFuncExprArgument) } if !a.rewriteExpr(node, node.Argument, func(newNode, parent SQLNode) { @@ -8362,6 +8468,7 @@ func (a *application) rewriteRefOfPointPropertyFuncExpr(parent SQLNode, node *Po } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfPointPropertyFuncExprPoint) } if !a.rewriteExpr(node, node.Point, func(newNode, parent SQLNode) { @@ -8449,6 +8556,7 @@ func (a *application) rewriteRefOfPolygonPropertyFuncExpr(parent SQLNode, node * } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfPolygonPropertyFuncExprPolygon) } if !a.rewriteExpr(node, node.Polygon, func(newNode, parent SQLNode) { @@ -9101,6 +9209,7 @@ func (a *application) rewriteRefOfRevertMigration(parent SQLNode, node *RevertMi } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfRevertMigrationComments) } if !a.rewriteRefOfParsedComments(node, node.Comments, func(newNode, parent SQLNode) { @@ -9304,6 +9413,7 @@ func (a *application) rewriteRefOfSelect(parent SQLNode, node *Select, replacer } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfSelectWith) } if !a.rewriteRefOfWith(node, node.With, func(newNode, parent SQLNode) { @@ -9423,6 +9533,10 @@ func (a *application) rewriteSelectExprs(parent SQLNode, node SelectExprs, repla return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + } for x, el := range node { if !a.rewriteSelectExpr(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { @@ -9432,6 +9546,9 @@ func (a *application) rewriteSelectExprs(parent SQLNode, node SelectExprs, repla return false } } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -9570,6 +9687,10 @@ func (a *application) rewriteSetExprs(parent SQLNode, node SetExprs, replacer re return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + } for x, el := range node { if !a.rewriteRefOfSetExpr(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { @@ -9579,6 +9700,9 @@ func (a *application) rewriteSetExprs(parent SQLNode, node SetExprs, replacer re return false } } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -9638,6 +9762,7 @@ func (a *application) rewriteRefOfShowBasic(parent SQLNode, node *ShowBasic, rep } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfShowBasicTbl) } if !a.rewriteTableName(node, node.Tbl, func(newNode, parent SQLNode) { @@ -9688,6 +9813,7 @@ func (a *application) rewriteRefOfShowCreate(parent SQLNode, node *ShowCreate, r } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfShowCreateOp) } if !a.rewriteTableName(node, node.Op, func(newNode, parent SQLNode) { @@ -9722,6 +9848,7 @@ func (a *application) rewriteRefOfShowFilter(parent SQLNode, node *ShowFilter, r } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfShowFilterFilter) } if !a.rewriteExpr(node, node.Filter, func(newNode, parent SQLNode) { @@ -9756,6 +9883,7 @@ func (a *application) rewriteRefOfShowMigrationLogs(parent SQLNode, node *ShowMi } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfShowMigrationLogsComments) } if !a.rewriteRefOfParsedComments(node, node.Comments, func(newNode, parent SQLNode) { @@ -10164,6 +10292,7 @@ func (a *application) rewriteRefOfSubPartition(parent SQLNode, node *SubPartitio } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfSubPartitionColList) } if !a.rewriteColumns(node, node.ColList, func(newNode, parent SQLNode) { @@ -10312,6 +10441,10 @@ func (a *application) rewriteSubPartitionDefinitions(parent SQLNode, node SubPar return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + } for x, el := range node { if !a.rewriteRefOfSubPartitionDefinition(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { @@ -10321,6 +10454,9 @@ func (a *application) rewriteSubPartitionDefinitions(parent SQLNode, node SubPar return false } } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -10493,6 +10629,10 @@ func (a *application) rewriteTableExprs(parent SQLNode, node TableExprs, replace return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + } for x, el := range node { if !a.rewriteTableExpr(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { @@ -10502,6 +10642,9 @@ func (a *application) rewriteTableExprs(parent SQLNode, node TableExprs, replace return false } } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -10570,6 +10713,10 @@ func (a *application) rewriteTableNames(parent SQLNode, node TableNames, replace return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + } for x, el := range node { if !a.rewriteTableName(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { @@ -10579,6 +10726,9 @@ func (a *application) rewriteTableNames(parent SQLNode, node TableNames, replace return false } } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -10632,6 +10782,9 @@ func (a *application) rewriteRefOfTableSpec(parent SQLNode, node *TableSpec, rep } } var path ASTPath + if a.collectPaths { + path = a.cur.current + } for x, el := range node.Columns { if !a.rewriteRefOfColumnDefinition(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { @@ -10779,6 +10932,7 @@ func (a *application) rewriteRefOfTrimFuncExpr(parent SQLNode, node *TrimFuncExp } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfTrimFuncExprTrimArg) } if !a.rewriteExpr(node, node.TrimArg, func(newNode, parent SQLNode) { @@ -10861,6 +11015,7 @@ func (a *application) rewriteRefOfUnaryExpr(parent SQLNode, node *UnaryExpr, rep } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfUnaryExprExpr) } if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { @@ -11125,6 +11280,10 @@ func (a *application) rewriteUpdateExprs(parent SQLNode, node UpdateExprs, repla return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + } for x, el := range node { if !a.rewriteRefOfUpdateExpr(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { @@ -11134,6 +11293,9 @@ func (a *application) rewriteUpdateExprs(parent SQLNode, node UpdateExprs, repla return false } } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -11249,6 +11411,7 @@ func (a *application) rewriteRefOfVExplainStmt(parent SQLNode, node *VExplainStm } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfVExplainStmtStatement) } if !a.rewriteStatement(node, node.Statement, func(newNode, parent SQLNode) { @@ -11362,6 +11525,10 @@ func (a *application) rewriteValTuple(parent SQLNode, node ValTuple, replacer re return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + } for x, el := range node { if !a.rewriteExpr(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { @@ -11371,6 +11538,9 @@ func (a *application) rewriteValTuple(parent SQLNode, node ValTuple, replacer re return false } } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -11423,6 +11593,10 @@ func (a *application) rewriteValues(parent SQLNode, node Values, replacer replac return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + } for x, el := range node { if !a.rewriteValTuple(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { @@ -11432,6 +11606,9 @@ func (a *application) rewriteValues(parent SQLNode, node Values, replacer replac return false } } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -11672,6 +11849,7 @@ func (a *application) rewriteRefOfVariable(parent SQLNode, node *Variable, repla } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfVariableName) } if !a.rewriteIdentifierCI(node, node.Name, func(newNode, parent SQLNode) { @@ -11929,6 +12107,7 @@ func (a *application) rewriteRefOfWhere(parent SQLNode, node *Where, replacer re } var path ASTPath if a.collectPaths { + path = a.cur.current a.cur.current = AddStep(path, RefOfWhereExpr) } if !a.rewriteExpr(node, node.Expr, func(newNode, parent SQLNode) { @@ -12010,6 +12189,10 @@ func (a *application) rewriteWindowDefinitions(parent SQLNode, node WindowDefini return true } } + var path ASTPath + if a.collectPaths { + path = a.cur.current + } for x, el := range node { if !a.rewriteRefOfWindowDefinition(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { @@ -12019,6 +12202,9 @@ func (a *application) rewriteWindowDefinitions(parent SQLNode, node WindowDefini return false } } + if a.collectPaths { + a.cur.current = path + } if a.post != nil { a.cur.replacer = replacer a.cur.parent = parent @@ -12101,6 +12287,9 @@ func (a *application) rewriteRefOfWith(parent SQLNode, node *With, replacer repl } } var path ASTPath + if a.collectPaths { + path = a.cur.current + } for x, el := range node.CTEs { if !a.rewriteRefOfCommonTableExpr(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { diff --git a/go/vt/sqlparser/rewriter_test.go b/go/vt/sqlparser/rewriter_test.go index 89dfc25cac9..7e358d4ff40 100644 --- a/go/vt/sqlparser/rewriter_test.go +++ b/go/vt/sqlparser/rewriter_test.go @@ -66,7 +66,7 @@ func TestReplaceWorksInLaterCalls(t *testing.T) { assert.Equal(t, 2, count) } -func TestFindColNames(t *testing.T) { +func TestFindColNamesWithPaths(t *testing.T) { // this is the tpch query #1 q := "select l_returnflag, l_linestatus, sum(l_quantity) as sum_qty, sum(l_extendedprice) as sum_base_price, sum(l_extendedprice * (1 - l_discount)) as sum_disc_price, sum(l_extendedprice * (1 - l_discount) * (1 + l_tax)) as sum_charge, avg(l_quantity) as avg_qty, avg(l_extendedprice) as avg_price, avg(l_discount) as avg_disc, count(*) as count_order from lineitem where l_shipdate <= '1998-12-01' - interval '108' day group by l_returnflag, l_linestatus order by l_returnflag, l_linestatus" ast, err := NewTestParser().Parse(q) From add411cb5bd46c943ac228641b8e5c5029adbe9c Mon Sep 17 00:00:00 2001 From: Andres Taylor Date: Thu, 30 Jan 2025 08:56:01 +0100 Subject: [PATCH 09/13] refactor Signed-off-by: Andres Taylor --- go/tools/asthelpergen/rewrite_gen.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/go/tools/asthelpergen/rewrite_gen.go b/go/tools/asthelpergen/rewrite_gen.go index d7774bb7454..2bfb3d48cf2 100644 --- a/go/tools/asthelpergen/rewrite_gen.go +++ b/go/tools/asthelpergen/rewrite_gen.go @@ -222,7 +222,7 @@ func (r *rewriteGen) sliceMethod(t types.Type, slice *types.Slice, spi generator ), } stmts = append(stmts, forBlock...) - rewriteChild := r.rewriteChildSlice(t, slice.Elem(), "notUsed", jen.Id("el"), jen.Index(jen.Id("idx")), false, 0) + rewriteChild := r.rewriteChildSlice(t, slice.Elem(), "notUsed", jen.Id("el"), jen.Index(jen.Id("idx")), false) stmts = append(stmts, jen.For(jen.Id("x, el").Op(":=").Id("range node")). @@ -342,7 +342,7 @@ func (r *rewriteGen) rewriteAllStructFields(t types.Type, strct *types.Struct, s } output = append(output, jen.For(jen.List(id, jen.Id("el")).Op(":=").Id("range node."+field.Name())). - Block(r.rewriteChildSlice(t, slice.Elem(), field.Name(), jen.Id("el"), jen.Dot(field.Name()).Index(jen.Id("idx")), fail, fieldNumber)...)) + Block(r.rewriteChildSlice(t, slice.Elem(), field.Name(), jen.Id("el"), jen.Dot(field.Name()).Index(jen.Id("idx")), fail)...)) fieldNumber++ } } @@ -408,7 +408,7 @@ func (r *rewriteGen) rewriteChild(t, field types.Type, fieldName string, param j } } -func (r *rewriteGen) rewriteChildSlice(t, field types.Type, fieldName string, param jen.Code, replace jen.Code, fail bool, fieldOffset int) []jen.Code { +func (r *rewriteGen) rewriteChildSlice(t, field types.Type, fieldName string, param jen.Code, replace jen.Code, fail bool) []jen.Code { /* if errF := a.rewriteAST(node, el, func(idx int) replacerFunc { return func(newNode, parent AST) { From 309dfa6b85201e24473da6fb3b2bfebea785c301 Mon Sep 17 00:00:00 2001 From: Andres Taylor Date: Thu, 30 Jan 2025 09:23:14 +0100 Subject: [PATCH 10/13] add offset tracking when visiting slices Signed-off-by: Andres Taylor --- .../asthelpergen/integration/ast_rewrite.go | 20 ++- go/tools/asthelpergen/rewrite_gen.go | 16 ++- go/vt/sqlparser/ast_rewrite.go | 123 ++++++++++++++++++ go/vt/sqlparser/rewriter_test.go | 16 ++- 4 files changed, 161 insertions(+), 14 deletions(-) diff --git a/go/tools/asthelpergen/integration/ast_rewrite.go b/go/tools/asthelpergen/integration/ast_rewrite.go index 3f14d19d814..b5b7970d230 100644 --- a/go/tools/asthelpergen/integration/ast_rewrite.go +++ b/go/tools/asthelpergen/integration/ast_rewrite.go @@ -125,6 +125,9 @@ func (a *application) rewriteInterfaceSlice(parent AST, node InterfaceSlice, rep path = a.cur.current } for x, el := range node { + if a.collectPaths { + a.cur.current = AddStepWithSliceIndex(path, InterfaceSliceOffset8, x) + } if !a.rewriteAST(node, el, func(idx int) replacerFunc { return func(newNode, parent AST) { parent.(InterfaceSlice)[idx] = newNode.(AST) @@ -193,6 +196,9 @@ func (a *application) rewriteLeafSlice(parent AST, node LeafSlice, replacer repl path = a.cur.current } for x, el := range node { + if a.collectPaths { + a.cur.current = AddStepWithSliceIndex(path, LeafSliceOffset8, x) + } if !a.rewriteRefOfLeaf(node, el, func(idx int) replacerFunc { return func(newNode, parent AST) { parent.(LeafSlice)[idx] = newNode.(*Leaf) @@ -298,6 +304,9 @@ func (a *application) rewriteRefOfRefSliceContainer(parent AST, node *RefSliceCo path = a.cur.current } for x, el := range node.ASTElements { + if a.collectPaths { + a.cur.current = AddStepWithSliceIndex(path, RefOfRefSliceContainerASTElements8, x) + } if !a.rewriteAST(node, el, func(idx int) replacerFunc { return func(newNode, parent AST) { parent.(*RefSliceContainer).ASTElements[idx] = newNode.(AST) @@ -307,6 +316,9 @@ func (a *application) rewriteRefOfRefSliceContainer(parent AST, node *RefSliceCo } } for x, el := range node.ASTImplementationElements { + if a.collectPaths { + a.cur.current = AddStepWithSliceIndex(path, RefOfRefSliceContainerASTImplementationElements8, x) + } if !a.rewriteRefOfLeaf(node, el, func(idx int) replacerFunc { return func(newNode, parent AST) { parent.(*RefSliceContainer).ASTImplementationElements[idx] = newNode.(*Leaf) @@ -416,7 +428,10 @@ func (a *application) rewriteValueSliceContainer(parent AST, node ValueSliceCont if a.collectPaths { path = a.cur.current } - for _, el := range node.ASTElements { + for x, el := range node.ASTElements { + if a.collectPaths { + a.cur.current = AddStepWithSliceIndex(path, ValueSliceContainerASTElements8, x) + } if !a.rewriteAST(node, el, func(newNode, parent AST) { panic("[BUG] tried to replace 'ASTElements' on 'ValueSliceContainer'") }) { @@ -561,6 +576,9 @@ func (a *application) rewriteRefOfValueSliceContainer(parent AST, node *ValueSli path = a.cur.current } for x, el := range node.ASTElements { + if a.collectPaths { + a.cur.current = AddStepWithSliceIndex(path, RefOfValueSliceContainerASTElements8, x) + } if !a.rewriteAST(node, el, func(idx int) replacerFunc { return func(newNode, parent AST) { parent.(*ValueSliceContainer).ASTElements[idx] = newNode.(AST) diff --git a/go/tools/asthelpergen/rewrite_gen.go b/go/tools/asthelpergen/rewrite_gen.go index 2bfb3d48cf2..56a2257529b 100644 --- a/go/tools/asthelpergen/rewrite_gen.go +++ b/go/tools/asthelpergen/rewrite_gen.go @@ -222,7 +222,7 @@ func (r *rewriteGen) sliceMethod(t types.Type, slice *types.Slice, spi generator ), } stmts = append(stmts, forBlock...) - rewriteChild := r.rewriteChildSlice(t, slice.Elem(), "notUsed", jen.Id("el"), jen.Index(jen.Id("idx")), false) + rewriteChild := r.rewriteChildSlice(t, slice.Elem(), "Offset", jen.Id("el"), jen.Index(jen.Id("idx")), false) stmts = append(stmts, jen.For(jen.Id("x, el").Op(":=").Id("range node")). @@ -336,12 +336,8 @@ func (r *rewriteGen) rewriteAllStructFields(t types.Type, strct *types.Struct, s } spi.addType(slice.Elem()) - id := jen.Id("x") - if fail { - id = jen.Id("_") - } output = append(output, - jen.For(jen.List(id, jen.Id("el")).Op(":=").Id("range node."+field.Name())). + jen.For(jen.List(jen.Id("x"), jen.Id("el")).Op(":=").Id("range node."+field.Name())). Block(r.rewriteChildSlice(t, slice.Elem(), field.Name(), jen.Id("el"), jen.Dot(field.Name()).Index(jen.Id("idx")), fail)...)) fieldNumber++ } @@ -444,7 +440,15 @@ func (r *rewriteGen) rewriteChildSlice(t, field types.Type, fieldName string, pa param, funcBlock).Block(returnFalse())) + savePath := jen.If(jen.Id("a.collectPaths")).Block( + jen.Id("a.cur.current").Op("=").Id("AddStepWithSliceIndex").Call( + jen.Id("path"), + jen.Id(printableTypeName(t)+fieldName+"8"), + jen.Id("x")), + ) + return []jen.Code{ + savePath, rewriteField, } } diff --git a/go/vt/sqlparser/ast_rewrite.go b/go/vt/sqlparser/ast_rewrite.go index 1f06fb1b1db..d08842df1ab 100644 --- a/go/vt/sqlparser/ast_rewrite.go +++ b/go/vt/sqlparser/ast_rewrite.go @@ -586,6 +586,9 @@ func (a *application) rewriteRefOfAddColumns(parent SQLNode, node *AddColumns, r path = a.cur.current } for x, el := range node.Columns { + if a.collectPaths { + a.cur.current = AddStepWithSliceIndex(path, RefOfAddColumnsColumns8, x) + } if !a.rewriteRefOfColumnDefinition(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { parent.(*AddColumns).Columns[idx] = newNode.(*ColumnDefinition) @@ -1033,6 +1036,9 @@ func (a *application) rewriteRefOfAlterTable(parent SQLNode, node *AlterTable, r return false } for x, el := range node.AlterOptions { + if a.collectPaths { + a.cur.current = AddStepWithSliceIndex(path, RefOfAlterTableAlterOptions8, x) + } if !a.rewriteAlterOption(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { parent.(*AlterTable).AlterOptions[idx] = newNode.(AlterOption) @@ -1176,6 +1182,9 @@ func (a *application) rewriteRefOfAlterVschema(parent SQLNode, node *AlterVschem return false } for x, el := range node.VindexCols { + if a.collectPaths { + a.cur.current = AddStepWithSliceIndex(path, RefOfAlterVschemaVindexCols8, x) + } if !a.rewriteIdentifierCI(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { parent.(*AlterVschema).VindexCols[idx] = newNode.(IdentifierCI) @@ -1879,6 +1888,9 @@ func (a *application) rewriteRefOfCaseExpr(parent SQLNode, node *CaseExpr, repla return false } for x, el := range node.Whens { + if a.collectPaths { + a.cur.current = AddStepWithSliceIndex(path, RefOfCaseExprWhens8, x) + } if !a.rewriteRefOfWhen(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { parent.(*CaseExpr).Whens[idx] = newNode.(*When) @@ -2260,6 +2272,9 @@ func (a *application) rewriteColumns(parent SQLNode, node Columns, replacer repl path = a.cur.current } for x, el := range node { + if a.collectPaths { + a.cur.current = AddStepWithSliceIndex(path, ColumnsOffset8, x) + } if !a.rewriteIdentifierCI(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { parent.(Columns)[idx] = newNode.(IdentifierCI) @@ -3015,6 +3030,9 @@ func (a *application) rewriteRefOfDelete(parent SQLNode, node *Delete, replacer return false } for x, el := range node.TableExprs { + if a.collectPaths { + a.cur.current = AddStepWithSliceIndex(path, RefOfDeleteTableExprs8, x) + } if !a.rewriteTableExpr(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { parent.(*Delete).TableExprs[idx] = newNode.(TableExpr) @@ -3341,6 +3359,9 @@ func (a *application) rewriteRefOfExecuteStmt(parent SQLNode, node *ExecuteStmt, return false } for x, el := range node.Arguments { + if a.collectPaths { + a.cur.current = AddStepWithSliceIndex(path, RefOfExecuteStmtArguments8, x) + } if !a.rewriteRefOfVariable(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { parent.(*ExecuteStmt).Arguments[idx] = newNode.(*Variable) @@ -3503,6 +3524,9 @@ func (a *application) rewriteExprs(parent SQLNode, node Exprs, replacer replacer path = a.cur.current } for x, el := range node { + if a.collectPaths { + a.cur.current = AddStepWithSliceIndex(path, ExprsOffset8, x) + } if !a.rewriteExpr(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { parent.(Exprs)[idx] = newNode.(Expr) @@ -4529,6 +4553,9 @@ func (a *application) rewriteRefOfGroupBy(parent SQLNode, node *GroupBy, replace path = a.cur.current } for x, el := range node.Exprs { + if a.collectPaths { + a.cur.current = AddStepWithSliceIndex(path, RefOfGroupByExprs8, x) + } if !a.rewriteExpr(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { parent.(*GroupBy).Exprs[idx] = newNode.(Expr) @@ -4700,6 +4727,9 @@ func (a *application) rewriteRefOfIndexHint(parent SQLNode, node *IndexHint, rep path = a.cur.current } for x, el := range node.Indexes { + if a.collectPaths { + a.cur.current = AddStepWithSliceIndex(path, RefOfIndexHintIndexes8, x) + } if !a.rewriteIdentifierCI(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { parent.(*IndexHint).Indexes[idx] = newNode.(IdentifierCI) @@ -4744,6 +4774,9 @@ func (a *application) rewriteIndexHints(parent SQLNode, node IndexHints, replace path = a.cur.current } for x, el := range node { + if a.collectPaths { + a.cur.current = AddStepWithSliceIndex(path, IndexHintsOffset8, x) + } if !a.rewriteRefOfIndexHint(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { parent.(IndexHints)[idx] = newNode.(*IndexHint) @@ -5303,6 +5336,9 @@ func (a *application) rewriteRefOfJSONContainsExpr(parent SQLNode, node *JSONCon return false } for x, el := range node.PathList { + if a.collectPaths { + a.cur.current = AddStepWithSliceIndex(path, RefOfJSONContainsExprPathList8, x) + } if !a.rewriteExpr(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { parent.(*JSONContainsExpr).PathList[idx] = newNode.(Expr) @@ -5360,6 +5396,9 @@ func (a *application) rewriteRefOfJSONContainsPathExpr(parent SQLNode, node *JSO return false } for x, el := range node.PathList { + if a.collectPaths { + a.cur.current = AddStepWithSliceIndex(path, RefOfJSONContainsPathExprPathList8, x) + } if !a.rewriteExpr(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { parent.(*JSONContainsPathExpr).PathList[idx] = newNode.(Expr) @@ -5409,6 +5448,9 @@ func (a *application) rewriteRefOfJSONExtractExpr(parent SQLNode, node *JSONExtr return false } for x, el := range node.PathList { + if a.collectPaths { + a.cur.current = AddStepWithSliceIndex(path, RefOfJSONExtractExprPathList8, x) + } if !a.rewriteExpr(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { parent.(*JSONExtractExpr).PathList[idx] = newNode.(Expr) @@ -5556,6 +5598,9 @@ func (a *application) rewriteRefOfJSONObjectExpr(parent SQLNode, node *JSONObjec path = a.cur.current } for x, el := range node.Params { + if a.collectPaths { + a.cur.current = AddStepWithSliceIndex(path, RefOfJSONObjectExprParams8, x) + } if !a.rewriteRefOfJSONObjectParam(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { parent.(*JSONObjectExpr).Params[idx] = newNode.(*JSONObjectParam) @@ -5944,6 +5989,9 @@ func (a *application) rewriteRefOfJSONSearchExpr(parent SQLNode, node *JSONSearc return false } for x, el := range node.PathList { + if a.collectPaths { + a.cur.current = AddStepWithSliceIndex(path, RefOfJSONSearchExprPathList8, x) + } if !a.rewriteExpr(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { parent.(*JSONSearchExpr).PathList[idx] = newNode.(Expr) @@ -6084,6 +6132,9 @@ func (a *application) rewriteRefOfJSONTableExpr(parent SQLNode, node *JSONTableE return false } for x, el := range node.Columns { + if a.collectPaths { + a.cur.current = AddStepWithSliceIndex(path, RefOfJSONTableExprColumns8, x) + } if !a.rewriteRefOfJtColumnDefinition(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { parent.(*JSONTableExpr).Columns[idx] = newNode.(*JtColumnDefinition) @@ -6293,6 +6344,9 @@ func (a *application) rewriteRefOfJSONValueModifierExpr(parent SQLNode, node *JS return false } for x, el := range node.Params { + if a.collectPaths { + a.cur.current = AddStepWithSliceIndex(path, RefOfJSONValueModifierExprParams8, x) + } if !a.rewriteRefOfJSONObjectParam(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { parent.(*JSONValueModifierExpr).Params[idx] = newNode.(*JSONObjectParam) @@ -6945,6 +6999,9 @@ func (a *application) rewriteRefOfMatchExpr(parent SQLNode, node *MatchExpr, rep path = a.cur.current } for x, el := range node.Columns { + if a.collectPaths { + a.cur.current = AddStepWithSliceIndex(path, RefOfMatchExprColumns8, x) + } if !a.rewriteRefOfColName(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { parent.(*MatchExpr).Columns[idx] = newNode.(*ColName) @@ -7416,6 +7473,9 @@ func (a *application) rewriteNamedWindows(parent SQLNode, node NamedWindows, rep path = a.cur.current } for x, el := range node { + if a.collectPaths { + a.cur.current = AddStepWithSliceIndex(path, NamedWindowsOffset8, x) + } if !a.rewriteRefOfNamedWindow(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { parent.(NamedWindows)[idx] = newNode.(*NamedWindow) @@ -7676,6 +7736,9 @@ func (a *application) rewriteOnDup(parent SQLNode, node OnDup, replacer replacer path = a.cur.current } for x, el := range node { + if a.collectPaths { + a.cur.current = AddStepWithSliceIndex(path, OnDupOffset8, x) + } if !a.rewriteRefOfUpdateExpr(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { parent.(OnDup)[idx] = newNode.(*UpdateExpr) @@ -7838,6 +7901,9 @@ func (a *application) rewriteOrderBy(parent SQLNode, node OrderBy, replacer repl path = a.cur.current } for x, el := range node { + if a.collectPaths { + a.cur.current = AddStepWithSliceIndex(path, OrderByOffset8, x) + } if !a.rewriteRefOfOrder(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { parent.(OrderBy)[idx] = newNode.(*Order) @@ -8201,6 +8267,9 @@ func (a *application) rewriteRefOfPartitionOption(parent SQLNode, node *Partitio return false } for x, el := range node.Definitions { + if a.collectPaths { + a.cur.current = AddStepWithSliceIndex(path, RefOfPartitionOptionDefinitions8, x) + } if !a.rewriteRefOfPartitionDefinition(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { parent.(*PartitionOption).Definitions[idx] = newNode.(*PartitionDefinition) @@ -8261,6 +8330,9 @@ func (a *application) rewriteRefOfPartitionSpec(parent SQLNode, node *PartitionS return false } for x, el := range node.Definitions { + if a.collectPaths { + a.cur.current = AddStepWithSliceIndex(path, RefOfPartitionSpecDefinitions8, x) + } if !a.rewriteRefOfPartitionDefinition(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { parent.(*PartitionSpec).Definitions[idx] = newNode.(*PartitionDefinition) @@ -8340,6 +8412,9 @@ func (a *application) rewritePartitions(parent SQLNode, node Partitions, replace path = a.cur.current } for x, el := range node { + if a.collectPaths { + a.cur.current = AddStepWithSliceIndex(path, PartitionsOffset8, x) + } if !a.rewriteIdentifierCI(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { parent.(Partitions)[idx] = newNode.(IdentifierCI) @@ -9422,6 +9497,9 @@ func (a *application) rewriteRefOfSelect(parent SQLNode, node *Select, replacer return false } for x, el := range node.From { + if a.collectPaths { + a.cur.current = AddStepWithSliceIndex(path, RefOfSelectFrom8, x) + } if !a.rewriteTableExpr(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { parent.(*Select).From[idx] = newNode.(TableExpr) @@ -9538,6 +9616,9 @@ func (a *application) rewriteSelectExprs(parent SQLNode, node SelectExprs, repla path = a.cur.current } for x, el := range node { + if a.collectPaths { + a.cur.current = AddStepWithSliceIndex(path, SelectExprsOffset8, x) + } if !a.rewriteSelectExpr(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { parent.(SelectExprs)[idx] = newNode.(SelectExpr) @@ -9692,6 +9773,9 @@ func (a *application) rewriteSetExprs(parent SQLNode, node SetExprs, replacer re path = a.cur.current } for x, el := range node { + if a.collectPaths { + a.cur.current = AddStepWithSliceIndex(path, SetExprsOffset8, x) + } if !a.rewriteRefOfSetExpr(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { parent.(SetExprs)[idx] = newNode.(*SetExpr) @@ -10446,6 +10530,9 @@ func (a *application) rewriteSubPartitionDefinitions(parent SQLNode, node SubPar path = a.cur.current } for x, el := range node { + if a.collectPaths { + a.cur.current = AddStepWithSliceIndex(path, SubPartitionDefinitionsOffset8, x) + } if !a.rewriteRefOfSubPartitionDefinition(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { parent.(SubPartitionDefinitions)[idx] = newNode.(*SubPartitionDefinition) @@ -10634,6 +10721,9 @@ func (a *application) rewriteTableExprs(parent SQLNode, node TableExprs, replace path = a.cur.current } for x, el := range node { + if a.collectPaths { + a.cur.current = AddStepWithSliceIndex(path, TableExprsOffset8, x) + } if !a.rewriteTableExpr(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { parent.(TableExprs)[idx] = newNode.(TableExpr) @@ -10718,6 +10808,9 @@ func (a *application) rewriteTableNames(parent SQLNode, node TableNames, replace path = a.cur.current } for x, el := range node { + if a.collectPaths { + a.cur.current = AddStepWithSliceIndex(path, TableNamesOffset8, x) + } if !a.rewriteTableName(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { parent.(TableNames)[idx] = newNode.(TableName) @@ -10786,6 +10879,9 @@ func (a *application) rewriteRefOfTableSpec(parent SQLNode, node *TableSpec, rep path = a.cur.current } for x, el := range node.Columns { + if a.collectPaths { + a.cur.current = AddStepWithSliceIndex(path, RefOfTableSpecColumns8, x) + } if !a.rewriteRefOfColumnDefinition(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { parent.(*TableSpec).Columns[idx] = newNode.(*ColumnDefinition) @@ -10795,6 +10891,9 @@ func (a *application) rewriteRefOfTableSpec(parent SQLNode, node *TableSpec, rep } } for x, el := range node.Indexes { + if a.collectPaths { + a.cur.current = AddStepWithSliceIndex(path, RefOfTableSpecIndexes8, x) + } if !a.rewriteRefOfIndexDefinition(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { parent.(*TableSpec).Indexes[idx] = newNode.(*IndexDefinition) @@ -10804,6 +10903,9 @@ func (a *application) rewriteRefOfTableSpec(parent SQLNode, node *TableSpec, rep } } for x, el := range node.Constraints { + if a.collectPaths { + a.cur.current = AddStepWithSliceIndex(path, RefOfTableSpecConstraints8, x) + } if !a.rewriteRefOfConstraintDefinition(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { parent.(*TableSpec).Constraints[idx] = newNode.(*ConstraintDefinition) @@ -11166,6 +11268,9 @@ func (a *application) rewriteRefOfUpdate(parent SQLNode, node *Update, replacer return false } for x, el := range node.TableExprs { + if a.collectPaths { + a.cur.current = AddStepWithSliceIndex(path, RefOfUpdateTableExprs8, x) + } if !a.rewriteTableExpr(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { parent.(*Update).TableExprs[idx] = newNode.(TableExpr) @@ -11285,6 +11390,9 @@ func (a *application) rewriteUpdateExprs(parent SQLNode, node UpdateExprs, repla path = a.cur.current } for x, el := range node { + if a.collectPaths { + a.cur.current = AddStepWithSliceIndex(path, UpdateExprsOffset8, x) + } if !a.rewriteRefOfUpdateExpr(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { parent.(UpdateExprs)[idx] = newNode.(*UpdateExpr) @@ -11530,6 +11638,9 @@ func (a *application) rewriteValTuple(parent SQLNode, node ValTuple, replacer re path = a.cur.current } for x, el := range node { + if a.collectPaths { + a.cur.current = AddStepWithSliceIndex(path, ValTupleOffset8, x) + } if !a.rewriteExpr(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { parent.(ValTuple)[idx] = newNode.(Expr) @@ -11598,6 +11709,9 @@ func (a *application) rewriteValues(parent SQLNode, node Values, replacer replac path = a.cur.current } for x, el := range node { + if a.collectPaths { + a.cur.current = AddStepWithSliceIndex(path, ValuesOffset8, x) + } if !a.rewriteValTuple(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { parent.(Values)[idx] = newNode.(ValTuple) @@ -11981,6 +12095,9 @@ func (a *application) rewriteRefOfVindexSpec(parent SQLNode, node *VindexSpec, r return false } for x, el := range node.Params { + if a.collectPaths { + a.cur.current = AddStepWithSliceIndex(path, RefOfVindexSpecParams8, x) + } if !a.rewriteVindexParam(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { parent.(*VindexSpec).Params[idx] = newNode.(VindexParam) @@ -12194,6 +12311,9 @@ func (a *application) rewriteWindowDefinitions(parent SQLNode, node WindowDefini path = a.cur.current } for x, el := range node { + if a.collectPaths { + a.cur.current = AddStepWithSliceIndex(path, WindowDefinitionsOffset8, x) + } if !a.rewriteRefOfWindowDefinition(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { parent.(WindowDefinitions)[idx] = newNode.(*WindowDefinition) @@ -12291,6 +12411,9 @@ func (a *application) rewriteRefOfWith(parent SQLNode, node *With, replacer repl path = a.cur.current } for x, el := range node.CTEs { + if a.collectPaths { + a.cur.current = AddStepWithSliceIndex(path, RefOfWithCTEs8, x) + } if !a.rewriteRefOfCommonTableExpr(node, el, func(idx int) replacerFunc { return func(newNode, parent SQLNode) { parent.(*With).CTEs[idx] = newNode.(*CommonTableExpr) diff --git a/go/vt/sqlparser/rewriter_test.go b/go/vt/sqlparser/rewriter_test.go index 7e358d4ff40..94789fae52e 100644 --- a/go/vt/sqlparser/rewriter_test.go +++ b/go/vt/sqlparser/rewriter_test.go @@ -71,13 +71,15 @@ func TestFindColNamesWithPaths(t *testing.T) { q := "select l_returnflag, l_linestatus, sum(l_quantity) as sum_qty, sum(l_extendedprice) as sum_base_price, sum(l_extendedprice * (1 - l_discount)) as sum_disc_price, sum(l_extendedprice * (1 - l_discount) * (1 + l_tax)) as sum_charge, avg(l_quantity) as avg_qty, avg(l_extendedprice) as avg_price, avg(l_discount) as avg_disc, count(*) as count_order from lineitem where l_shipdate <= '1998-12-01' - interval '108' day group by l_returnflag, l_linestatus order by l_returnflag, l_linestatus" ast, err := NewTestParser().Parse(q) require.NoError(t, err) - RewriteWithPath(ast, nil, func(cursor *Cursor) bool { - if _, isColName := cursor.Node().(*ColName); isColName { - // TODO: actually assert something here - fmt.Println(cursor.CurrentPath().DebugString()) - } - return true - }) + RewriteWithPath(ast, + func(cursor *Cursor) bool { + fmt.Println("DOWN " + cursor.CurrentPath().DebugString()) + return true + }, + func(cursor *Cursor) bool { + fmt.Println("UP " + cursor.CurrentPath().DebugString()) + return true + }) } func TestReplaceAndRevisitWorksInLaterCalls(t *testing.T) { From d49b4bfca3c03d5e7bf75a3468e993532698140d Mon Sep 17 00:00:00 2001 From: Andres Taylor Date: Fri, 31 Jan 2025 07:53:08 +0100 Subject: [PATCH 11/13] preparing to add AST walk method Signed-off-by: Andres Taylor --- go/tools/asthelpergen/ast_path_gen.go | 98 +++- go/tools/asthelpergen/asthelpergen.go | 9 +- go/tools/asthelpergen/clone_gen.go | 2 +- go/tools/asthelpergen/copy_on_rewrite_gen.go | 2 +- go/tools/asthelpergen/equals_gen.go | 2 +- go/tools/asthelpergen/integration/ast_path.go | 72 +-- go/tools/asthelpergen/rewrite_gen.go | 2 +- go/tools/asthelpergen/visit_gen.go | 2 +- go/vt/sqlparser/ast_path.go | 480 +++++++++--------- go/vt/vtgate/semantics/analyzer.go | 2 +- 10 files changed, 376 insertions(+), 295 deletions(-) diff --git a/go/tools/asthelpergen/ast_path_gen.go b/go/tools/asthelpergen/ast_path_gen.go index b000a53fcbd..6844433f246 100644 --- a/go/tools/asthelpergen/ast_path_gen.go +++ b/go/tools/asthelpergen/ast_path_gen.go @@ -25,8 +25,9 @@ import ( type ( pathGen struct { - file *jen.File - steps []step + file *jen.File + steps []step + ifaceName string } step struct { container types.Type // the type of the container @@ -36,19 +37,29 @@ type ( } ) +const sliceMarker = " -SLICE- " + var _ generator = (*pathGen)(nil) -func newPathGen(pkgname string) *pathGen { +func newPathGen(pkgname, ifaceName string) *pathGen { file := jen.NewFile(pkgname) file.HeaderComment(licenseFileHeader) file.HeaderComment("Code generated by ASTHelperGen. DO NOT EDIT.") return &pathGen{ - file: file, + file: file, + ifaceName: ifaceName, + } +} + +func (s step) AsEnum() string { + if s.name == sliceMarker { + return printableTypeName(s.container) } + return printableTypeName(s.container) + s.name } -func (p *pathGen) genFile() (string, *jen.File) { +func (p *pathGen) genFile(spi generatorSPI) (string, *jen.File) { p.file.ImportName("fmt", "fmt") // Declare the ASTStep type with underlying type uint16 @@ -59,6 +70,10 @@ func (p *pathGen) genFile() (string, *jen.File) { // Add the ASTStep#DebugString() method to the file p.file.Add(p.debugString()) + + // Add the generated WalkASTPath method + p.file.Add(p.generateWalkASTPath(spi)) + return "ast_path.go", p.file } @@ -106,7 +121,7 @@ func (p *pathGen) ptrToBasicMethod(t types.Type, basic *types.Basic, spi generat func (p *pathGen) sliceMethod(t types.Type, _ *types.Slice, _ generatorSPI) error { p.steps = append(p.steps, step{ container: t, - name: "Offset", + name: sliceMarker, slice: true, typ: t, }) @@ -122,10 +137,15 @@ func (p *pathGen) debugString() *jen.Statement { var switchCases []jen.Code for _, step := range p.steps { - stepName := printableTypeName(step.container) + step.name + stepName := step.AsEnum() // Generate the debug string using the helper function - debugStr := fmt.Sprintf("(%s).%s", types.TypeString(step.container, noQualifier), step.name) + var debugStr string + if step.name == sliceMarker { + debugStr = fmt.Sprintf("(%s)[]", types.TypeString(step.container, noQualifier)) + } else { + debugStr = fmt.Sprintf("(%s).%s", types.TypeString(step.container, noQualifier), step.name) + } if !step.slice { switchCases = append(switchCases, jen.Case(jen.Id(stepName)).Block( @@ -163,7 +183,7 @@ func (p *pathGen) buildConstWithEnum() *jen.Statement { constDefs = append(constDefs, jen.Id(step)) } for _, step := range p.steps { - stepName := printableTypeName(step.container) + step.name + stepName := step.AsEnum() if step.slice { addStep(stepName + "8") addStep(stepName + "32") @@ -176,3 +196,63 @@ func (p *pathGen) buildConstWithEnum() *jen.Statement { constBlock := jen.Const().Defs(constDefs...) return constBlock } + +func (p *pathGen) generateWalkASTPath(spi generatorSPI) *jen.Statement { + method := jen.Func().Id("WalkASTPath").Params( + jen.Id("node").Id(p.ifaceName), + jen.Id("path").Id("ASTPath"), + ).Id(p.ifaceName).Block( + jen.If(jen.Len(jen.Id("path")).Op("<").Lit(2)).Block( + jen.Return(jen.Nil()), + ), + jen.Id("step").Op(":=").Qual("encoding/binary", "BigEndian").Dot("Uint16").Call(jen.Index().Byte().Parens(jen.Id("path[:2]"))), + jen.Id("path").Op("=").Id("path[2:]"), + + jen.Switch(jen.Id("ASTStep").Parens(jen.Id("step"))).Block(p.generateWalkCases()...), + jen.Return(jen.Nil()), // Fallback return + ) + return method +} + +func (p *pathGen) generateWalkCases() []jen.Code { + var cases []jen.Code + + for _, step := range p.steps { + stepName := step.AsEnum() + + if !step.slice { + // return WalkASTPath(node.(*RefContainer).ASTType, path) + t := types.TypeString(step.typ, noQualifier) + n := jen.Id("node").Dot(fmt.Sprintf("(%s)", t)).Dot(step.name) + + cases = append(cases, jen.Case(jen.Id(stepName)).Block( + //jen.Id("node").Op("=").Id("node").Dot(step.name), + jen.Return(jen.Id("WalkASTPath").Call(n, jen.Id("path"))), + )) + continue + } + + var el1 jen.Code + var assignNode jen.Code + if step.name == sliceMarker { + el1 = jen.Id("node") + assignNode = jen.Id("node").Op("=").Id("node").Index(jen.Id("idx")) + } else { + el1 = jen.Id("node").Dot(step.name) + assignNode = jen.Id("node").Op("=").Id("node").Dot(step.name).Index(jen.Id("idx")) + } + + cases = append(cases, jen.Case(jen.Id(stepName+"8")).Block( + jen.If(jen.Len(jen.Id("path")).Op("<").Lit(2)).Block(jen.Return(jen.Nil())), + jen.Id("idx").Op(":=").Qual("encoding/binary", "BigEndian").Dot("Uint16").Call(jen.Index().Byte().Parens(jen.Id("path[:2]"))), + jen.Id("path").Op("=").Id("path[2:]"), + jen.If(jen.Id("int(idx)").Op("<").Lit(0).Op("||").Id("int(idx)").Op(">=").Len(el1)).Block( + jen.Return(jen.Nil()), + ), + assignNode, + jen.Return(jen.Id("WalkASTPath").Call(jen.Id("node"), jen.Id("path"))), + )) + } + + return cases +} diff --git a/go/tools/asthelpergen/asthelpergen.go b/go/tools/asthelpergen/asthelpergen.go index a81925c33a4..907bd87f894 100644 --- a/go/tools/asthelpergen/asthelpergen.go +++ b/go/tools/asthelpergen/asthelpergen.go @@ -54,7 +54,7 @@ type ( iface() *types.Interface // the root interface that all nodes are expected to implement } generator interface { - genFile() (string, *jen.File) + genFile(generatorSPI) (string, *jen.File) interfaceMethod(t types.Type, iface *types.Interface, spi generatorSPI) error structMethod(t types.Type, strct *types.Struct, spi generatorSPI) error ptrToStructMethod(t types.Type, strct *types.Struct, spi generatorSPI) error @@ -215,12 +215,13 @@ func GenerateASTHelpers(options *Options) (map[string]*jen.File, error) { nt := tt.Type().(*types.Named) pName := nt.Obj().Pkg().Name() + ifaceName := types.TypeString(nt, noQualifier) generator := newGenerator(loaded[0].Module, loaded[0].TypesSizes, nt, newEqualsGen(pName, &options.Equals), newCloneGen(pName, &options.Clone), - newPathGen(pName), + newPathGen(pName, ifaceName), newVisitGen(pName), - newRewriterGen(pName, types.TypeString(nt, noQualifier), exprInterface), + newRewriterGen(pName, ifaceName, exprInterface), newCOWGen(pName, nt), ) @@ -308,7 +309,7 @@ func (gen *astHelperGen) createFiles() map[string]*jen.File { result := map[string]*jen.File{} for _, g := range gen.gens { - fName, jenFile := g.genFile() + fName, jenFile := g.genFile(gen) result[fName] = jenFile } return result diff --git a/go/tools/asthelpergen/clone_gen.go b/go/tools/asthelpergen/clone_gen.go index 10387a5dc25..eed3ff685ee 100644 --- a/go/tools/asthelpergen/clone_gen.go +++ b/go/tools/asthelpergen/clone_gen.go @@ -56,7 +56,7 @@ func (c *cloneGen) addFunc(name string, code *jen.Statement) { c.file.Add(code) } -func (c *cloneGen) genFile() (string, *jen.File) { +func (c *cloneGen) genFile(generatorSPI) (string, *jen.File) { return "ast_clone.go", c.file } diff --git a/go/tools/asthelpergen/copy_on_rewrite_gen.go b/go/tools/asthelpergen/copy_on_rewrite_gen.go index 1daa8d18981..a12e71cbe8f 100644 --- a/go/tools/asthelpergen/copy_on_rewrite_gen.go +++ b/go/tools/asthelpergen/copy_on_rewrite_gen.go @@ -44,7 +44,7 @@ func (c *cowGen) addFunc(code *jen.Statement) { c.file.Add(code) } -func (c *cowGen) genFile() (string, *jen.File) { +func (c *cowGen) genFile(generatorSPI) (string, *jen.File) { return "ast_copy_on_rewrite.go", c.file } diff --git a/go/tools/asthelpergen/equals_gen.go b/go/tools/asthelpergen/equals_gen.go index 2c188a30d1d..2e34eb5a36c 100644 --- a/go/tools/asthelpergen/equals_gen.go +++ b/go/tools/asthelpergen/equals_gen.go @@ -62,7 +62,7 @@ func (e *equalsGen) customComparatorField(t types.Type) string { return printableTypeName(t) + "_" } -func (e *equalsGen) genFile() (string, *jen.File) { +func (e *equalsGen) genFile(generatorSPI) (string, *jen.File) { e.file.Type().Id(Comparator).StructFunc(func(g *jen.Group) { for tname, t := range e.comparators { if t == nil { diff --git a/go/tools/asthelpergen/integration/ast_path.go b/go/tools/asthelpergen/integration/ast_path.go index efb4bac3512..3dc2fe89c21 100644 --- a/go/tools/asthelpergen/integration/ast_path.go +++ b/go/tools/asthelpergen/integration/ast_path.go @@ -20,12 +20,12 @@ package integration type ASTStep uint16 const ( - BytesOffset8 ASTStep = iota - BytesOffset32 - InterfaceSliceOffset8 - InterfaceSliceOffset32 - LeafSliceOffset8 - LeafSliceOffset32 + Bytes8 ASTStep = iota + Bytes32 + InterfaceSlice8 + InterfaceSlice32 + LeafSlice8 + LeafSlice32 RefOfRefContainerASTType RefOfRefContainerASTImplementationType RefOfRefSliceContainerASTElements8 @@ -38,12 +38,12 @@ const ( ValueSliceContainerASTElements8 ValueSliceContainerASTElements32 ValueSliceContainerASTImplementationElements - SliceOfASTOffset8 - SliceOfASTOffset32 - SliceOfIntOffset8 - SliceOfIntOffset32 - SliceOfRefOfLeafOffset8 - SliceOfRefOfLeafOffset32 + SliceOfAST8 + SliceOfAST32 + SliceOfInt8 + SliceOfInt32 + SliceOfRefOfLeaf8 + SliceOfRefOfLeaf32 RefOfValueContainerASTType RefOfValueContainerASTImplementationType RefOfValueSliceContainerASTElements8 @@ -53,18 +53,18 @@ const ( func (s ASTStep) DebugString() string { switch s { - case BytesOffset8: - return "(Bytes).Offset8" - case BytesOffset32: - return "(Bytes).Offset32" - case InterfaceSliceOffset8: - return "(InterfaceSlice).Offset8" - case InterfaceSliceOffset32: - return "(InterfaceSlice).Offset32" - case LeafSliceOffset8: - return "(LeafSlice).Offset8" - case LeafSliceOffset32: - return "(LeafSlice).Offset32" + case Bytes8: + return "(Bytes)[]8" + case Bytes32: + return "(Bytes)[]32" + case InterfaceSlice8: + return "(InterfaceSlice)[]8" + case InterfaceSlice32: + return "(InterfaceSlice)[]32" + case LeafSlice8: + return "(LeafSlice)[]8" + case LeafSlice32: + return "(LeafSlice)[]32" case RefOfRefContainerASTType: return "(*RefContainer).ASTType" case RefOfRefContainerASTImplementationType: @@ -89,18 +89,18 @@ func (s ASTStep) DebugString() string { return "(ValueSliceContainer).ASTElements32" case ValueSliceContainerASTImplementationElements: return "(ValueSliceContainer).ASTImplementationElements" - case SliceOfASTOffset8: - return "([]AST).Offset8" - case SliceOfASTOffset32: - return "([]AST).Offset32" - case SliceOfIntOffset8: - return "([]int).Offset8" - case SliceOfIntOffset32: - return "([]int).Offset32" - case SliceOfRefOfLeafOffset8: - return "([]*Leaf).Offset8" - case SliceOfRefOfLeafOffset32: - return "([]*Leaf).Offset32" + case SliceOfAST8: + return "([]AST)[]8" + case SliceOfAST32: + return "([]AST)[]32" + case SliceOfInt8: + return "([]int)[]8" + case SliceOfInt32: + return "([]int)[]32" + case SliceOfRefOfLeaf8: + return "([]*Leaf)[]8" + case SliceOfRefOfLeaf32: + return "([]*Leaf)[]32" case RefOfValueContainerASTType: return "(*ValueContainer).ASTType" case RefOfValueContainerASTImplementationType: diff --git a/go/tools/asthelpergen/rewrite_gen.go b/go/tools/asthelpergen/rewrite_gen.go index 56a2257529b..5a9979f45f3 100644 --- a/go/tools/asthelpergen/rewrite_gen.go +++ b/go/tools/asthelpergen/rewrite_gen.go @@ -48,7 +48,7 @@ func newRewriterGen(pkgname string, ifaceName string, exprInterface *types.Inter } } -func (r *rewriteGen) genFile() (string, *jen.File) { +func (r *rewriteGen) genFile(generatorSPI) (string, *jen.File) { return "ast_rewrite.go", r.file } diff --git a/go/tools/asthelpergen/visit_gen.go b/go/tools/asthelpergen/visit_gen.go index d82b3d8b661..dca2cfcd0f0 100644 --- a/go/tools/asthelpergen/visit_gen.go +++ b/go/tools/asthelpergen/visit_gen.go @@ -40,7 +40,7 @@ func newVisitGen(pkgname string) *visitGen { } } -func (v *visitGen) genFile() (string, *jen.File) { +func (v *visitGen) genFile(generatorSPI) (string, *jen.File) { return "ast_visit.go", v.file } diff --git a/go/vt/sqlparser/ast_path.go b/go/vt/sqlparser/ast_path.go index 17168849f9e..58009b722ef 100644 --- a/go/vt/sqlparser/ast_path.go +++ b/go/vt/sqlparser/ast_path.go @@ -95,8 +95,8 @@ const ( RefOfCollateExprExpr RefOfColumnDefinitionName RefOfColumnDefinitionType - ColumnsOffset8 - ColumnsOffset32 + Columns8 + Columns32 RefOfCommonTableExprID RefOfCommonTableExprColumns RefOfCommonTableExprSubquery @@ -151,8 +151,8 @@ const ( RefOfExplainStmtStatement RefOfExplainStmtComments RefOfExplainTabTable - ExprsOffset8 - ExprsOffset32 + Exprs8 + Exprs32 RefOfExtractFuncExprExpr RefOfExtractValueExprFragment RefOfExtractValueExprXPathExpr @@ -205,8 +205,8 @@ const ( RefOfIndexDefinitionInfo RefOfIndexHintIndexes8 RefOfIndexHintIndexes32 - IndexHintsOffset8 - IndexHintsOffset32 + IndexHints8 + IndexHints32 RefOfIndexInfoName RefOfIndexInfoConstraintName RefOfInsertComments @@ -326,21 +326,21 @@ const ( RefOfNTHValueExprFromFirstLastClause RefOfNTHValueExprNullTreatmentClause RefOfNamedWindowWindows - NamedWindowsOffset8 - NamedWindowsOffset32 + NamedWindows8 + NamedWindows32 RefOfNextvalExpr RefOfNotExprExpr RefOfNtileExprN RefOfNtileExprOverClause RefOfOffsetOriginal - OnDupOffset8 - OnDupOffset32 + OnDup8 + OnDup32 RefOfOptLikeLikeTable RefOfOrExprLeft RefOfOrExprRight RefOfOrderExpr - OrderByOffset8 - OrderByOffset32 + OrderBy8 + OrderBy32 RefOfOrderByOptionCols RefOfOverClauseWindowName RefOfOverClauseWindowSpec @@ -364,8 +364,8 @@ const ( RefOfPartitionSpecDefinitions8 RefOfPartitionSpecDefinitions32 RefOfPartitionValueRangeRange - PartitionsOffset8 - PartitionsOffset32 + Partitions8 + Partitions32 RefOfPerformanceSchemaFuncExprArgument RefOfPointExprXCordinate RefOfPointExprYCordinate @@ -426,14 +426,14 @@ const ( RefOfSelectOrderBy RefOfSelectLimit RefOfSelectInto - SelectExprsOffset8 - SelectExprsOffset32 + SelectExprs8 + SelectExprs32 RefOfSetComments RefOfSetExprs RefOfSetExprVar RefOfSetExprExpr - SetExprsOffset8 - SetExprsOffset32 + SetExprs8 + SetExprs32 RefOfShowInternal RefOfShowBasicTbl RefOfShowBasicDbName @@ -461,22 +461,22 @@ const ( RefOfSubPartitionDefinitionOptionsEngine RefOfSubPartitionDefinitionOptionsDataDirectory RefOfSubPartitionDefinitionOptionsIndexDirectory - SubPartitionDefinitionsOffset8 - SubPartitionDefinitionsOffset32 + SubPartitionDefinitions8 + SubPartitionDefinitions32 RefOfSubquerySelect RefOfSubstrExprName RefOfSubstrExprFrom RefOfSubstrExprTo RefOfSumArg RefOfSumOverClause - TableExprsOffset8 - TableExprsOffset32 + TableExprs8 + TableExprs32 TableNameName TableNameQualifier - TableNamesOffset8 - TableNamesOffset32 - TableOptionsOffset8 - TableOptionsOffset32 + TableNames8 + TableNames32 + TableOptions8 + TableOptions32 RefOfTableSpecColumns8 RefOfTableSpecColumns32 RefOfTableSpecIndexes8 @@ -507,8 +507,8 @@ const ( RefOfUpdateLimit RefOfUpdateExprName RefOfUpdateExprExpr - UpdateExprsOffset8 - UpdateExprsOffset32 + UpdateExprs8 + UpdateExprs32 RefOfUpdateXMLExprTarget RefOfUpdateXMLExprXPathExpr RefOfUpdateXMLExprNewXML @@ -520,10 +520,10 @@ const ( RefOfVStreamTable RefOfVStreamWhere RefOfVStreamLimit - ValTupleOffset8 - ValTupleOffset32 - ValuesOffset8 - ValuesOffset32 + ValTuple8 + ValTuple32 + Values8 + Values32 RefOfValuesFuncExprName RefOfValuesStatementWith RefOfValuesStatementRows @@ -550,8 +550,8 @@ const ( RefOfWhereExpr RefOfWindowDefinitionName RefOfWindowDefinitionWindowSpec - WindowDefinitionsOffset8 - WindowDefinitionsOffset32 + WindowDefinitions8 + WindowDefinitions32 RefOfWindowSpecificationName RefOfWindowSpecificationPartitionClause RefOfWindowSpecificationOrderClause @@ -560,18 +560,18 @@ const ( RefOfWithCTEs32 RefOfXorExprLeft RefOfXorExprRight - SliceOfRefOfColumnDefinitionOffset8 - SliceOfRefOfColumnDefinitionOffset32 - SliceOfDatabaseOptionOffset8 - SliceOfDatabaseOptionOffset32 - SliceOfAlterOptionOffset8 - SliceOfAlterOptionOffset32 - SliceOfIdentifierCIOffset8 - SliceOfIdentifierCIOffset32 - SliceOfTxAccessModeOffset8 - SliceOfTxAccessModeOffset32 - SliceOfRefOfWhenOffset8 - SliceOfRefOfWhenOffset32 + SliceOfRefOfColumnDefinition8 + SliceOfRefOfColumnDefinition32 + SliceOfDatabaseOption8 + SliceOfDatabaseOption32 + SliceOfAlterOption8 + SliceOfAlterOption32 + SliceOfIdentifierCI8 + SliceOfIdentifierCI32 + SliceOfTxAccessMode8 + SliceOfTxAccessMode32 + SliceOfRefOfWhen8 + SliceOfRefOfWhen32 RefOfColumnTypeOptionsDefault RefOfColumnTypeOptionsOnUpdate RefOfColumnTypeOptionsAs @@ -580,22 +580,22 @@ const ( RefOfColumnTypeOptionsEngineAttribute RefOfColumnTypeOptionsSecondaryEngineAttribute RefOfColumnTypeOptionsSRID - SliceOfStringOffset8 - SliceOfStringOffset32 - SliceOfTableExprOffset8 - SliceOfTableExprOffset32 - SliceOfRefOfVariableOffset8 - SliceOfRefOfVariableOffset32 - SliceOfExprOffset8 - SliceOfExprOffset32 - SliceOfRefOfIndexColumnOffset8 - SliceOfRefOfIndexColumnOffset32 - SliceOfRefOfIndexOptionOffset8 - SliceOfRefOfIndexOptionOffset32 - SliceOfRefOfJSONObjectParamOffset8 - SliceOfRefOfJSONObjectParamOffset32 - SliceOfRefOfJtColumnDefinitionOffset8 - SliceOfRefOfJtColumnDefinitionOffset32 + SliceOfString8 + SliceOfString32 + SliceOfTableExpr8 + SliceOfTableExpr32 + SliceOfRefOfVariable8 + SliceOfRefOfVariable32 + SliceOfExpr8 + SliceOfExpr32 + SliceOfRefOfIndexColumn8 + SliceOfRefOfIndexColumn32 + SliceOfRefOfIndexOption8 + SliceOfRefOfIndexOption32 + SliceOfRefOfJSONObjectParam8 + SliceOfRefOfJSONObjectParam32 + SliceOfRefOfJtColumnDefinition8 + SliceOfRefOfJtColumnDefinition32 RefOfJtOrdinalColDefName RefOfJtPathColDefName RefOfJtPathColDefType @@ -605,30 +605,30 @@ const ( RefOfJtNestedPathColDefPath RefOfJtNestedPathColDefColumns8 RefOfJtNestedPathColDefColumns32 - TableAndLockTypesOffset8 - TableAndLockTypesOffset32 - SliceOfRefOfColNameOffset8 - SliceOfRefOfColNameOffset32 - CommentsOffset8 - CommentsOffset32 - SliceOfRefOfPartitionDefinitionOffset8 - SliceOfRefOfPartitionDefinitionOffset32 - SliceOfRefOfRenameTablePairOffset8 - SliceOfRefOfRenameTablePairOffset32 + TableAndLockTypes8 + TableAndLockTypes32 + SliceOfRefOfColName8 + SliceOfRefOfColName32 + Comments8 + Comments32 + SliceOfRefOfPartitionDefinition8 + SliceOfRefOfPartitionDefinition32 + SliceOfRefOfRenameTablePair8 + SliceOfRefOfRenameTablePair32 RefOfRootNodeSQLNode RefOfTableNameName RefOfTableNameQualifier RefOfTableOptionValue RefOfTableOptionTables - SliceOfRefOfIndexDefinitionOffset8 - SliceOfRefOfIndexDefinitionOffset32 - SliceOfRefOfConstraintDefinitionOffset8 - SliceOfRefOfConstraintDefinitionOffset32 + SliceOfRefOfIndexDefinition8 + SliceOfRefOfIndexDefinition32 + SliceOfRefOfConstraintDefinition8 + SliceOfRefOfConstraintDefinition32 RefOfVindexParamKey - SliceOfVindexParamOffset8 - SliceOfVindexParamOffset32 - SliceOfRefOfCommonTableExprOffset8 - SliceOfRefOfCommonTableExprOffset32 + SliceOfVindexParam8 + SliceOfVindexParam32 + SliceOfRefOfCommonTableExpr8 + SliceOfRefOfCommonTableExpr32 RefOfIndexColumnColumn RefOfIndexColumnExpression RefOfIndexOptionValue @@ -789,10 +789,10 @@ func (s ASTStep) DebugString() string { return "(*ColumnDefinition).Name" case RefOfColumnDefinitionType: return "(*ColumnDefinition).Type" - case ColumnsOffset8: - return "(Columns).Offset8" - case ColumnsOffset32: - return "(Columns).Offset32" + case Columns8: + return "(Columns)[]8" + case Columns32: + return "(Columns)[]32" case RefOfCommonTableExprID: return "(*CommonTableExpr).ID" case RefOfCommonTableExprColumns: @@ -901,10 +901,10 @@ func (s ASTStep) DebugString() string { return "(*ExplainStmt).Comments" case RefOfExplainTabTable: return "(*ExplainTab).Table" - case ExprsOffset8: - return "(Exprs).Offset8" - case ExprsOffset32: - return "(Exprs).Offset32" + case Exprs8: + return "(Exprs)[]8" + case Exprs32: + return "(Exprs)[]32" case RefOfExtractFuncExprExpr: return "(*ExtractFuncExpr).Expr" case RefOfExtractValueExprFragment: @@ -1009,10 +1009,10 @@ func (s ASTStep) DebugString() string { return "(*IndexHint).Indexes8" case RefOfIndexHintIndexes32: return "(*IndexHint).Indexes32" - case IndexHintsOffset8: - return "(IndexHints).Offset8" - case IndexHintsOffset32: - return "(IndexHints).Offset32" + case IndexHints8: + return "(IndexHints)[]8" + case IndexHints32: + return "(IndexHints)[]32" case RefOfIndexInfoName: return "(*IndexInfo).Name" case RefOfIndexInfoConstraintName: @@ -1251,10 +1251,10 @@ func (s ASTStep) DebugString() string { return "(*NTHValueExpr).NullTreatmentClause" case RefOfNamedWindowWindows: return "(*NamedWindow).Windows" - case NamedWindowsOffset8: - return "(NamedWindows).Offset8" - case NamedWindowsOffset32: - return "(NamedWindows).Offset32" + case NamedWindows8: + return "(NamedWindows)[]8" + case NamedWindows32: + return "(NamedWindows)[]32" case RefOfNextvalExpr: return "(*Nextval).Expr" case RefOfNotExprExpr: @@ -1265,10 +1265,10 @@ func (s ASTStep) DebugString() string { return "(*NtileExpr).OverClause" case RefOfOffsetOriginal: return "(*Offset).Original" - case OnDupOffset8: - return "(OnDup).Offset8" - case OnDupOffset32: - return "(OnDup).Offset32" + case OnDup8: + return "(OnDup)[]8" + case OnDup32: + return "(OnDup)[]32" case RefOfOptLikeLikeTable: return "(*OptLike).LikeTable" case RefOfOrExprLeft: @@ -1277,10 +1277,10 @@ func (s ASTStep) DebugString() string { return "(*OrExpr).Right" case RefOfOrderExpr: return "(*Order).Expr" - case OrderByOffset8: - return "(OrderBy).Offset8" - case OrderByOffset32: - return "(OrderBy).Offset32" + case OrderBy8: + return "(OrderBy)[]8" + case OrderBy32: + return "(OrderBy)[]32" case RefOfOrderByOptionCols: return "(*OrderByOption).Cols" case RefOfOverClauseWindowName: @@ -1327,10 +1327,10 @@ func (s ASTStep) DebugString() string { return "(*PartitionSpec).Definitions32" case RefOfPartitionValueRangeRange: return "(*PartitionValueRange).Range" - case PartitionsOffset8: - return "(Partitions).Offset8" - case PartitionsOffset32: - return "(Partitions).Offset32" + case Partitions8: + return "(Partitions)[]8" + case Partitions32: + return "(Partitions)[]32" case RefOfPerformanceSchemaFuncExprArgument: return "(*PerformanceSchemaFuncExpr).Argument" case RefOfPointExprXCordinate: @@ -1451,10 +1451,10 @@ func (s ASTStep) DebugString() string { return "(*Select).Limit" case RefOfSelectInto: return "(*Select).Into" - case SelectExprsOffset8: - return "(SelectExprs).Offset8" - case SelectExprsOffset32: - return "(SelectExprs).Offset32" + case SelectExprs8: + return "(SelectExprs)[]8" + case SelectExprs32: + return "(SelectExprs)[]32" case RefOfSetComments: return "(*Set).Comments" case RefOfSetExprs: @@ -1463,10 +1463,10 @@ func (s ASTStep) DebugString() string { return "(*SetExpr).Var" case RefOfSetExprExpr: return "(*SetExpr).Expr" - case SetExprsOffset8: - return "(SetExprs).Offset8" - case SetExprsOffset32: - return "(SetExprs).Offset32" + case SetExprs8: + return "(SetExprs)[]8" + case SetExprs32: + return "(SetExprs)[]32" case RefOfShowInternal: return "(*Show).Internal" case RefOfShowBasicTbl: @@ -1521,10 +1521,10 @@ func (s ASTStep) DebugString() string { return "(*SubPartitionDefinitionOptions).DataDirectory" case RefOfSubPartitionDefinitionOptionsIndexDirectory: return "(*SubPartitionDefinitionOptions).IndexDirectory" - case SubPartitionDefinitionsOffset8: - return "(SubPartitionDefinitions).Offset8" - case SubPartitionDefinitionsOffset32: - return "(SubPartitionDefinitions).Offset32" + case SubPartitionDefinitions8: + return "(SubPartitionDefinitions)[]8" + case SubPartitionDefinitions32: + return "(SubPartitionDefinitions)[]32" case RefOfSubquerySelect: return "(*Subquery).Select" case RefOfSubstrExprName: @@ -1537,22 +1537,22 @@ func (s ASTStep) DebugString() string { return "(*Sum).Arg" case RefOfSumOverClause: return "(*Sum).OverClause" - case TableExprsOffset8: - return "(TableExprs).Offset8" - case TableExprsOffset32: - return "(TableExprs).Offset32" + case TableExprs8: + return "(TableExprs)[]8" + case TableExprs32: + return "(TableExprs)[]32" case TableNameName: return "(TableName).Name" case TableNameQualifier: return "(TableName).Qualifier" - case TableNamesOffset8: - return "(TableNames).Offset8" - case TableNamesOffset32: - return "(TableNames).Offset32" - case TableOptionsOffset8: - return "(TableOptions).Offset8" - case TableOptionsOffset32: - return "(TableOptions).Offset32" + case TableNames8: + return "(TableNames)[]8" + case TableNames32: + return "(TableNames)[]32" + case TableOptions8: + return "(TableOptions)[]8" + case TableOptions32: + return "(TableOptions)[]32" case RefOfTableSpecColumns8: return "(*TableSpec).Columns8" case RefOfTableSpecColumns32: @@ -1613,10 +1613,10 @@ func (s ASTStep) DebugString() string { return "(*UpdateExpr).Name" case RefOfUpdateExprExpr: return "(*UpdateExpr).Expr" - case UpdateExprsOffset8: - return "(UpdateExprs).Offset8" - case UpdateExprsOffset32: - return "(UpdateExprs).Offset32" + case UpdateExprs8: + return "(UpdateExprs)[]8" + case UpdateExprs32: + return "(UpdateExprs)[]32" case RefOfUpdateXMLExprTarget: return "(*UpdateXMLExpr).Target" case RefOfUpdateXMLExprXPathExpr: @@ -1639,14 +1639,14 @@ func (s ASTStep) DebugString() string { return "(*VStream).Where" case RefOfVStreamLimit: return "(*VStream).Limit" - case ValTupleOffset8: - return "(ValTuple).Offset8" - case ValTupleOffset32: - return "(ValTuple).Offset32" - case ValuesOffset8: - return "(Values).Offset8" - case ValuesOffset32: - return "(Values).Offset32" + case ValTuple8: + return "(ValTuple)[]8" + case ValTuple32: + return "(ValTuple)[]32" + case Values8: + return "(Values)[]8" + case Values32: + return "(Values)[]32" case RefOfValuesFuncExprName: return "(*ValuesFuncExpr).Name" case RefOfValuesStatementWith: @@ -1699,10 +1699,10 @@ func (s ASTStep) DebugString() string { return "(*WindowDefinition).Name" case RefOfWindowDefinitionWindowSpec: return "(*WindowDefinition).WindowSpec" - case WindowDefinitionsOffset8: - return "(WindowDefinitions).Offset8" - case WindowDefinitionsOffset32: - return "(WindowDefinitions).Offset32" + case WindowDefinitions8: + return "(WindowDefinitions)[]8" + case WindowDefinitions32: + return "(WindowDefinitions)[]32" case RefOfWindowSpecificationName: return "(*WindowSpecification).Name" case RefOfWindowSpecificationPartitionClause: @@ -1719,30 +1719,30 @@ func (s ASTStep) DebugString() string { return "(*XorExpr).Left" case RefOfXorExprRight: return "(*XorExpr).Right" - case SliceOfRefOfColumnDefinitionOffset8: - return "([]*ColumnDefinition).Offset8" - case SliceOfRefOfColumnDefinitionOffset32: - return "([]*ColumnDefinition).Offset32" - case SliceOfDatabaseOptionOffset8: - return "([]DatabaseOption).Offset8" - case SliceOfDatabaseOptionOffset32: - return "([]DatabaseOption).Offset32" - case SliceOfAlterOptionOffset8: - return "([]AlterOption).Offset8" - case SliceOfAlterOptionOffset32: - return "([]AlterOption).Offset32" - case SliceOfIdentifierCIOffset8: - return "([]IdentifierCI).Offset8" - case SliceOfIdentifierCIOffset32: - return "([]IdentifierCI).Offset32" - case SliceOfTxAccessModeOffset8: - return "([]TxAccessMode).Offset8" - case SliceOfTxAccessModeOffset32: - return "([]TxAccessMode).Offset32" - case SliceOfRefOfWhenOffset8: - return "([]*When).Offset8" - case SliceOfRefOfWhenOffset32: - return "([]*When).Offset32" + case SliceOfRefOfColumnDefinition8: + return "([]*ColumnDefinition)[]8" + case SliceOfRefOfColumnDefinition32: + return "([]*ColumnDefinition)[]32" + case SliceOfDatabaseOption8: + return "([]DatabaseOption)[]8" + case SliceOfDatabaseOption32: + return "([]DatabaseOption)[]32" + case SliceOfAlterOption8: + return "([]AlterOption)[]8" + case SliceOfAlterOption32: + return "([]AlterOption)[]32" + case SliceOfIdentifierCI8: + return "([]IdentifierCI)[]8" + case SliceOfIdentifierCI32: + return "([]IdentifierCI)[]32" + case SliceOfTxAccessMode8: + return "([]TxAccessMode)[]8" + case SliceOfTxAccessMode32: + return "([]TxAccessMode)[]32" + case SliceOfRefOfWhen8: + return "([]*When)[]8" + case SliceOfRefOfWhen32: + return "([]*When)[]32" case RefOfColumnTypeOptionsDefault: return "(*ColumnTypeOptions).Default" case RefOfColumnTypeOptionsOnUpdate: @@ -1759,38 +1759,38 @@ func (s ASTStep) DebugString() string { return "(*ColumnTypeOptions).SecondaryEngineAttribute" case RefOfColumnTypeOptionsSRID: return "(*ColumnTypeOptions).SRID" - case SliceOfStringOffset8: - return "([]string).Offset8" - case SliceOfStringOffset32: - return "([]string).Offset32" - case SliceOfTableExprOffset8: - return "([]TableExpr).Offset8" - case SliceOfTableExprOffset32: - return "([]TableExpr).Offset32" - case SliceOfRefOfVariableOffset8: - return "([]*Variable).Offset8" - case SliceOfRefOfVariableOffset32: - return "([]*Variable).Offset32" - case SliceOfExprOffset8: - return "([]Expr).Offset8" - case SliceOfExprOffset32: - return "([]Expr).Offset32" - case SliceOfRefOfIndexColumnOffset8: - return "([]*IndexColumn).Offset8" - case SliceOfRefOfIndexColumnOffset32: - return "([]*IndexColumn).Offset32" - case SliceOfRefOfIndexOptionOffset8: - return "([]*IndexOption).Offset8" - case SliceOfRefOfIndexOptionOffset32: - return "([]*IndexOption).Offset32" - case SliceOfRefOfJSONObjectParamOffset8: - return "([]*JSONObjectParam).Offset8" - case SliceOfRefOfJSONObjectParamOffset32: - return "([]*JSONObjectParam).Offset32" - case SliceOfRefOfJtColumnDefinitionOffset8: - return "([]*JtColumnDefinition).Offset8" - case SliceOfRefOfJtColumnDefinitionOffset32: - return "([]*JtColumnDefinition).Offset32" + case SliceOfString8: + return "([]string)[]8" + case SliceOfString32: + return "([]string)[]32" + case SliceOfTableExpr8: + return "([]TableExpr)[]8" + case SliceOfTableExpr32: + return "([]TableExpr)[]32" + case SliceOfRefOfVariable8: + return "([]*Variable)[]8" + case SliceOfRefOfVariable32: + return "([]*Variable)[]32" + case SliceOfExpr8: + return "([]Expr)[]8" + case SliceOfExpr32: + return "([]Expr)[]32" + case SliceOfRefOfIndexColumn8: + return "([]*IndexColumn)[]8" + case SliceOfRefOfIndexColumn32: + return "([]*IndexColumn)[]32" + case SliceOfRefOfIndexOption8: + return "([]*IndexOption)[]8" + case SliceOfRefOfIndexOption32: + return "([]*IndexOption)[]32" + case SliceOfRefOfJSONObjectParam8: + return "([]*JSONObjectParam)[]8" + case SliceOfRefOfJSONObjectParam32: + return "([]*JSONObjectParam)[]32" + case SliceOfRefOfJtColumnDefinition8: + return "([]*JtColumnDefinition)[]8" + case SliceOfRefOfJtColumnDefinition32: + return "([]*JtColumnDefinition)[]32" case RefOfJtOrdinalColDefName: return "(*JtOrdinalColDef).Name" case RefOfJtPathColDefName: @@ -1809,26 +1809,26 @@ func (s ASTStep) DebugString() string { return "(*JtNestedPathColDef).Columns8" case RefOfJtNestedPathColDefColumns32: return "(*JtNestedPathColDef).Columns32" - case TableAndLockTypesOffset8: - return "(TableAndLockTypes).Offset8" - case TableAndLockTypesOffset32: - return "(TableAndLockTypes).Offset32" - case SliceOfRefOfColNameOffset8: - return "([]*ColName).Offset8" - case SliceOfRefOfColNameOffset32: - return "([]*ColName).Offset32" - case CommentsOffset8: - return "(Comments).Offset8" - case CommentsOffset32: - return "(Comments).Offset32" - case SliceOfRefOfPartitionDefinitionOffset8: - return "([]*PartitionDefinition).Offset8" - case SliceOfRefOfPartitionDefinitionOffset32: - return "([]*PartitionDefinition).Offset32" - case SliceOfRefOfRenameTablePairOffset8: - return "([]*RenameTablePair).Offset8" - case SliceOfRefOfRenameTablePairOffset32: - return "([]*RenameTablePair).Offset32" + case TableAndLockTypes8: + return "(TableAndLockTypes)[]8" + case TableAndLockTypes32: + return "(TableAndLockTypes)[]32" + case SliceOfRefOfColName8: + return "([]*ColName)[]8" + case SliceOfRefOfColName32: + return "([]*ColName)[]32" + case Comments8: + return "(Comments)[]8" + case Comments32: + return "(Comments)[]32" + case SliceOfRefOfPartitionDefinition8: + return "([]*PartitionDefinition)[]8" + case SliceOfRefOfPartitionDefinition32: + return "([]*PartitionDefinition)[]32" + case SliceOfRefOfRenameTablePair8: + return "([]*RenameTablePair)[]8" + case SliceOfRefOfRenameTablePair32: + return "([]*RenameTablePair)[]32" case RefOfRootNodeSQLNode: return "(*RootNode).SQLNode" case RefOfTableNameName: @@ -1839,24 +1839,24 @@ func (s ASTStep) DebugString() string { return "(*TableOption).Value" case RefOfTableOptionTables: return "(*TableOption).Tables" - case SliceOfRefOfIndexDefinitionOffset8: - return "([]*IndexDefinition).Offset8" - case SliceOfRefOfIndexDefinitionOffset32: - return "([]*IndexDefinition).Offset32" - case SliceOfRefOfConstraintDefinitionOffset8: - return "([]*ConstraintDefinition).Offset8" - case SliceOfRefOfConstraintDefinitionOffset32: - return "([]*ConstraintDefinition).Offset32" + case SliceOfRefOfIndexDefinition8: + return "([]*IndexDefinition)[]8" + case SliceOfRefOfIndexDefinition32: + return "([]*IndexDefinition)[]32" + case SliceOfRefOfConstraintDefinition8: + return "([]*ConstraintDefinition)[]8" + case SliceOfRefOfConstraintDefinition32: + return "([]*ConstraintDefinition)[]32" case RefOfVindexParamKey: return "(*VindexParam).Key" - case SliceOfVindexParamOffset8: - return "([]VindexParam).Offset8" - case SliceOfVindexParamOffset32: - return "([]VindexParam).Offset32" - case SliceOfRefOfCommonTableExprOffset8: - return "([]*CommonTableExpr).Offset8" - case SliceOfRefOfCommonTableExprOffset32: - return "([]*CommonTableExpr).Offset32" + case SliceOfVindexParam8: + return "([]VindexParam)[]8" + case SliceOfVindexParam32: + return "([]VindexParam)[]32" + case SliceOfRefOfCommonTableExpr8: + return "([]*CommonTableExpr)[]8" + case SliceOfRefOfCommonTableExpr32: + return "([]*CommonTableExpr)[]32" case RefOfIndexColumnColumn: return "(*IndexColumn).Column" case RefOfIndexColumnExpression: diff --git a/go/vt/vtgate/semantics/analyzer.go b/go/vt/vtgate/semantics/analyzer.go index c4e7dc55866..02d592d79bf 100644 --- a/go/vt/vtgate/semantics/analyzer.go +++ b/go/vt/vtgate/semantics/analyzer.go @@ -384,7 +384,7 @@ func (a *analyzer) analyze(statement sqlparser.Statement) error { } func (a *analyzer) lateAnalyze(statement sqlparser.SQLNode) error { - _ = sqlparser.Rewrite(statement, a.analyzeDown, a.analyzeUp) + _ = sqlparser.RewriteWithPath(statement, a.analyzeDown, a.analyzeUp) return a.err } From 15c4d8b8f519f5fed892063bfdaa9195ca545f55 Mon Sep 17 00:00:00 2001 From: Andres Taylor Date: Fri, 31 Jan 2025 09:01:58 +0100 Subject: [PATCH 12/13] update generation of enums Signed-off-by: Andres Taylor --- go/tools/asthelpergen/ast_path_gen.go | 72 +++++++++++-------- go/tools/asthelpergen/integration/ast_path.go | 14 +--- go/vt/sqlparser/ast_path.go | 54 -------------- 3 files changed, 43 insertions(+), 97 deletions(-) diff --git a/go/tools/asthelpergen/ast_path_gen.go b/go/tools/asthelpergen/ast_path_gen.go index 6844433f246..d6784bf0c9f 100644 --- a/go/tools/asthelpergen/ast_path_gen.go +++ b/go/tools/asthelpergen/ast_path_gen.go @@ -31,9 +31,9 @@ type ( } step struct { container types.Type // the type of the container + typ types.Type // the type of the field name string // the name of the field slice bool // whether the field is a slice - typ types.Type // the type of the field } ) @@ -92,8 +92,9 @@ func (p *pathGen) ptrToStructMethod(t types.Type, strct *types.Struct, spi gener } func (p *pathGen) addStructFields(t types.Type, strct *types.Struct, spi generatorSPI) { - for i := range strct.NumFields() { + for i := 0; i < strct.NumFields(); i++ { field := strct.Field(i) + // Check if the field type implements the interface if types.Implements(field.Type(), spi.iface()) { p.steps = append(p.steps, step{ container: t, @@ -102,14 +103,26 @@ func (p *pathGen) addStructFields(t types.Type, strct *types.Struct, spi generat }) continue } + // Check if the field type is a slice slice, isSlice := field.Type().(*types.Slice) - if isSlice && types.Implements(slice.Elem(), spi.iface()) { - p.steps = append(p.steps, step{ - container: t, - slice: true, - name: field.Name(), - typ: slice.Elem(), - }) + if isSlice { + // Check if the slice type implements the interface + if types.Implements(slice, spi.iface()) { + p.steps = append(p.steps, step{ + container: t, + slice: true, + name: field.Name(), + typ: slice, + }) + } else if types.Implements(slice.Elem(), spi.iface()) { + // Check if the element type of the slice implements the interface + p.steps = append(p.steps, step{ + container: t, + slice: true, + name: field.Name(), + typ: slice.Elem(), + }) + } } } } @@ -118,13 +131,16 @@ func (p *pathGen) ptrToBasicMethod(t types.Type, basic *types.Basic, spi generat return nil } -func (p *pathGen) sliceMethod(t types.Type, _ *types.Slice, _ generatorSPI) error { - p.steps = append(p.steps, step{ - container: t, - name: sliceMarker, - slice: true, - typ: t, - }) +func (p *pathGen) sliceMethod(t types.Type, slice *types.Slice, spi generatorSPI) error { + elemType := slice.Elem() + if types.Implements(elemType, spi.iface()) { + p.steps = append(p.steps, step{ + container: t, + name: sliceMarker, + slice: true, + typ: elemType, + }) + } return nil } @@ -202,9 +218,6 @@ func (p *pathGen) generateWalkASTPath(spi generatorSPI) *jen.Statement { jen.Id("node").Id(p.ifaceName), jen.Id("path").Id("ASTPath"), ).Id(p.ifaceName).Block( - jen.If(jen.Len(jen.Id("path")).Op("<").Lit(2)).Block( - jen.Return(jen.Nil()), - ), jen.Id("step").Op(":=").Qual("encoding/binary", "BigEndian").Dot("Uint16").Call(jen.Index().Byte().Parens(jen.Id("path[:2]"))), jen.Id("path").Op("=").Id("path[2:]"), @@ -232,25 +245,24 @@ func (p *pathGen) generateWalkCases() []jen.Code { continue } - var el1 jen.Code var assignNode jen.Code + t := types.TypeString(step.container, noQualifier) if step.name == sliceMarker { - el1 = jen.Id("node") - assignNode = jen.Id("node").Op("=").Id("node").Index(jen.Id("idx")) + assignNode = jen.Id("node").Dot(fmt.Sprintf("(%s)", t)).Index(jen.Id("idx")) } else { - el1 = jen.Id("node").Dot(step.name) - assignNode = jen.Id("node").Op("=").Id("node").Dot(step.name).Index(jen.Id("idx")) + assignNode = jen.Id("node").Dot(step.name).Index(jen.Id("idx")) } cases = append(cases, jen.Case(jen.Id(stepName+"8")).Block( - jen.If(jen.Len(jen.Id("path")).Op("<").Lit(2)).Block(jen.Return(jen.Nil())), + jen.Id("idx").Op(":=").Id("path[0]"), + jen.Id("path").Op("=").Id("path[1:]"), + jen.Return(jen.Id("WalkASTPath").Call(assignNode, jen.Id("path"))), + )) + + cases = append(cases, jen.Case(jen.Id(stepName+"32")).Block( jen.Id("idx").Op(":=").Qual("encoding/binary", "BigEndian").Dot("Uint16").Call(jen.Index().Byte().Parens(jen.Id("path[:2]"))), jen.Id("path").Op("=").Id("path[2:]"), - jen.If(jen.Id("int(idx)").Op("<").Lit(0).Op("||").Id("int(idx)").Op(">=").Len(el1)).Block( - jen.Return(jen.Nil()), - ), - assignNode, - jen.Return(jen.Id("WalkASTPath").Call(jen.Id("node"), jen.Id("path"))), + jen.Return(jen.Id("WalkASTPath").Call(assignNode, jen.Id("path"))), )) } diff --git a/go/tools/asthelpergen/integration/ast_path.go b/go/tools/asthelpergen/integration/ast_path.go index 3dc2fe89c21..87cb659c430 100644 --- a/go/tools/asthelpergen/integration/ast_path.go +++ b/go/tools/asthelpergen/integration/ast_path.go @@ -20,9 +20,7 @@ package integration type ASTStep uint16 const ( - Bytes8 ASTStep = iota - Bytes32 - InterfaceSlice8 + InterfaceSlice8 ASTStep = iota InterfaceSlice32 LeafSlice8 LeafSlice32 @@ -40,8 +38,6 @@ const ( ValueSliceContainerASTImplementationElements SliceOfAST8 SliceOfAST32 - SliceOfInt8 - SliceOfInt32 SliceOfRefOfLeaf8 SliceOfRefOfLeaf32 RefOfValueContainerASTType @@ -53,10 +49,6 @@ const ( func (s ASTStep) DebugString() string { switch s { - case Bytes8: - return "(Bytes)[]8" - case Bytes32: - return "(Bytes)[]32" case InterfaceSlice8: return "(InterfaceSlice)[]8" case InterfaceSlice32: @@ -93,10 +85,6 @@ func (s ASTStep) DebugString() string { return "([]AST)[]8" case SliceOfAST32: return "([]AST)[]32" - case SliceOfInt8: - return "([]int)[]8" - case SliceOfInt32: - return "([]int)[]32" case SliceOfRefOfLeaf8: return "([]*Leaf)[]8" case SliceOfRefOfLeaf32: diff --git a/go/vt/sqlparser/ast_path.go b/go/vt/sqlparser/ast_path.go index 58009b722ef..0e76bccf4a2 100644 --- a/go/vt/sqlparser/ast_path.go +++ b/go/vt/sqlparser/ast_path.go @@ -475,8 +475,6 @@ const ( TableNameQualifier TableNames8 TableNames32 - TableOptions8 - TableOptions32 RefOfTableSpecColumns8 RefOfTableSpecColumns32 RefOfTableSpecIndexes8 @@ -562,14 +560,10 @@ const ( RefOfXorExprRight SliceOfRefOfColumnDefinition8 SliceOfRefOfColumnDefinition32 - SliceOfDatabaseOption8 - SliceOfDatabaseOption32 SliceOfAlterOption8 SliceOfAlterOption32 SliceOfIdentifierCI8 SliceOfIdentifierCI32 - SliceOfTxAccessMode8 - SliceOfTxAccessMode32 SliceOfRefOfWhen8 SliceOfRefOfWhen32 RefOfColumnTypeOptionsDefault @@ -580,18 +574,12 @@ const ( RefOfColumnTypeOptionsEngineAttribute RefOfColumnTypeOptionsSecondaryEngineAttribute RefOfColumnTypeOptionsSRID - SliceOfString8 - SliceOfString32 SliceOfTableExpr8 SliceOfTableExpr32 SliceOfRefOfVariable8 SliceOfRefOfVariable32 SliceOfExpr8 SliceOfExpr32 - SliceOfRefOfIndexColumn8 - SliceOfRefOfIndexColumn32 - SliceOfRefOfIndexOption8 - SliceOfRefOfIndexOption32 SliceOfRefOfJSONObjectParam8 SliceOfRefOfJSONObjectParam32 SliceOfRefOfJtColumnDefinition8 @@ -605,16 +593,10 @@ const ( RefOfJtNestedPathColDefPath RefOfJtNestedPathColDefColumns8 RefOfJtNestedPathColDefColumns32 - TableAndLockTypes8 - TableAndLockTypes32 SliceOfRefOfColName8 SliceOfRefOfColName32 - Comments8 - Comments32 SliceOfRefOfPartitionDefinition8 SliceOfRefOfPartitionDefinition32 - SliceOfRefOfRenameTablePair8 - SliceOfRefOfRenameTablePair32 RefOfRootNodeSQLNode RefOfTableNameName RefOfTableNameQualifier @@ -1549,10 +1531,6 @@ func (s ASTStep) DebugString() string { return "(TableNames)[]8" case TableNames32: return "(TableNames)[]32" - case TableOptions8: - return "(TableOptions)[]8" - case TableOptions32: - return "(TableOptions)[]32" case RefOfTableSpecColumns8: return "(*TableSpec).Columns8" case RefOfTableSpecColumns32: @@ -1723,10 +1701,6 @@ func (s ASTStep) DebugString() string { return "([]*ColumnDefinition)[]8" case SliceOfRefOfColumnDefinition32: return "([]*ColumnDefinition)[]32" - case SliceOfDatabaseOption8: - return "([]DatabaseOption)[]8" - case SliceOfDatabaseOption32: - return "([]DatabaseOption)[]32" case SliceOfAlterOption8: return "([]AlterOption)[]8" case SliceOfAlterOption32: @@ -1735,10 +1709,6 @@ func (s ASTStep) DebugString() string { return "([]IdentifierCI)[]8" case SliceOfIdentifierCI32: return "([]IdentifierCI)[]32" - case SliceOfTxAccessMode8: - return "([]TxAccessMode)[]8" - case SliceOfTxAccessMode32: - return "([]TxAccessMode)[]32" case SliceOfRefOfWhen8: return "([]*When)[]8" case SliceOfRefOfWhen32: @@ -1759,10 +1729,6 @@ func (s ASTStep) DebugString() string { return "(*ColumnTypeOptions).SecondaryEngineAttribute" case RefOfColumnTypeOptionsSRID: return "(*ColumnTypeOptions).SRID" - case SliceOfString8: - return "([]string)[]8" - case SliceOfString32: - return "([]string)[]32" case SliceOfTableExpr8: return "([]TableExpr)[]8" case SliceOfTableExpr32: @@ -1775,14 +1741,6 @@ func (s ASTStep) DebugString() string { return "([]Expr)[]8" case SliceOfExpr32: return "([]Expr)[]32" - case SliceOfRefOfIndexColumn8: - return "([]*IndexColumn)[]8" - case SliceOfRefOfIndexColumn32: - return "([]*IndexColumn)[]32" - case SliceOfRefOfIndexOption8: - return "([]*IndexOption)[]8" - case SliceOfRefOfIndexOption32: - return "([]*IndexOption)[]32" case SliceOfRefOfJSONObjectParam8: return "([]*JSONObjectParam)[]8" case SliceOfRefOfJSONObjectParam32: @@ -1809,26 +1767,14 @@ func (s ASTStep) DebugString() string { return "(*JtNestedPathColDef).Columns8" case RefOfJtNestedPathColDefColumns32: return "(*JtNestedPathColDef).Columns32" - case TableAndLockTypes8: - return "(TableAndLockTypes)[]8" - case TableAndLockTypes32: - return "(TableAndLockTypes)[]32" case SliceOfRefOfColName8: return "([]*ColName)[]8" case SliceOfRefOfColName32: return "([]*ColName)[]32" - case Comments8: - return "(Comments)[]8" - case Comments32: - return "(Comments)[]32" case SliceOfRefOfPartitionDefinition8: return "([]*PartitionDefinition)[]8" case SliceOfRefOfPartitionDefinition32: return "([]*PartitionDefinition)[]32" - case SliceOfRefOfRenameTablePair8: - return "([]*RenameTablePair)[]8" - case SliceOfRefOfRenameTablePair32: - return "([]*RenameTablePair)[]32" case RefOfRootNodeSQLNode: return "(*RootNode).SQLNode" case RefOfTableNameName: From 9807745addbf3046ee1d50e961c006dadd72c872 Mon Sep 17 00:00:00 2001 From: Andres Taylor Date: Fri, 31 Jan 2025 10:21:46 +0100 Subject: [PATCH 13/13] wip --- go/tools/asthelpergen/ast_path_gen.go | 67 +++++++------- go/tools/asthelpergen/integration/ast_path.go | 88 +++++++++++++------ .../asthelpergen/integration/ast_path_test.go | 67 ++++++++++++++ .../asthelpergen/integration/test_helpers.go | 73 +++++++++++++++ 4 files changed, 237 insertions(+), 58 deletions(-) create mode 100644 go/tools/asthelpergen/integration/ast_path_test.go diff --git a/go/tools/asthelpergen/ast_path_gen.go b/go/tools/asthelpergen/ast_path_gen.go index d6784bf0c9f..8b981b46f81 100644 --- a/go/tools/asthelpergen/ast_path_gen.go +++ b/go/tools/asthelpergen/ast_path_gen.go @@ -72,7 +72,7 @@ func (p *pathGen) genFile(spi generatorSPI) (string, *jen.File) { p.file.Add(p.debugString()) // Add the generated WalkASTPath method - p.file.Add(p.generateWalkASTPath(spi)) + p.file.Add(p.generateWalkASTPath()) return "ast_path.go", p.file } @@ -91,16 +91,30 @@ func (p *pathGen) ptrToStructMethod(t types.Type, strct *types.Struct, spi gener return nil } +func (p *pathGen) addStep( + container types.Type, // the name of the container type + typ types.Type, // the type of the field + name string, // the name of the field + slice bool, // whether the field is a slice +) { + s := step{ + container: container, + name: name, + typ: typ, + slice: slice, + } + stepName := s.AsEnum() + fmt.Println("Adding step:", stepName) + p.steps = append(p.steps, s) + +} + func (p *pathGen) addStructFields(t types.Type, strct *types.Struct, spi generatorSPI) { for i := 0; i < strct.NumFields(); i++ { field := strct.Field(i) // Check if the field type implements the interface if types.Implements(field.Type(), spi.iface()) { - p.steps = append(p.steps, step{ - container: t, - name: field.Name(), - typ: field.Type(), - }) + p.addStep(t, field.Type(), field.Name(), false) continue } // Check if the field type is a slice @@ -108,20 +122,10 @@ func (p *pathGen) addStructFields(t types.Type, strct *types.Struct, spi generat if isSlice { // Check if the slice type implements the interface if types.Implements(slice, spi.iface()) { - p.steps = append(p.steps, step{ - container: t, - slice: true, - name: field.Name(), - typ: slice, - }) + p.addStep(t, slice, field.Name(), true) } else if types.Implements(slice.Elem(), spi.iface()) { // Check if the element type of the slice implements the interface - p.steps = append(p.steps, step{ - container: t, - slice: true, - name: field.Name(), - typ: slice.Elem(), - }) + p.addStep(t, slice.Elem(), field.Name(), true) } } } @@ -132,16 +136,11 @@ func (p *pathGen) ptrToBasicMethod(t types.Type, basic *types.Basic, spi generat } func (p *pathGen) sliceMethod(t types.Type, slice *types.Slice, spi generatorSPI) error { - elemType := slice.Elem() - if types.Implements(elemType, spi.iface()) { - p.steps = append(p.steps, step{ - container: t, - name: sliceMarker, - slice: true, - typ: elemType, - }) - } - + //elemType := slice.Elem() + //if types.Implements(elemType, spi.iface()) { + // p.addStep(t, elemType, sliceMarker, true) + //} + // return nil } @@ -213,11 +212,13 @@ func (p *pathGen) buildConstWithEnum() *jen.Statement { return constBlock } -func (p *pathGen) generateWalkASTPath(spi generatorSPI) *jen.Statement { +func (p *pathGen) generateWalkASTPath() *jen.Statement { method := jen.Func().Id("WalkASTPath").Params( jen.Id("node").Id(p.ifaceName), jen.Id("path").Id("ASTPath"), ).Id(p.ifaceName).Block( + jen.If(jen.Id("path").Op("==").Id(`""`).Block( + jen.Return(jen.Id("node")))), jen.Id("step").Op(":=").Qual("encoding/binary", "BigEndian").Dot("Uint16").Call(jen.Index().Byte().Parens(jen.Id("path[:2]"))), jen.Id("path").Op("=").Id("path[2:]"), @@ -235,7 +236,7 @@ func (p *pathGen) generateWalkCases() []jen.Code { if !step.slice { // return WalkASTPath(node.(*RefContainer).ASTType, path) - t := types.TypeString(step.typ, noQualifier) + t := types.TypeString(step.container, noQualifier) n := jen.Id("node").Dot(fmt.Sprintf("(%s)", t)).Dot(step.name) cases = append(cases, jen.Case(jen.Id(stepName)).Block( @@ -250,7 +251,7 @@ func (p *pathGen) generateWalkCases() []jen.Code { if step.name == sliceMarker { assignNode = jen.Id("node").Dot(fmt.Sprintf("(%s)", t)).Index(jen.Id("idx")) } else { - assignNode = jen.Id("node").Dot(step.name).Index(jen.Id("idx")) + assignNode = jen.Id("node").Dot(fmt.Sprintf("(%s)", t)).Dot(step.name).Index(jen.Id("idx")) } cases = append(cases, jen.Case(jen.Id(stepName+"8")).Block( @@ -260,8 +261,8 @@ func (p *pathGen) generateWalkCases() []jen.Code { )) cases = append(cases, jen.Case(jen.Id(stepName+"32")).Block( - jen.Id("idx").Op(":=").Qual("encoding/binary", "BigEndian").Dot("Uint16").Call(jen.Index().Byte().Parens(jen.Id("path[:2]"))), - jen.Id("path").Op("=").Id("path[2:]"), + jen.Id("idx").Op(":=").Qual("encoding/binary", "BigEndian").Dot("Uint32").Call(jen.Index().Byte().Parens(jen.Id("path[:2]"))), + jen.Id("path").Op("=").Id("path[4:]"), jen.Return(jen.Id("WalkASTPath").Call(assignNode, jen.Id("path"))), )) } diff --git a/go/tools/asthelpergen/integration/ast_path.go b/go/tools/asthelpergen/integration/ast_path.go index 87cb659c430..986b6dda8f4 100644 --- a/go/tools/asthelpergen/integration/ast_path.go +++ b/go/tools/asthelpergen/integration/ast_path.go @@ -17,14 +17,12 @@ limitations under the License. package integration +import "encoding/binary" + type ASTStep uint16 const ( - InterfaceSlice8 ASTStep = iota - InterfaceSlice32 - LeafSlice8 - LeafSlice32 - RefOfRefContainerASTType + RefOfRefContainerASTType ASTStep = iota RefOfRefContainerASTImplementationType RefOfRefSliceContainerASTElements8 RefOfRefSliceContainerASTElements32 @@ -36,10 +34,6 @@ const ( ValueSliceContainerASTElements8 ValueSliceContainerASTElements32 ValueSliceContainerASTImplementationElements - SliceOfAST8 - SliceOfAST32 - SliceOfRefOfLeaf8 - SliceOfRefOfLeaf32 RefOfValueContainerASTType RefOfValueContainerASTImplementationType RefOfValueSliceContainerASTElements8 @@ -49,14 +43,6 @@ const ( func (s ASTStep) DebugString() string { switch s { - case InterfaceSlice8: - return "(InterfaceSlice)[]8" - case InterfaceSlice32: - return "(InterfaceSlice)[]32" - case LeafSlice8: - return "(LeafSlice)[]8" - case LeafSlice32: - return "(LeafSlice)[]32" case RefOfRefContainerASTType: return "(*RefContainer).ASTType" case RefOfRefContainerASTImplementationType: @@ -81,14 +67,6 @@ func (s ASTStep) DebugString() string { return "(ValueSliceContainer).ASTElements32" case ValueSliceContainerASTImplementationElements: return "(ValueSliceContainer).ASTImplementationElements" - case SliceOfAST8: - return "([]AST)[]8" - case SliceOfAST32: - return "([]AST)[]32" - case SliceOfRefOfLeaf8: - return "([]*Leaf)[]8" - case SliceOfRefOfLeaf32: - return "([]*Leaf)[]32" case RefOfValueContainerASTType: return "(*ValueContainer).ASTType" case RefOfValueContainerASTImplementationType: @@ -102,3 +80,63 @@ func (s ASTStep) DebugString() string { } panic("unknown ASTStep") } +func WalkASTPath(node AST, path ASTPath) AST { + if path == "" { + return node + } + step := binary.BigEndian.Uint16([]byte(path[:2])) + path = path[2:] + switch ASTStep(step) { + case RefOfRefContainerASTType: + return WalkASTPath(node.(*RefContainer).ASTType, path) + case RefOfRefContainerASTImplementationType: + return WalkASTPath(node.(*RefContainer).ASTImplementationType, path) + case RefOfRefSliceContainerASTElements8: + idx := path[0] + path = path[1:] + return WalkASTPath(node.(*RefSliceContainer).ASTElements[idx], path) + case RefOfRefSliceContainerASTElements32: + idx := binary.BigEndian.Uint32([]byte(path[:2])) + path = path[4:] + return WalkASTPath(node.(*RefSliceContainer).ASTElements[idx], path) + case RefOfRefSliceContainerASTImplementationElements8: + idx := path[0] + path = path[1:] + return WalkASTPath(node.(*RefSliceContainer).ASTImplementationElements[idx], path) + case RefOfRefSliceContainerASTImplementationElements32: + idx := binary.BigEndian.Uint32([]byte(path[:2])) + path = path[4:] + return WalkASTPath(node.(*RefSliceContainer).ASTImplementationElements[idx], path) + case RefOfSubImplinner: + return WalkASTPath(node.(*SubImpl).inner, path) + case ValueContainerASTType: + return WalkASTPath(node.(ValueContainer).ASTType, path) + case ValueContainerASTImplementationType: + return WalkASTPath(node.(ValueContainer).ASTImplementationType, path) + case ValueSliceContainerASTElements8: + idx := path[0] + path = path[1:] + return WalkASTPath(node.(ValueSliceContainer).ASTElements[idx], path) + case ValueSliceContainerASTElements32: + idx := binary.BigEndian.Uint32([]byte(path[:2])) + path = path[4:] + return WalkASTPath(node.(ValueSliceContainer).ASTElements[idx], path) + case ValueSliceContainerASTImplementationElements: + return WalkASTPath(node.(ValueSliceContainer).ASTImplementationElements, path) + case RefOfValueContainerASTType: + return WalkASTPath(node.(*ValueContainer).ASTType, path) + case RefOfValueContainerASTImplementationType: + return WalkASTPath(node.(*ValueContainer).ASTImplementationType, path) + case RefOfValueSliceContainerASTElements8: + idx := path[0] + path = path[1:] + return WalkASTPath(node.(*ValueSliceContainer).ASTElements[idx], path) + case RefOfValueSliceContainerASTElements32: + idx := binary.BigEndian.Uint32([]byte(path[:2])) + path = path[4:] + return WalkASTPath(node.(*ValueSliceContainer).ASTElements[idx], path) + case RefOfValueSliceContainerASTImplementationElements: + return WalkASTPath(node.(*ValueSliceContainer).ASTImplementationElements, path) + } + return nil +} diff --git a/go/tools/asthelpergen/integration/ast_path_test.go b/go/tools/asthelpergen/integration/ast_path_test.go new file mode 100644 index 00000000000..e32956fac37 --- /dev/null +++ b/go/tools/asthelpergen/integration/ast_path_test.go @@ -0,0 +1,67 @@ +/* +Copyright 2025 The Vitess Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package integration + +import ( + "fmt" + "github.com/stretchr/testify/assert" + "reflect" + "testing" +) + +func TestWalkAllPartsOfAST(t *testing.T) { + sliceContainer := &RefSliceContainer{ + something: 12, + ASTElements: []AST{}, + NotASTElements: []int{1, 2}, + ASTImplementationElements: []*Leaf{{v: 1}, {v: 2}}, + } + + for i := range 300 { + sliceContainer.ASTImplementationElements = append(sliceContainer.ASTImplementationElements, &Leaf{v: i}) + } + + ast := &RefContainer{ + ASTType: sliceContainer, + NotASTType: 2, + ASTImplementationType: &Leaf{v: 3}, + } + + v := make(map[ASTPath]AST) + + RewriteWithPaths(ast, func(c *Cursor) bool { + node := c.Node() + if !reflect.TypeOf(node).Comparable() { + return true + } + current := c.current + v[current] = node + return true + }, nil) + + fmt.Println("walked all parts of AST") + + assert.NotEmpty(t, v) + + for path, n1 := range v { + s := path.DebugString() + fmt.Println(s) + + n2 := WalkASTPath(ast, path) + assert.Equal(t, n1, n2) + } +} diff --git a/go/tools/asthelpergen/integration/test_helpers.go b/go/tools/asthelpergen/integration/test_helpers.go index 64278f3c357..592cda2e19e 100644 --- a/go/tools/asthelpergen/integration/test_helpers.go +++ b/go/tools/asthelpergen/integration/test_helpers.go @@ -17,6 +17,8 @@ limitations under the License. package integration import ( + "encoding/binary" + "fmt" "strings" ) @@ -100,6 +102,22 @@ func Rewrite(node AST, pre, post ApplyFunc) AST { return outer.AST } +func RewriteWithPaths(node AST, pre, post ApplyFunc) AST { + outer := &struct{ AST }{node} + + a := &application{ + pre: pre, + post: post, + collectPaths: true, + } + + a.rewriteAST(outer, node, func(newNode, parent AST) { + outer.AST = newNode + }) + + return outer.AST +} + type ( cow struct { pre func(node, parent AST) bool @@ -115,3 +133,58 @@ type ( func (c *cow) postVisit(a, b AST, d bool) (AST, bool) { return a, d } + +func (path ASTPath) DebugString() string { + var sb strings.Builder + + remaining := []byte(path) + stepCount := 0 + + for len(remaining) >= 2 { + // Read the step code (2 bytes) + stepVal := binary.BigEndian.Uint16(remaining[:2]) + remaining = remaining[2:] + + step := ASTStep(stepVal) + stepStr := step.DebugString() // e.g. "CaseExprWhens8" or "CaseExprWhens32" + + // If this isn't the very first step in the path, prepend a separator + if stepCount > 0 { + sb.WriteString("->") + } + stepCount++ + + // Write the step name + sb.WriteString(stepStr) + + // Check suffix to see if we need to read an offset + switch { + // 1-byte offset if stepStr ends with "8" + case strings.HasSuffix(stepStr, "8"): + if len(remaining) < 1 { + sb.WriteString("(ERR-no-offset-byte)") + return sb.String() + } + offsetByte := remaining[0] + remaining = remaining[1:] + sb.WriteString(fmt.Sprintf("(%d)", offsetByte)) + + // 4-byte offset if stepStr ends with "32" + case strings.HasSuffix(stepStr, "32"): + if len(remaining) < 4 { + sb.WriteString("(ERR-no-offset-uint32)") + return sb.String() + } + offsetVal := binary.BigEndian.Uint32(remaining[:4]) + remaining = remaining[4:] + sb.WriteString(fmt.Sprintf("(%d)", offsetVal)) + } + } + + // If there's leftover data that doesn't fit into 2 (or more) bytes, you could note it: + if len(remaining) != 0 { + sb.WriteString("->(ERR-unaligned-extra-bytes)") + } + + return sb.String() +}