diff --git a/sql3/planner/inbuiltfunctionsset.go b/sql3/planner/inbuiltfunctionsset.go index 8c24f8559..0d31c9203 100644 --- a/sql3/planner/inbuiltfunctionsset.go +++ b/sql3/planner/inbuiltfunctionsset.go @@ -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: diff --git a/sql3/test/defs/defs_set_functions.go b/sql3/test/defs/defs_set_functions.go index c3acc23c1..aa0d7edde 100644 --- a/sql3/test/defs/defs_set_functions.go +++ b/sql3/test/defs/defs_set_functions.go @@ -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", + }, }, }