MCPcopy Create free account
hub / github.com/brimdata/super / maybeConvertAgg

Method maybeConvertAgg

compiler/semantic/expr.go:1117–1141  ·  view source on GitHub ↗
(call *ast.CallExpr, inType super.Type)

Source from the content-addressed store, hash-verified

1115}
1116
1117func (t *translator) maybeConvertAgg(call *ast.CallExpr, inType super.Type) (sem.Expr, super.Type) {
1118 name, ok := call.Func.(*ast.FuncNameExpr)
1119 if !ok {
1120 return nil, t.checker.unknown
1121 }
1122 nameLower := strings.ToLower(name.Name)
1123 if _, err := agg.NewPattern(nameLower, false, true); err != nil {
1124 return nil, t.checker.unknown
1125 }
1126 if err := function.CheckArgCount(len(call.Args), 0, 1); err != nil {
1127 if nameLower == "min" || nameLower == "max" {
1128 // min and max are special cases as they are also functions. If the
1129 // number of args is greater than 1 they're probably a function so do not
1130 // return an error.
1131 return nil, nil
1132 }
1133 t.error(call, err)
1134 return badExpr, t.checker.unknown
1135 }
1136 var e ast.Expr
1137 if len(call.Args) == 1 {
1138 e = call.Args[0]
1139 }
1140 return t.aggFunc(call, nameLower, e, nil, false, inType)
1141}
1142
1143func (t *translator) aggFunc(n ast.Node, name string, arg ast.Expr, filter ast.Expr, distinct bool, inType super.Type) (sem.Expr, super.Type) {
1144 // If we are in the context of a having clause, re-expose the select schema

Callers 2

maybeCallShortcutMethod · 0.95
semCallMethod · 0.95

Calls 4

aggFuncMethod · 0.95
NewPatternFunction · 0.92
CheckArgCountFunction · 0.92
errorMethod · 0.45

Tested by

no test coverage detected