Skip to content
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
32 changes: 24 additions & 8 deletions enginetest/queries/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -766,16 +766,32 @@ var SpatialQueryTests = []QueryTest{

var QueryTests = []QueryTest{
{
Query: "SELECT 1 % true",
Expected: []sql.Row{{"0"}},
Query: "SELECT 1 WHERE ((1 IN (NULL >= 1)) IS NULL);",
Expected: []sql.Row{{1}},
},
{
Query: "SELECT * from mytable where (1/1 and true)",
Expected: []sql.Row{
{1, "first row"},
{2, "second row"},
{3, "third row"},
},
Query: "SELECT 1 WHERE (1 IN (NULL NOT BETWEEN -1 AND 1)) IS NULL;",
Expected: []sql.Row{{1}},
},
{
Query: "SELECT 1 WHERE ((1 IN (NULL * 1)) IS NULL);",
Expected: []sql.Row{{1}},
},
{
Query: "SELECT count(*) from mytable WHERE ((i IN (NULL >= 1)) IS NULL);",
Expected: []sql.Row{{3}},
},
{
Query: "SELECT count(*) from mytable WHERE (i IN (NULL NOT BETWEEN -1 AND 1)) IS NULL;",
Expected: []sql.Row{{3}},
},
{
Query: "SELECT count(*) from mytable WHERE ((i IN (NULL * 1)) IS NULL);",
Expected: []sql.Row{{3}},
},
{
Query: "SELECT 1 % true",
Expected: []sql.Row{{"0"}},
},
{
Query: "SELECT * from mytable where (0.000 and true)",
Expand Down
12 changes: 8 additions & 4 deletions sql/expression/in.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,16 @@ func newInMap(ctx *sql.Context, right Tuple, lType sql.Type) (map[uint64]sql.Exp

if el.Type() == types.Null {
hasNull = true
continue
}
i, err := el.Eval(ctx, sql.Row{})
if err != nil {
return nil, hasNull, err
}
if i == nil {
hasNull = true
continue
}

key, err := hashOfSimple(ctx, i, lType)
if err != nil {
Expand Down Expand Up @@ -249,10 +254,6 @@ func hashOfSimple(ctx *sql.Context, i interface{}, t sql.Type) (uint64, error) {

// Eval implements the Expression interface.
func (hit *HashInTuple) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
if hit.hasNull {
return nil, nil
}

leftElems := types.NumColumns(hit.in.Left().Type().Promote())

leftVal, err := hit.in.Left().Eval(ctx, row)
Expand All @@ -271,6 +272,9 @@ func (hit *HashInTuple) Eval(ctx *sql.Context, row sql.Row) (interface{}, error)

right, ok := hit.cmp[key]
if !ok {
if hit.hasNull {
return nil, nil
}
return false, nil
}

Expand Down