handle null results gracefully in SetContains{Any,All}

SetContains returns null if either of the values it's given
is null. SetContainsAny and SetContainsAll should also do this.
This commit is contained in:
Seebs 2023-03-20 11:53:39 -05:00 committed by seebs
parent 2b4d49e502
commit f12587f414
2 changed files with 53 additions and 0 deletions

View file

@ -69,6 +69,11 @@ func (n *callPlanExpression) EvaluateSetContainsAny(currentRow []interface{}) (i
return nil, err
}
//if either term is null, then null
if testSetEval == nil || targetSetEval == nil {
return nil, nil
}
if targetSetEval != nil {
switch typ := n.args[0].Type().(type) {
case *parser.DataTypeStringSet:
@ -116,6 +121,11 @@ func (n *callPlanExpression) EvaluateSetContainsAll(currentRow []interface{}) (i
return nil, err
}
//if either term is null, then null
if testSetEval == nil || targetSetEval == nil {
return nil, nil
}
if targetSetEval != nil {
switch typ := n.args[0].Type().(type) {
case *parser.DataTypeStringSet:

View file

@ -146,6 +146,8 @@ var setFunctionTests = TableTest{
name: "set-contains-int",
SQLs: sqls(
"select * from selectwithset where setcontains(ievent, 101)",
"select * from selectwithset where setcontainsany(ievent, [101])",
"select * from selectwithset where setcontainsall(ievent, [101])",
),
ExpHdrs: hdrs(
hdr("_id", fldTypeID),
@ -159,6 +161,23 @@ var setFunctionTests = TableTest{
),
Compare: CompareExactUnordered,
},
{
// SetContainsInt
name: "set-contains-int-using-value",
SQLs: sqls(
"select _id, setcontainsany(ievent, [101]) from selectwithset",
),
ExpHdrs: hdrs(
hdr("_id", fldTypeID),
hdr("", fldTypeBool),
),
ExpRows: rows(
row(int64(1), true),
row(int64(2), nil),
row(int64(3), nil),
),
Compare: CompareExactUnordered,
},
{
// SetContainsOrSetContains
// SetContainsAny
@ -227,6 +246,30 @@ var setFunctionTests = TableTest{
),
ExpErr: "types 'stringset' and 'stringset' are not equatable",
},
{
// SetContainsWrongTypeSet
name: "set-contains-null-in-values",
SQLs: sqls(
"select * from selectwithset where setcontains(event, [null])",
),
ExpErr: "set literal must contain ints or strings",
},
{
// SetContainsWrongTypeSet
name: "set-contains-null-value",
SQLs: sqls(
"select * from selectwithset where setcontains(event, null)",
),
ExpErr: "types 'stringset' and 'void' are not equatable",
},
{
// SetContainsWrongTypeSet
name: "set-contains-null-set",
SQLs: sqls(
"select * from selectwithset where setcontains(null, [1])",
),
ExpErr: "set expression expected",
},
},
}