Skip to content

Commit 8863988

Browse files
author
James Cor
committed
use interface
1 parent 64b611d commit 8863988

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

sql/aggregates.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ type WindowFrame interface {
115115
StartNFollowing() Expression
116116
// EndNPreceding returns whether a frame end preceding Expression or nil
117117
EndNPreceding() Expression
118-
// EndNPreceding returns whether a frame end following Expression or nil
118+
// EndNFollowing returns whether a frame end following Expression or nil
119119
EndNFollowing() Expression
120120
}
121121

@@ -135,3 +135,9 @@ type AggregationBuffer interface {
135135
type WindowAggregation interface {
136136
WindowAdaptableExpression
137137
}
138+
139+
// OrderedAggregation are aggregate functions that modify the current working row with additional result columns.
140+
type OrderedAggregation interface {
141+
// OutputExpressions gets a list of return expressions.
142+
OutputExpressions() []Expression
143+
}

sql/analyzer/fix_exec_indexes.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ import (
1818
"fmt"
1919
"strings"
2020

21-
"github.com/dolthub/go-mysql-server/sql/expression/function/aggregation"
22-
2321
"github.com/dolthub/go-mysql-server/sql"
2422
"github.com/dolthub/go-mysql-server/sql/expression"
2523
"github.com/dolthub/go-mysql-server/sql/plan"
@@ -583,19 +581,18 @@ func (s *idxScope) visitSelf(n sql.Node) error {
583581
// default nodes can't see lateral join nodes, unless we're in lateral
584582
// join and lateral scopes are promoted to parent status
585583
for _, e := range ne.Expressions() {
586-
// groupConcat is special as it appends results to outer scope row
587-
// we need to account for this extra column in the rows when assigning indexes
588-
// see gms/expression/function/aggregation/group_concat.go:groupConcatBuffer.Update()
589-
if gc, isGc := e.(*aggregation.GroupConcat); isGc {
590-
selExprs := gc.GetSelectExprs()
584+
// OrderedAggregations are special as they append results to the outer scope row
585+
// We need to account for this extra column in the rows when assigning indexes
586+
// Example: gms/expression/function/aggregation/group_concat.go:groupConcatBuffer.Update()
587+
if ordAgg, isOrdAgg := e.(sql.OrderedAggregation); isOrdAgg {
588+
selExprs := ordAgg.OutputExpressions()
591589
selScope := &idxScope{}
592590
for _, expr := range selExprs {
593591
selScope.columns = append(selScope.columns, expr.String())
594592
if gf, isGf := expr.(*expression.GetField); isGf {
595593
selScope.ids = append(selScope.ids, gf.Id())
596594
}
597595
}
598-
scope = append(scope, selScope)
599596
}
600597
s.expressions = append(s.expressions, fixExprToScope(e, scope...))
601598
}

sql/expression/function/aggregation/group_concat.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type GroupConcat struct {
4040
var _ sql.FunctionExpression = &GroupConcat{}
4141
var _ sql.Aggregation = &GroupConcat{}
4242
var _ sql.WindowAdaptableExpression = (*GroupConcat)(nil)
43+
var _ sql.OrderedAggregation = (*GroupConcat)(nil)
4344

4445
func NewEmptyGroupConcat() sql.Expression {
4546
return &GroupConcat{}
@@ -229,9 +230,8 @@ func (g *GroupConcat) WithChildren(children ...sql.Expression) (sql.Expression,
229230
return NewGroupConcat(g.distinct, g.sf.FromExpressions(orderByExpr...), g.separator, children[sortFieldMarker:], g.maxLen), nil
230231
}
231232

232-
// GetSelectExprs returns the select expressions
233-
// TODO: just expose the member variable
234-
func (g *GroupConcat) GetSelectExprs() []sql.Expression {
233+
// OutputExpressions implements the OrderedAggregation interface.
234+
func (g *GroupConcat) OutputExpressions() []sql.Expression {
235235
return g.selectExprs
236236
}
237237

0 commit comments

Comments
 (0)