Skip to content
Permalink
Browse files
feat(spanner/spannertest): implement ANY_VALUE aggregation function (#…
…3428)

Fixes #3375.
  • Loading branch information
dsymonds committed Dec 9, 2020
1 parent 48aa1ce commit e16c3e9b412762b85483f3831ee586a5e6631313
Showing with 14 additions and 0 deletions.
  1. +13 −0 spanner/spannertest/funcs.go
  2. +1 −0 spanner/spansql/keywords.go
@@ -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) {
@@ -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,

0 comments on commit e16c3e9

Please sign in to comment.