mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
fix bug on left/right join mapping
This commit is contained in:
parent
58007ab7ef
commit
32b5826d1a
2 changed files with 42 additions and 2 deletions
|
|
@ -755,6 +755,46 @@ func TestQuerySQLUnary(t *testing.T) {
|
|||
},
|
||||
eq: equal,
|
||||
},
|
||||
// The following cases test different paths within the `case *sqlparser.AndExpr`
|
||||
// of extract.go by providing different WHERE conditions.
|
||||
{
|
||||
// len(left) == 2 && len(right) == 1
|
||||
// right[0].table == left[0].table
|
||||
sql: "select _id from grouper g INNER JOIN joiner j ON g._id = j.grouperid where g.color = 'red' and j.jointype = 2 and g.age = 16",
|
||||
exp: tableResponse{
|
||||
headers: []columnInfo{{"_id", "uint64"}},
|
||||
rows: []row{
|
||||
{[]columnResponse{uint64(8)}},
|
||||
{[]columnResponse{uint64(9)}},
|
||||
},
|
||||
},
|
||||
eq: equalUnordered,
|
||||
},
|
||||
{
|
||||
// len(left) == 2 && len(right) == 1
|
||||
// right[0].table == left[1].table {
|
||||
sql: "select _id from grouper g INNER JOIN joiner j ON g._id = j.grouperid where j.jointype = 2 and g.color = 'red' and g.age = 16",
|
||||
exp: tableResponse{
|
||||
headers: []columnInfo{{"_id", "uint64"}},
|
||||
rows: []row{
|
||||
{[]columnResponse{uint64(8)}},
|
||||
{[]columnResponse{uint64(9)}},
|
||||
},
|
||||
},
|
||||
eq: equalUnordered,
|
||||
},
|
||||
{
|
||||
// len(left) == 1 && len(right) == 1 && left[0].table != right[0].table
|
||||
sql: "select _id from grouper g INNER JOIN joiner j ON g._id = j.grouperid where g.color = 'red' and g.age = 16 and j.jointype = 2",
|
||||
exp: tableResponse{
|
||||
headers: []columnInfo{{"_id", "uint64"}},
|
||||
rows: []row{
|
||||
{[]columnResponse{uint64(8)}},
|
||||
{[]columnResponse{uint64(9)}},
|
||||
},
|
||||
},
|
||||
eq: equalUnordered,
|
||||
},
|
||||
}
|
||||
|
||||
for i, test := range tests {
|
||||
|
|
|
|||
|
|
@ -1042,12 +1042,12 @@ func extractWheres(indexes []*pilosa.Index, tbls parseTables, expr sqlparser.Exp
|
|||
return []*tableWhere{left[0], right[0]}, nil
|
||||
}
|
||||
return nil, errors.Errorf("no matching table on right: %s", left[0].table.name)
|
||||
} else if len(left) == 1 && len(right) == 2 {
|
||||
} else if len(left) == 2 && len(right) == 1 {
|
||||
// if left(2) and right(1),
|
||||
// then intersect the 1's and return final(2)
|
||||
if right[0].table == left[0].table {
|
||||
right[0].where = Intersect(right[0].where, left[0].where)
|
||||
return []*tableWhere{left[0], right[1]}, nil
|
||||
return []*tableWhere{left[1], right[0]}, nil
|
||||
} else if right[0].table == left[1].table {
|
||||
right[0].where = Intersect(right[0].where, left[1].where)
|
||||
return []*tableWhere{left[0], right[0]}, nil
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue