Skip to content

Commit f063d44

Browse files
committed
new hacky extension point for aggregate id
1 parent e116aa6 commit f063d44

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

sql/planbuilder/aggregates.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,10 @@ func (b *Builder) buildAggregation(fromScope, projScope *scope, groupingCols []s
257257
return outScope
258258
}
259259

260-
func isAggregateFunc(name string) bool {
260+
// IsAggregateFunc is a hacky "extension point" to allow for other dialects to declare additional aggregate functions
261+
var IsAggregateFunc = IsMySQLAggregateFuncName
262+
263+
func IsMySQLAggregateFuncName(name string) bool {
261264
switch name {
262265
case "avg", "bit_and", "bit_or", "bit_xor", "count",
263266
"group_concat", "json_arrayagg", "json_objectagg",
@@ -794,7 +797,7 @@ func (b *Builder) analyzeHaving(fromScope, projScope *scope, having *ast.Where)
794797
return false, nil
795798
case *ast.FuncExpr:
796799
name := n.Name.Lowered()
797-
if isAggregateFunc(name) {
800+
if IsAggregateFunc(name) {
798801
// record aggregate
799802
// TODO: this should get projScope as well
800803
_ = b.buildAggregateFunc(fromScope, name, n)

sql/planbuilder/scalar.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func (b *Builder) buildScalar(inScope *scope, e ast.Expr) (ex sql.Expression) {
153153
return b.buildNameConst(inScope, v)
154154
} else if name == "icu_version" {
155155
return expression.NewLiteral(icuVersion, types.MustCreateString(query.Type_VARCHAR, int64(len(icuVersion)), sql.Collation_Default))
156-
} else if isAggregateFunc(name) && v.Over == nil {
156+
} else if IsAggregateFunc(name) && v.Over == nil {
157157
// TODO this assumes aggregate is in the same scope
158158
// also need to avoid nested aggregates
159159
return b.buildAggregateFunc(inScope, name, v)

sql/planbuilder/show.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ func (b *Builder) buildAsOfExpr(inScope *scope, time ast.Expr) sql.Expression {
614614
return expression.NewLiteral(v.String(), types.LongText)
615615
case *ast.FuncExpr:
616616
// todo(max): more specific validation for nested ASOF functions
617-
if isWindowFunc(v.Name.Lowered()) || isAggregateFunc(v.Name.Lowered()) {
617+
if isWindowFunc(v.Name.Lowered()) || IsAggregateFunc(v.Name.Lowered()) {
618618
err := sql.ErrInvalidAsOfExpression.New(v)
619619
b.handleErr(err)
620620
}

0 commit comments

Comments
 (0)