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

Dont crash on nil in LOGICAL_OR and LOGICAL_AND #187

Merged
merged 1 commit into from
Mar 9, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading