Skip to content

Commit

Permalink
review touch ups
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Taylor <[email protected]>
  • Loading branch information
systay committed Jun 20, 2024
1 parent 3039c4e commit 826abd6
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions go/vt/vtgate/planbuilder/operators/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,17 @@ func (a *Aggregator) FindCol(ctx *plancontext.PlanningContext, in sqlparser.Expr
}

func (a *Aggregator) checkOffset(offset int) {
// if the offset is greater than the number of columns we expect to produce, we need to update the number of columns
// this is to make sure that the column is not truncated in the final result
if a.ResultColumns > 0 && a.ResultColumns <= offset {
a.ResultColumns = offset + 1
}
}

func (a *Aggregator) AddColumn(ctx *plancontext.PlanningContext, reuse bool, groupBy bool, ae *sqlparser.AliasedExpr) int {
func (a *Aggregator) AddColumn(ctx *plancontext.PlanningContext, reuse bool, groupBy bool, ae *sqlparser.AliasedExpr) (offset int) {
defer func() {
a.checkOffset(offset)
}()
rewritten := a.DT.RewriteExpression(ctx, ae.Expr)

ae = &sqlparser.AliasedExpr{
Expand All @@ -167,7 +172,6 @@ func (a *Aggregator) AddColumn(ctx *plancontext.PlanningContext, reuse bool, gro
if reuse {
offset := a.findColInternal(ctx, ae, groupBy)
if offset >= 0 {
a.checkOffset(offset)
return offset
}
}
Expand All @@ -191,15 +195,14 @@ func (a *Aggregator) AddColumn(ctx *plancontext.PlanningContext, reuse bool, gro
a.Aggregations = append(a.Aggregations, aggr)
}

offset := len(a.Columns)
offset = len(a.Columns)
a.Columns = append(a.Columns, ae)
incomingOffset := a.Source.AddColumn(ctx, false, groupBy, ae)

if offset != incomingOffset {
panic(errFailedToPlan(ae))
}

a.checkOffset(offset)
return offset
}

Expand Down

0 comments on commit 826abd6

Please sign in to comment.