Skip to content

Commit

Permalink
feat(spanner/spannertest): implement ANY_VALUE aggregation function (#…
Browse files Browse the repository at this point in the history
…3428)

Fixes #3375.
  • Loading branch information
dsymonds committed Dec 9, 2020
1 parent 48aa1ce commit e16c3e9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
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

0 comments on commit e16c3e9

Please sign in to comment.