Skip to content
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

feat(spanner/spannertest): implement ANY_VALUE aggregation function #3428

Merged
merged 1 commit into from Dec 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions spanner/spannertest/funcs.go
Expand Up @@ -37,6 +37,19 @@ type aggregateFunc struct {

// TODO: more aggregate funcs.
var aggregateFuncs = map[string]aggregateFunc{
"ANY_VALUE": {
// https://cloud.google.com/spanner/docs/aggregate_functions#any_value
Eval: func(values []interface{}, typ spansql.Type) (interface{}, spansql.Type, error) {
// Return the first non-NULL value.
for _, v := range values {
if v != nil {
return v, typ, nil
}
}
// Either all values are NULL, or there are no values.
return nil, typ, nil
},
},
"ARRAY_AGG": {
// https://cloud.google.com/spanner/docs/aggregate_functions#array_agg
Eval: func(values []interface{}, typ spansql.Type) (interface{}, spansql.Type, error) {
Expand Down
1 change: 1 addition & 0 deletions spanner/spansql/keywords.go
Expand Up @@ -129,6 +129,7 @@ var keywords = map[string]bool{
// https://cloud.google.com/spanner/docs/functions-and-operators
var funcs = map[string]bool{
// Aggregate functions.
"ANY_VALUE": true,
"ARRAY_AGG": true,
"AVG": true,
"BIT_XOR": true,
Expand Down