diff --git a/go/tools/asthelpergen/integration/ast_rewrite.go b/go/tools/asthelpergen/integration/ast_rewrite.go index 7a6f1161b91..5c20afad21c 100644 --- a/go/tools/asthelpergen/integration/ast_rewrite.go +++ b/go/tools/asthelpergen/integration/ast_rewrite.go @@ -126,7 +126,7 @@ func (a *application) rewriteInterfaceSlice(parent AST, node InterfaceSlice, rep for x, el := range node { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(InterfaceSliceOffset), x) + a.cur.current.AddStepWithOffset(uint16(InterfaceSliceOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -201,7 +201,7 @@ func (a *application) rewriteLeafSlice(parent AST, node LeafSlice, replacer repl for x, el := range node { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(LeafSliceOffset), x) + a.cur.current.AddStepWithOffset(uint16(LeafSliceOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -326,7 +326,7 @@ func (a *application) rewriteRefOfRefSliceContainer(parent AST, node *RefSliceCo for x, el := range node.ASTElements { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(RefOfRefSliceContainerASTElementsOffset), x) + a.cur.current.AddStepWithOffset(uint16(RefOfRefSliceContainerASTElementsOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -345,7 +345,7 @@ func (a *application) rewriteRefOfRefSliceContainer(parent AST, node *RefSliceCo for x, el := range node.ASTImplementationElements { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(RefOfRefSliceContainerASTImplementationElementsOffset), x) + a.cur.current.AddStepWithOffset(uint16(RefOfRefSliceContainerASTImplementationElementsOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -473,7 +473,7 @@ func (a *application) rewriteValueSliceContainer(parent AST, node ValueSliceCont for x, el := range node.ASTElements { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(ValueSliceContainerASTElementsOffset), x) + a.cur.current.AddStepWithOffset(uint16(ValueSliceContainerASTElementsOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -643,7 +643,7 @@ func (a *application) rewriteRefOfValueSliceContainer(parent AST, node *ValueSli for x, el := range node.ASTElements { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(RefOfValueSliceContainerASTElementsOffset), x) + a.cur.current.AddStepWithOffset(uint16(RefOfValueSliceContainerASTElementsOffset)) } else { a.cur.current.ChangeOffset(x) } diff --git a/go/tools/asthelpergen/rewrite_gen.go b/go/tools/asthelpergen/rewrite_gen.go index 768e7cd2690..31c3c6f75ed 100644 --- a/go/tools/asthelpergen/rewrite_gen.go +++ b/go/tools/asthelpergen/rewrite_gen.go @@ -415,14 +415,14 @@ func (r *rewriteGen) rewriteChildSlice(t, field types.Type, fieldName string, pa // if a.collectPaths { // if x == 0 { - // a.cur.current.AddStepWithSliceIndex(LeafSliceOffset, x) + // a.cur.current.AddStepWithOffset(LeafSliceOffset) // } else { // a.cur.current.ChangeOffset(x) // } // } savePath := jen.If(jen.Id("a.collectPaths")).Block( jen.If(jen.Id("x").Op("==").Lit(0)).Block( - jen.Id("a.cur.current.AddStepWithOffset").Params(jen.Id("uint16").Params(jen.Id(printableTypeName(t)+fieldName+"Offset")), jen.Id("x")), + jen.Id("a.cur.current.AddStepWithOffset").Params(jen.Id("uint16").Params(jen.Id(printableTypeName(t) + fieldName + "Offset"))), ).Else().Block( jen.Id("a.cur.current.ChangeOffset").Params(jen.Id("x")), ), diff --git a/go/vt/sqlparser/ast_rewrite.go b/go/vt/sqlparser/ast_rewrite.go index f501f9bad8f..bdeff6b7789 100644 --- a/go/vt/sqlparser/ast_rewrite.go +++ b/go/vt/sqlparser/ast_rewrite.go @@ -592,7 +592,7 @@ func (a *application) rewriteRefOfAddColumns(parent SQLNode, node *AddColumns, r for x, el := range node.Columns { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(RefOfAddColumnsColumnsOffset), x) + a.cur.current.AddStepWithOffset(uint16(RefOfAddColumnsColumnsOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -1092,7 +1092,7 @@ func (a *application) rewriteRefOfAlterTable(parent SQLNode, node *AlterTable, r for x, el := range node.AlterOptions { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(RefOfAlterTableAlterOptionsOffset), x) + a.cur.current.AddStepWithOffset(uint16(RefOfAlterTableAlterOptionsOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -1259,7 +1259,7 @@ func (a *application) rewriteRefOfAlterVschema(parent SQLNode, node *AlterVschem for x, el := range node.VindexCols { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(RefOfAlterVschemaVindexColsOffset), x) + a.cur.current.AddStepWithOffset(uint16(RefOfAlterVschemaVindexColsOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -1929,7 +1929,7 @@ func (a *application) rewriteRefOfCallProc(parent SQLNode, node *CallProc, repla for x, el := range node.Params { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(RefOfCallProcParamsOffset), x) + a.cur.current.AddStepWithOffset(uint16(RefOfCallProcParamsOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -1986,7 +1986,7 @@ func (a *application) rewriteRefOfCaseExpr(parent SQLNode, node *CaseExpr, repla for x, el := range node.Whens { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(RefOfCaseExprWhensOffset), x) + a.cur.current.AddStepWithOffset(uint16(RefOfCaseExprWhensOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -2147,7 +2147,7 @@ func (a *application) rewriteRefOfCharExpr(parent SQLNode, node *CharExpr, repla for x, el := range node.Exprs { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(RefOfCharExprExprsOffset), x) + a.cur.current.AddStepWithOffset(uint16(RefOfCharExprExprsOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -2392,7 +2392,7 @@ func (a *application) rewriteColumns(parent SQLNode, node Columns, replacer repl for x, el := range node { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(ColumnsOffset), x) + a.cur.current.AddStepWithOffset(uint16(ColumnsOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -2772,7 +2772,7 @@ func (a *application) rewriteRefOfCount(parent SQLNode, node *Count, replacer re for x, el := range node.Args { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(RefOfCountArgsOffset), x) + a.cur.current.AddStepWithOffset(uint16(RefOfCountArgsOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -3214,7 +3214,7 @@ func (a *application) rewriteRefOfDelete(parent SQLNode, node *Delete, replacer for x, el := range node.TableExprs { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(RefOfDeleteTableExprsOffset), x) + a.cur.current.AddStepWithOffset(uint16(RefOfDeleteTableExprsOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -3580,7 +3580,7 @@ func (a *application) rewriteRefOfExecuteStmt(parent SQLNode, node *ExecuteStmt, for x, el := range node.Arguments { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(RefOfExecuteStmtArgumentsOffset), x) + a.cur.current.AddStepWithOffset(uint16(RefOfExecuteStmtArgumentsOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -3752,7 +3752,7 @@ func (a *application) rewriteRefOfExprs(parent SQLNode, node *Exprs, replacer re for x, el := range node.Exprs { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(RefOfExprsExprsOffset), x) + a.cur.current.AddStepWithOffset(uint16(RefOfExprsExprsOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -4196,7 +4196,7 @@ func (a *application) rewriteRefOfFuncExpr(parent SQLNode, node *FuncExpr, repla for x, el := range node.Exprs { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(RefOfFuncExprExprsOffset), x) + a.cur.current.AddStepWithOffset(uint16(RefOfFuncExprExprsOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -4816,7 +4816,7 @@ func (a *application) rewriteRefOfGroupBy(parent SQLNode, node *GroupBy, replace for x, el := range node.Exprs { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(RefOfGroupByExprsOffset), x) + a.cur.current.AddStepWithOffset(uint16(RefOfGroupByExprsOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -4865,7 +4865,7 @@ func (a *application) rewriteRefOfGroupConcatExpr(parent SQLNode, node *GroupCon for x, el := range node.Exprs { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(RefOfGroupConcatExprExprsOffset), x) + a.cur.current.AddStepWithOffset(uint16(RefOfGroupConcatExprExprsOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -5022,7 +5022,7 @@ func (a *application) rewriteRefOfIndexHint(parent SQLNode, node *IndexHint, rep for x, el := range node.Indexes { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(RefOfIndexHintIndexesOffset), x) + a.cur.current.AddStepWithOffset(uint16(RefOfIndexHintIndexesOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -5068,7 +5068,7 @@ func (a *application) rewriteIndexHints(parent SQLNode, node IndexHints, replace for x, el := range node { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(IndexHintsOffset), x) + a.cur.current.AddStepWithOffset(uint16(IndexHintsOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -5376,7 +5376,7 @@ func (a *application) rewriteRefOfIntervalFuncExpr(parent SQLNode, node *Interva for x, el := range node.Exprs { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(RefOfIntervalFuncExprExprsOffset), x) + a.cur.current.AddStepWithOffset(uint16(RefOfIntervalFuncExprExprsOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -5548,7 +5548,7 @@ func (a *application) rewriteRefOfJSONArrayExpr(parent SQLNode, node *JSONArrayE for x, el := range node.Params { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(RefOfJSONArrayExprParamsOffset), x) + a.cur.current.AddStepWithOffset(uint16(RefOfJSONArrayExprParamsOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -5661,7 +5661,7 @@ func (a *application) rewriteRefOfJSONContainsExpr(parent SQLNode, node *JSONCon for x, el := range node.PathList { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(RefOfJSONContainsExprPathListOffset), x) + a.cur.current.AddStepWithOffset(uint16(RefOfJSONContainsExprPathListOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -5727,7 +5727,7 @@ func (a *application) rewriteRefOfJSONContainsPathExpr(parent SQLNode, node *JSO for x, el := range node.PathList { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(RefOfJSONContainsPathExprPathListOffset), x) + a.cur.current.AddStepWithOffset(uint16(RefOfJSONContainsPathExprPathListOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -5784,7 +5784,7 @@ func (a *application) rewriteRefOfJSONExtractExpr(parent SQLNode, node *JSONExtr for x, el := range node.PathList { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(RefOfJSONExtractExprPathListOffset), x) + a.cur.current.AddStepWithOffset(uint16(RefOfJSONExtractExprPathListOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -5936,7 +5936,7 @@ func (a *application) rewriteRefOfJSONObjectExpr(parent SQLNode, node *JSONObjec for x, el := range node.Params { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(RefOfJSONObjectExprParamsOffset), x) + a.cur.current.AddStepWithOffset(uint16(RefOfJSONObjectExprParamsOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -6163,7 +6163,7 @@ func (a *application) rewriteRefOfJSONRemoveExpr(parent SQLNode, node *JSONRemov for x, el := range node.PathList { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(RefOfJSONRemoveExprPathListOffset), x) + a.cur.current.AddStepWithOffset(uint16(RefOfJSONRemoveExprPathListOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -6341,7 +6341,7 @@ func (a *application) rewriteRefOfJSONSearchExpr(parent SQLNode, node *JSONSearc for x, el := range node.PathList { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(RefOfJSONSearchExprPathListOffset), x) + a.cur.current.AddStepWithOffset(uint16(RefOfJSONSearchExprPathListOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -6492,7 +6492,7 @@ func (a *application) rewriteRefOfJSONTableExpr(parent SQLNode, node *JSONTableE for x, el := range node.Columns { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(RefOfJSONTableExprColumnsOffset), x) + a.cur.current.AddStepWithOffset(uint16(RefOfJSONTableExprColumnsOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -6661,7 +6661,7 @@ func (a *application) rewriteRefOfJSONValueMergeExpr(parent SQLNode, node *JSONV for x, el := range node.JSONDocList { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(RefOfJSONValueMergeExprJSONDocListOffset), x) + a.cur.current.AddStepWithOffset(uint16(RefOfJSONValueMergeExprJSONDocListOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -6718,7 +6718,7 @@ func (a *application) rewriteRefOfJSONValueModifierExpr(parent SQLNode, node *JS for x, el := range node.Params { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(RefOfJSONValueModifierExprParamsOffset), x) + a.cur.current.AddStepWithOffset(uint16(RefOfJSONValueModifierExprParamsOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -7116,7 +7116,7 @@ func (a *application) rewriteRefOfLineStringExpr(parent SQLNode, node *LineStrin for x, el := range node.PointParams { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(RefOfLineStringExprPointParamsOffset), x) + a.cur.current.AddStepWithOffset(uint16(RefOfLineStringExprPointParamsOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -7431,7 +7431,7 @@ func (a *application) rewriteRefOfMatchExpr(parent SQLNode, node *MatchExpr, rep for x, el := range node.Columns { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(RefOfMatchExprColumnsOffset), x) + a.cur.current.AddStepWithOffset(uint16(RefOfMatchExprColumnsOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -7677,7 +7677,7 @@ func (a *application) rewriteRefOfMultiLinestringExpr(parent SQLNode, node *Mult for x, el := range node.LinestringParams { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(RefOfMultiLinestringExprLinestringParamsOffset), x) + a.cur.current.AddStepWithOffset(uint16(RefOfMultiLinestringExprLinestringParamsOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -7726,7 +7726,7 @@ func (a *application) rewriteRefOfMultiPointExpr(parent SQLNode, node *MultiPoin for x, el := range node.PointParams { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(RefOfMultiPointExprPointParamsOffset), x) + a.cur.current.AddStepWithOffset(uint16(RefOfMultiPointExprPointParamsOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -7775,7 +7775,7 @@ func (a *application) rewriteRefOfMultiPolygonExpr(parent SQLNode, node *MultiPo for x, el := range node.PolygonParams { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(RefOfMultiPolygonExprPolygonParamsOffset), x) + a.cur.current.AddStepWithOffset(uint16(RefOfMultiPolygonExprPolygonParamsOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -7933,7 +7933,7 @@ func (a *application) rewriteNamedWindows(parent SQLNode, node NamedWindows, rep for x, el := range node { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(NamedWindowsOffset), x) + a.cur.current.AddStepWithOffset(uint16(NamedWindowsOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -8198,7 +8198,7 @@ func (a *application) rewriteOnDup(parent SQLNode, node OnDup, replacer replacer for x, el := range node { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(OnDupOffset), x) + a.cur.current.AddStepWithOffset(uint16(OnDupOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -8367,7 +8367,7 @@ func (a *application) rewriteOrderBy(parent SQLNode, node OrderBy, replacer repl for x, el := range node { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(OrderByOffset), x) + a.cur.current.AddStepWithOffset(uint16(OrderByOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -8782,7 +8782,7 @@ func (a *application) rewriteRefOfPartitionOption(parent SQLNode, node *Partitio for x, el := range node.Definitions { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(RefOfPartitionOptionDefinitionsOffset), x) + a.cur.current.AddStepWithOffset(uint16(RefOfPartitionOptionDefinitionsOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -8857,7 +8857,7 @@ func (a *application) rewriteRefOfPartitionSpec(parent SQLNode, node *PartitionS for x, el := range node.Definitions { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(RefOfPartitionSpecDefinitionsOffset), x) + a.cur.current.AddStepWithOffset(uint16(RefOfPartitionSpecDefinitionsOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -8941,7 +8941,7 @@ func (a *application) rewritePartitions(parent SQLNode, node Partitions, replace for x, el := range node { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(PartitionsOffset), x) + a.cur.current.AddStepWithOffset(uint16(PartitionsOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -9122,7 +9122,7 @@ func (a *application) rewriteRefOfPolygonExpr(parent SQLNode, node *PolygonExpr, for x, el := range node.LinestringParams { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(RefOfPolygonExprLinestringParamsOffset), x) + a.cur.current.AddStepWithOffset(uint16(RefOfPolygonExprLinestringParamsOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -10105,7 +10105,7 @@ func (a *application) rewriteRefOfSelect(parent SQLNode, node *Select, replacer for x, el := range node.From { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(RefOfSelectFromOffset), x) + a.cur.current.AddStepWithOffset(uint16(RefOfSelectFromOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -10235,7 +10235,7 @@ func (a *application) rewriteRefOfSelectExprs(parent SQLNode, node *SelectExprs, for x, el := range node.Exprs { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(RefOfSelectExprsExprsOffset), x) + a.cur.current.AddStepWithOffset(uint16(RefOfSelectExprsExprsOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -10404,7 +10404,7 @@ func (a *application) rewriteSetExprs(parent SQLNode, node SetExprs, replacer re for x, el := range node { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(SetExprsOffset), x) + a.cur.current.AddStepWithOffset(uint16(SetExprsOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -11215,7 +11215,7 @@ func (a *application) rewriteSubPartitionDefinitions(parent SQLNode, node SubPar for x, el := range node { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(SubPartitionDefinitionsOffset), x) + a.cur.current.AddStepWithOffset(uint16(SubPartitionDefinitionsOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -11402,7 +11402,7 @@ func (a *application) rewriteTableExprs(parent SQLNode, node TableExprs, replace for x, el := range node { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(TableExprsOffset), x) + a.cur.current.AddStepWithOffset(uint16(TableExprsOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -11492,7 +11492,7 @@ func (a *application) rewriteTableNames(parent SQLNode, node TableNames, replace for x, el := range node { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(TableNamesOffset), x) + a.cur.current.AddStepWithOffset(uint16(TableNamesOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -11570,7 +11570,7 @@ func (a *application) rewriteRefOfTableSpec(parent SQLNode, node *TableSpec, rep for x, el := range node.Columns { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(RefOfTableSpecColumnsOffset), x) + a.cur.current.AddStepWithOffset(uint16(RefOfTableSpecColumnsOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -11589,7 +11589,7 @@ func (a *application) rewriteRefOfTableSpec(parent SQLNode, node *TableSpec, rep for x, el := range node.Indexes { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(RefOfTableSpecIndexesOffset), x) + a.cur.current.AddStepWithOffset(uint16(RefOfTableSpecIndexesOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -11608,7 +11608,7 @@ func (a *application) rewriteRefOfTableSpec(parent SQLNode, node *TableSpec, rep for x, el := range node.Constraints { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(RefOfTableSpecConstraintsOffset), x) + a.cur.current.AddStepWithOffset(uint16(RefOfTableSpecConstraintsOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -12003,7 +12003,7 @@ func (a *application) rewriteRefOfUpdate(parent SQLNode, node *Update, replacer for x, el := range node.TableExprs { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(RefOfUpdateTableExprsOffset), x) + a.cur.current.AddStepWithOffset(uint16(RefOfUpdateTableExprsOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -12132,7 +12132,7 @@ func (a *application) rewriteUpdateExprs(parent SQLNode, node UpdateExprs, repla for x, el := range node { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(UpdateExprsOffset), x) + a.cur.current.AddStepWithOffset(uint16(UpdateExprsOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -12393,7 +12393,7 @@ func (a *application) rewriteValTuple(parent SQLNode, node ValTuple, replacer re for x, el := range node { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(ValTupleOffset), x) + a.cur.current.AddStepWithOffset(uint16(ValTupleOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -12468,7 +12468,7 @@ func (a *application) rewriteValues(parent SQLNode, node Values, replacer replac for x, el := range node { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(ValuesOffset), x) + a.cur.current.AddStepWithOffset(uint16(ValuesOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -12869,7 +12869,7 @@ func (a *application) rewriteRefOfVindexSpec(parent SQLNode, node *VindexSpec, r for x, el := range node.Params { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(RefOfVindexSpecParamsOffset), x) + a.cur.current.AddStepWithOffset(uint16(RefOfVindexSpecParamsOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -13094,7 +13094,7 @@ func (a *application) rewriteWindowDefinitions(parent SQLNode, node WindowDefini for x, el := range node { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(WindowDefinitionsOffset), x) + a.cur.current.AddStepWithOffset(uint16(WindowDefinitionsOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -13151,7 +13151,7 @@ func (a *application) rewriteRefOfWindowSpecification(parent SQLNode, node *Wind for x, el := range node.PartitionClause { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(RefOfWindowSpecificationPartitionClauseOffset), x) + a.cur.current.AddStepWithOffset(uint16(RefOfWindowSpecificationPartitionClauseOffset)) } else { a.cur.current.ChangeOffset(x) } @@ -13218,7 +13218,7 @@ func (a *application) rewriteRefOfWith(parent SQLNode, node *With, replacer repl for x, el := range node.CTEs { if a.collectPaths { if x == 0 { - a.cur.current.AddStepWithOffset(uint16(RefOfWithCTEsOffset), x) + a.cur.current.AddStepWithOffset(uint16(RefOfWithCTEsOffset)) } else { a.cur.current.ChangeOffset(x) } diff --git a/go/vt/sqlparser/pathbuilder/ast_paths_builder.go b/go/vt/sqlparser/pathbuilder/builder.go similarity index 88% rename from go/vt/sqlparser/pathbuilder/ast_paths_builder.go rename to go/vt/sqlparser/pathbuilder/builder.go index e548221822a..20fa14dd906 100644 --- a/go/vt/sqlparser/pathbuilder/ast_paths_builder.go +++ b/go/vt/sqlparser/pathbuilder/builder.go @@ -30,13 +30,14 @@ type ASTPathBuilder struct { const initialCap = 16 -// NewASTPathBuilder creates a new ASTPathBuilder with an optional initial capacity. +// NewASTPathBuilder creates a new ASTPathBuilder func NewASTPathBuilder() *ASTPathBuilder { return &ASTPathBuilder{ path: make([]byte, initialCap), } } +// TODO: Remove this. We should only use it for testing while building confidence. func (apb *ASTPathBuilder) sanityCheck() { var total int for _, size := range apb.sizes { @@ -50,15 +51,15 @@ func (apb *ASTPathBuilder) sanityCheck() { // growIfNeeded expands the slice capacity if we don't have enough room for n more bytes. func (apb *ASTPathBuilder) growIfNeeded(n int) { needed := apb.pathLen + n - i := cap(apb.path) - if needed <= i { + currentCap := cap(apb.path) + if needed <= currentCap { return } - newCap := cap(apb.path) * 2 + newCap := currentCap * 2 for newCap < needed { newCap *= 2 } - newPath := make([]byte, apb.pathLen, newCap) + newPath := make([]byte, newCap) copy(newPath, apb.path[:apb.pathLen]) apb.path = newPath } @@ -77,8 +78,8 @@ func (apb *ASTPathBuilder) AddStep(step uint16) { apb.sanityCheck() } -// AddStepWithOffset appends a single step (2 bytes) + varint offset. -func (apb *ASTPathBuilder) AddStepWithOffset(step uint16, offset int) { +// AddStepWithOffset appends a single step (2 bytes) + varint offset with value 0 to path. +func (apb *ASTPathBuilder) AddStepWithOffset(step uint16) { // Step apb.growIfNeeded(2) binary.BigEndian.PutUint16(apb.path[apb.pathLen:apb.pathLen+2], step) @@ -86,7 +87,7 @@ func (apb *ASTPathBuilder) AddStepWithOffset(step uint16, offset int) { // Offset var buf [8]byte - bytesWritten := binary.PutVarint(buf[:], int64(offset)) + bytesWritten := binary.PutVarint(buf[:], 0) // 0 offset apb.growIfNeeded(bytesWritten) copy(apb.path[apb.pathLen:apb.pathLen+bytesWritten], buf[:bytesWritten]) apb.pathLen += bytesWritten diff --git a/go/vt/sqlparser/pathbuilder/ast_paths_builder_test.go b/go/vt/sqlparser/pathbuilder/builder_test.go similarity index 66% rename from go/vt/sqlparser/pathbuilder/ast_paths_builder_test.go rename to go/vt/sqlparser/pathbuilder/builder_test.go index efea7a67fe3..764fda49470 100644 --- a/go/vt/sqlparser/pathbuilder/ast_paths_builder_test.go +++ b/go/vt/sqlparser/pathbuilder/builder_test.go @@ -65,60 +65,24 @@ func TestASTPathBuilderAddStepOffset(t *testing.T) { }, { name: "multiple steps", - steps: []uint16{1, 0x24, 0x913}, - offsets: []int{0, -1, 2}, - wantPath: "\x00\x01\x00\x00\x24\x09\x13\x04", - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - apb := NewASTPathBuilder() - for idx, step := range tt.steps { - if tt.offsets[idx] == -1 { - apb.AddStep(step) - } else { - apb.AddStepWithOffset(step, tt.offsets[idx]) - } - } - require.Equal(t, tt.wantPath, apb.ToPath()) - }) - } -} - -func TestASTPathBuilderChangeOffset(t *testing.T) { - tests := []struct { - name string - steps []uint16 - offsets []int - changeOffsetValue int - wantPath string - }{ - { - name: "single step", - steps: []uint16{1}, - offsets: []int{0}, - changeOffsetValue: 5, - wantPath: "\x00\x01\x0a", - }, - { - name: "multiple steps", - steps: []uint16{1, 0x24, 0x913}, - offsets: []int{0, -1, 2}, - changeOffsetValue: 5, - wantPath: "\x00\x01\x00\x00\x24\x09\x13\x0a", + steps: []uint16{1, 0x24, 0x913, 0x913}, + offsets: []int{0, -1, 0, 1}, // the 0 is overwritten by the last offset + wantPath: "\x00\x01\x00\x00\x24\x09\x13\x02", }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { apb := NewASTPathBuilder() for idx, step := range tt.steps { - if tt.offsets[idx] == -1 { + switch { + case tt.offsets[idx] == -1: apb.AddStep(step) - } else { - apb.AddStepWithOffset(step, tt.offsets[idx]) + case tt.offsets[idx] == 0: + apb.AddStepWithOffset(step) + default: + apb.ChangeOffset(tt.offsets[idx]) } } - apb.ChangeOffset(tt.changeOffsetValue) require.Equal(t, tt.wantPath, apb.ToPath()) }) } @@ -140,7 +104,7 @@ func TestASTPathBuilderPop(t *testing.T) { { name: "multiple steps - final step with offset", steps: []uint16{1, 0x24, 0x913}, - offsets: []int{0, -1, 2}, + offsets: []int{0, -1, 0, 1}, wantPath: "\x00\x01\x00\x00\x24", }, { @@ -154,10 +118,13 @@ func TestASTPathBuilderPop(t *testing.T) { t.Run(tt.name, func(t *testing.T) { apb := NewASTPathBuilder() for idx, step := range tt.steps { - if tt.offsets[idx] == -1 { + switch { + case tt.offsets[idx] == -1: apb.AddStep(step) - } else { - apb.AddStepWithOffset(step, tt.offsets[idx]) + case tt.offsets[idx] == 0: + apb.AddStepWithOffset(step) + default: + apb.ChangeOffset(tt.offsets[idx]) } } apb.Pop() diff --git a/go/vt/sqlparser/paths.go b/go/vt/sqlparser/paths.go index 6fa27ad02ea..3a4d281ecf5 100644 --- a/go/vt/sqlparser/paths.go +++ b/go/vt/sqlparser/paths.go @@ -34,21 +34,12 @@ func AddStep(path ASTPath, step ASTStep) ASTPath { 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) - } +func AddStepWithOffset(path ASTPath, step ASTStep, offset int) ASTPath { + var buf [10]byte + binary.BigEndian.PutUint16(buf[0:], uint16(step)) + n := binary.PutVarint(buf[2:], int64(offset)) - // 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) + return path + ASTPath(buf[:2+n]) } func (path ASTPath) DebugString() string { diff --git a/go/vt/sqlparser/paths_test.go b/go/vt/sqlparser/paths_test.go index 4b44eba42a8..b3163d914dd 100644 --- a/go/vt/sqlparser/paths_test.go +++ b/go/vt/sqlparser/paths_test.go @@ -29,7 +29,7 @@ func TestASTPathDebugString(t *testing.T) { p = AddStep(p, RefOfSelectWhere) p = AddStep(p, RefOfWhereExpr) p = AddStep(p, RefOfBinaryExprLeft) - p = AddStepWithSliceIndex(p, RefOfFuncExprExprsOffset, 2) + p = AddStepWithOffset(p, RefOfFuncExprExprsOffset, 2) expected := "(*Select).Where->(*Where).Expr->(*BinaryExpr).Left->(*FuncExpr).ExprsOffset(2)" assert.Equal(t, expected, p.DebugString()) } diff --git a/go/vt/sqlparser/rewriter_test.go b/go/vt/sqlparser/rewriter_test.go index 09d01f37a11..b1fad2642d8 100644 --- a/go/vt/sqlparser/rewriter_test.go +++ b/go/vt/sqlparser/rewriter_test.go @@ -17,7 +17,6 @@ limitations under the License. package sqlparser import ( - "fmt" "testing" "github.com/stretchr/testify/assert" @@ -68,27 +67,56 @@ func TestReplaceWorksInLaterCalls(t *testing.T) { func TestFindColNamesWithPaths(t *testing.T) { // this is the tpch query #1 - q := "select l_returnflag, l_linestatus from tbl where l_shipdate <= 12" + 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) - check := func(in string) { - if in == "UP (*Select).With->(*Select).FromOffset(0)->(*AliasedTableExpr).Expr->(TableName).Name->(*AliasedTableExpr).Partitions->(*AliasedTableExpr).As->(*AliasedTableExpr).Hints->(*Select).Comments->(*Select).SelectExprs->(*SelectExprs).ExprsOffset(0)->(*AliasedExpr).Expr->(*ColName).Name->(*ColName).Qualifier" { - _ = in - } - assert.NotContains(t, in, "ERR-unaligned-extra-bytes") - fmt.Println(in) - } - + var foundColNames []string RewriteWithPath(ast, func(cursor *Cursor) bool { - check("DOWN " + cursor.CurrentPath().DebugString()) - return true - }, - func(cursor *Cursor) bool { - check("UP " + cursor.CurrentPath().DebugString()) + _, ok := cursor.Node().(*ColName) + if ok { + foundColNames = append(foundColNames, cursor.CurrentPath().DebugString()) + } + return true - }) + }, nil) + + expected := []string{ + "(*SelectExprs).ExprsOffset(0)->(*AliasedExpr).Expr", // l_returnflag + "(*SelectExprs).ExprsOffset(1)->(*AliasedExpr).Expr", // l_linestatus + "(*SelectExprs).ExprsOffset(2)->(*AliasedExpr).Expr->(*Sum).Arg", // sum(l_quantity) + "(*SelectExprs).ExprsOffset(3)->(*AliasedExpr).Expr->(*Sum).Arg", // sum(l_extendedprice) + "(*SelectExprs).ExprsOffset(4)->(*AliasedExpr).Expr->(*Sum).Arg->(*BinaryExpr).Left", // sum(->l_extendedprice<- * (1 - l_discount)) + "(*SelectExprs).ExprsOffset(4)->(*AliasedExpr).Expr->(*Sum).Arg->(*BinaryExpr).Right->(*BinaryExpr).Right", // sum(l_extendedprice * (1 - ->l_discount<-)) + "(*SelectExprs).ExprsOffset(5)->(*AliasedExpr).Expr->(*Sum).Arg->(*BinaryExpr).Left->(*BinaryExpr).Left", // etc + "(*SelectExprs).ExprsOffset(5)->(*AliasedExpr).Expr->(*Sum).Arg->(*BinaryExpr).Left->(*BinaryExpr).Right->(*BinaryExpr).Right", + "(*SelectExprs).ExprsOffset(5)->(*AliasedExpr).Expr->(*Sum).Arg->(*BinaryExpr).Right->(*BinaryExpr).Right", + "(*SelectExprs).ExprsOffset(6)->(*AliasedExpr).Expr->(*Avg).Arg", + "(*SelectExprs).ExprsOffset(7)->(*AliasedExpr).Expr->(*Avg).Arg", + "(*SelectExprs).ExprsOffset(8)->(*AliasedExpr).Expr->(*Avg).Arg", + "(*Select).Where->(*Where).Expr->(*ComparisonExpr).Left", + "(*GroupBy).ExprsOffset(0)", + "(*GroupBy).ExprsOffset(1)", + "(*Select).OrderBy->(OrderBy)[]Offset(0)->(*Order).Expr", + "(*Select).OrderBy->(OrderBy)[]Offset(1)->(*Order).Expr", + } + + assert.Equal(t, expected, foundColNames) } func TestReplaceAndRevisitWorksInLaterCalls(t *testing.T) {