Skip to content

Commit

Permalink
Dont crash on nil in LOGICAL_OR and LOGICAL_AND (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
ohaibbq authored Mar 9, 2024
1 parent 961ce06 commit b14ee6a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/function_aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,9 @@ type LOGICAL_AND struct {
}

func (f *LOGICAL_AND) Step(cond Value, opt *AggregatorOption) error {
if cond == nil {
return nil
}
b, err := cond.ToBool()
if err != nil {
return err
Expand All @@ -369,6 +372,9 @@ type LOGICAL_OR struct {
}

func (f *LOGICAL_OR) Step(cond Value, opt *AggregatorOption) error {
if cond == nil {
return nil
}
b, err := cond.ToBool()
if err != nil {
return err
Expand Down
12 changes: 12 additions & 0 deletions query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -783,11 +783,23 @@ SELECT ARRAY_CONCAT_AGG(x) AS array_concat_agg FROM (
query: `SELECT LOGICAL_AND(x) AS logical_and FROM UNNEST([true, false, true]) AS x`,
expectedRows: [][]interface{}{{false}},
},
{
name: "logical_and null",
query: ` WITH toks AS (SELECT FALSE AS x UNION ALL SELECT FALSE UNION ALL SELECT NULL)
SELECT LOGICAL_AND(x) AS logical_or FROM toks`,
expectedRows: [][]interface{}{{false}},
},
{
name: "logical_or",
query: `SELECT LOGICAL_OR(x) AS logical_or FROM UNNEST([true, false, true]) AS x`,
expectedRows: [][]interface{}{{true}},
},
{
name: "logical_or null",
query: ` WITH toks AS (SELECT FALSE AS x UNION ALL SELECT FALSE UNION ALL SELECT NULL)
SELECT LOGICAL_OR(x) AS logical_or FROM toks`,
expectedRows: [][]interface{}{{false}},
},
{
name: "max from int group",
query: `SELECT MAX(x) AS max FROM UNNEST([8, 37, 4, 55]) AS x`,
Expand Down

0 comments on commit b14ee6a

Please sign in to comment.