-
Notifications
You must be signed in to change notification settings - Fork 70
change "where" clause of agg functions to "filter" #6465
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This commit changes the "where <expr>" clause on agg functions to use the SQL syntax "filter ( <expr> )". While we were here, we change ast.Agg to ast.AggFunc, removed the Where field from ast.CallExpr, and cleaned up the grammar for how agg functions are integrated into expressions and shortcuts. We also fixed a big where "count(*) where ..." did not previously parse, but "count(*) filter ( ... )" now works.
compiler/ast/op.go
Outdated
| // upon a function of the record, e.g., count() counts up records without | ||
| // looking into them. | ||
| type Agg struct { | ||
| type AggFunc struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: While you're here, maybe move this to expr.go?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also gonna call it AggFuncExpr
compiler/parser/parser.peg
Outdated
|
|
||
| FilterClause = _ FILTER __ "(" __ expr:LogicalOrExpr __ ")" { return expr, nil } | ||
|
|
||
| WhereClause = _ WHERE _ expr:LogicalOrExpr { return expr, nil } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Since this is now used only in FromSelect and Select, maybe move it down where OptWhereClause used to live?
compiler/parser/support.go
Outdated
|
|
||
| func newCall(c *current, name, args, where any) ast.Expr { | ||
| func newCall(c *current, name, args any) ast.Expr { | ||
| call := &ast.CallExpr{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit:
| call := &ast.CallExpr{ | |
| return &ast.CallExpr{ |
compiler/semantic/op.go
Outdated
| }, | ||
| } | ||
| values := sem.NewValues(agg, sem.NewThis(agg, []string{name})) | ||
| return append(append(seq, aggregate), values) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit:
| return append(append(seq, aggregate), values) | |
| return append(seq, aggregate, values) |
This commit changes the "where " clause on agg functions to use the SQL syntax "filter ( )".
While we were here, we changed ast.Agg to ast.AggFunc, removed the Where field from ast.CallExpr, and cleaned up the grammar for how agg functions are integrated into expressions and shortcuts.
We also fixed a big where "count() where ..." did not previously parse, but "count() filter ( ... )" now works.
Fixes #6261