Skip to content

Commit

Permalink
Rename SQL_builder -> op_to_ast
Browse files Browse the repository at this point in the history
Signed-off-by: Florent Poinsard <[email protected]>
  • Loading branch information
frouioui committed Jan 29, 2025
1 parent 2e7ae91 commit 7a695b0
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
4 changes: 2 additions & 2 deletions go/vt/vtgate/planbuilder/operator_transformers.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func transformInsertionSelection(ctx *plancontext.PlanningContext, op *operators
return nil, vterrors.VT13001(fmt.Sprintf("Incorrect type encountered: %T (transformInsertionSelection)", op.Insert))
}

stmt, dmlOp, err := operators.ToSQL(ctx, rb.Source)
stmt, dmlOp, err := operators.ToAST(ctx, rb.Source)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -579,7 +579,7 @@ func getHints(cmt *sqlparser.ParsedComments) *queryHints {
}

func transformRoutePlan(ctx *plancontext.PlanningContext, op *operators.Route) (engine.Primitive, error) {
stmt, dmlOp, err := operators.ToSQL(ctx, op.Source)
stmt, dmlOp, err := operators.ToAST(ctx, op.Source)
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ import (
"vitess.io/vitess/go/vt/vtgate/planbuilder/plancontext"
)

func ToSQL(ctx *plancontext.PlanningContext, op Operator) (_ sqlparser.Statement, _ Operator, err error) {
func ToAST(ctx *plancontext.PlanningContext, op Operator) (_ sqlparser.Statement, _ Operator, err error) {
defer PanicHandler(&err)

q := &queryBuilder{ctx: ctx}
buildQuery(op, q)
buildAST(op, q)
if ctx.SemTable != nil {
q.sortTables()
}
Expand Down Expand Up @@ -75,8 +75,8 @@ func stripDownQuery(from, to sqlparser.TableStatement) {
}
}

// buildQuery recursively builds the query into an AST, from an operator tree
func buildQuery(op Operator, qb *queryBuilder) {
// buildAST recursively builds the query into an AST, from an operator tree
func buildAST(op Operator, qb *queryBuilder) {
switch op := op.(type) {
case *Table:
buildTable(op, qb)
Expand Down Expand Up @@ -120,7 +120,7 @@ func buildQuery(op Operator, qb *queryBuilder) {
}

func buildDistinct(op *Distinct, qb *queryBuilder) {
buildQuery(op.Source, qb)
buildAST(op.Source, qb)
statement := qb.asSelectStatement()
d, ok := statement.(sqlparser.Distinctable)
if !ok {
Expand All @@ -131,14 +131,14 @@ func buildDistinct(op *Distinct, qb *queryBuilder) {

func buildValuesJoin(op *ValuesJoin, qb *queryBuilder) {
qb.ctx.SkipValuesArgument(op.bindVarName)
buildQuery(op.LHS, qb)
buildAST(op.LHS, qb)
qbR := &queryBuilder{ctx: qb.ctx}
buildQuery(op.RHS, qbR)
buildAST(op.RHS, qbR)
qb.joinWith(qbR, nil, sqlparser.NormalJoinType)
}

func buildValues(op *Values, qb *queryBuilder) {
buildQuery(op.Source, qb)
buildAST(op.Source, qb)
if qb.ctx.IsValuesArgumentSkipped(op.Arg) {
return
}
Expand All @@ -155,7 +155,7 @@ func buildDelete(op *Delete, qb *queryBuilder) {
Ignore: op.Ignore,
Targets: sqlparser.TableNames{op.Target.Name},
}
buildQuery(op.Source, qb)
buildAST(op.Source, qb)

qb.dmlOperator = op
}
Expand All @@ -168,7 +168,7 @@ func buildUpdate(op *Update, qb *queryBuilder) {
}
qb.stmt = upd
qb.dmlOperator = op
buildQuery(op.Source, qb)
buildAST(op.Source, qb)
}

func getUpdateExprs(op *Update) sqlparser.UpdateExprs {
Expand All @@ -193,7 +193,7 @@ func buildDML(op OpWithAST, qb *queryBuilder) {
}

func buildAggregation(op *Aggregator, qb *queryBuilder) {
buildQuery(op.Source, qb)
buildAST(op.Source, qb)

qb.clearProjections()

Expand Down Expand Up @@ -223,15 +223,15 @@ func buildAggregation(op *Aggregator, qb *queryBuilder) {
}

func buildOrdering(op *Ordering, qb *queryBuilder) {
buildQuery(op.Source, qb)
buildAST(op.Source, qb)

for _, order := range op.Order {
qb.asOrderAndLimit().AddOrder(order.Inner)
}
}

func buildLimit(op *Limit, qb *queryBuilder) {
buildQuery(op.Source, qb)
buildAST(op.Source, qb)
qb.asOrderAndLimit().SetLimit(op.AST)
}

Expand All @@ -255,7 +255,7 @@ func buildTable(op *Table, qb *queryBuilder) {
}

func buildProjection(op *Projection, qb *queryBuilder) {
buildQuery(op.Source, qb)
buildAST(op.Source, qb)

_, isSel := qb.stmt.(*sqlparser.Select)
if isSel {
Expand Down Expand Up @@ -295,10 +295,10 @@ func buildApplyJoin(op *ApplyJoin, qb *queryBuilder) {
})
pred := sqlparser.AndExpressions(predicates...)

buildQuery(op.LHS, qb)
buildAST(op.LHS, qb)

qbR := &queryBuilder{ctx: qb.ctx}
buildQuery(op.RHS, qbR)
buildAST(op.RHS, qbR)

switch {
// if we have a recursive cte, we might be missing a statement from one of the sides
Expand All @@ -313,7 +313,7 @@ func buildApplyJoin(op *ApplyJoin, qb *queryBuilder) {

func buildUnion(op *Union, qb *queryBuilder) {
// the first input is built first
buildQuery(op.Sources[0], qb)
buildAST(op.Sources[0], qb)

for i, src := range op.Sources {
if i == 0 {
Expand All @@ -322,21 +322,21 @@ func buildUnion(op *Union, qb *queryBuilder) {

// now we can go over the remaining inputs and UNION them together
qbOther := &queryBuilder{ctx: qb.ctx}
buildQuery(src, qbOther)
buildAST(src, qbOther)
qb.unionWith(qbOther, op.distinct)
}
}

func buildFilter(op *Filter, qb *queryBuilder) {
buildQuery(op.Source, qb)
buildAST(op.Source, qb)

for _, pred := range op.Predicates {
qb.addPredicate(pred)
}
}

func buildDerived(op *Horizon, qb *queryBuilder) {
buildQuery(op.Source, qb)
buildAST(op.Source, qb)

sqlparser.RemoveKeyspaceInCol(op.Query)

Expand Down Expand Up @@ -388,7 +388,7 @@ func buildDerivedSelect(op *Horizon, qb *queryBuilder, sel *sqlparser.Select) {
}

func buildHorizon(op *Horizon, qb *queryBuilder) {
buildQuery(op.Source, qb)
buildAST(op.Source, qb)
stripDownQuery(op.Query, qb.asSelectStatement())
sqlparser.RemoveKeyspaceInCol(qb.stmt)
}
Expand All @@ -403,9 +403,9 @@ func buildRecursiveCTE(op *RecurseCTE, qb *queryBuilder) {
return jc.Original
})
pred := sqlparser.AndExpressions(predicates...)
buildQuery(op.Seed(), qb)
buildAST(op.Seed(), qb)
qbR := &queryBuilder{ctx: qb.ctx}
buildQuery(op.Term(), qbR)
buildAST(op.Term(), qbR)
qbR.addPredicate(pred)
infoFor, err := qb.ctx.SemTable.TableInfoFor(op.OuterID)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestToSQLValues(t *testing.T) {
Arg: "toto",
}

stmt, _, err := ToSQL(ctx, op)
stmt, _, err := ToAST(ctx, op)
require.NoError(t, err)
require.Equal(t, "select id from x, (values ::toto) as t(user_id)", sqlparser.String(stmt))

Expand All @@ -57,7 +57,7 @@ func TestToSQLValues(t *testing.T) {
userIdColName,
)

stmt, _, err = ToSQL(ctx, proj)
stmt, _, err = ToAST(ctx, proj)
require.NoError(t, err)
require.Equal(t, "select id, t.user_id from x, (values ::toto) as t(user_id)", sqlparser.String(stmt))
}
Expand Down Expand Up @@ -112,7 +112,7 @@ func TestToSQLValuesJoin(t *testing.T) {
bindVarName: argumentName,
}

stmt, _, err := ToSQL(ctx, vj)
stmt, _, err := ToAST(ctx, vj)
require.NoError(t, err)
require.Equal(t, "select id, tata from x, y where x.id = 42 and y.tata = 42 and y.tata = x.id", sqlparser.String(stmt))
}
2 changes: 1 addition & 1 deletion go/vt/vtgate/planbuilder/operators/subquery_planning.go
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ func (s *subqueryRouteMerger) merge(ctx *plancontext.PlanningContext, inner, out
// We really need to figure out why this is not working as expected
func (s *subqueryRouteMerger) rewriteASTExpression(ctx *plancontext.PlanningContext, inner *Route) Operator {
src := s.outer.Source
stmt, _, err := ToSQL(ctx, inner.Source)
stmt, _, err := ToAST(ctx, inner.Source)
if err != nil {
panic(err)
}
Expand Down

0 comments on commit 7a695b0

Please sign in to comment.