Skip to content

Commit

Permalink
Dont crash on nil in LOGICAL_OR and LOGICAL_AND (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
ohaibbq authored Mar 2, 2024
1 parent f53a6e2 commit 2425672
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 @@ -322,6 +322,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 @@ -341,6 +344,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 @@ -815,11 +815,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 2425672

Please sign in to comment.