mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 02:44:59 +00:00
unbreak nested joins
It turns out that the problem with nested joins was that we were trying to cleverly invert them, but that seems to be incorrect and resulted in incorrect nesting. The test case for this is SELECT * FROM X INNER JOIN Y ON true INNER JOIN Z ON false this is now parsed as (X inner join Y on true) inner join z on false Which, as it turns out, is the structure that stringizes back to the original statement. We were previously parsing it as X inner join (y inner join z on false) on true which stringizes out to a different form, and is also, I think, just straightforwardly not what we want. So basically, we had special case code to recognize that we were doing a join on top of another join, and invert them in some way, and I have no idea why because that seems not to be correct, or at least, it produces nonsensical stringizing that we can't then parse.
This commit is contained in:
parent
3f7ae75e17
commit
f4905891d4
2 changed files with 21 additions and 38 deletions
|
|
@ -2419,22 +2419,7 @@ func (p *Parser) parseSource() (source Source, err error) {
|
|||
return source, err
|
||||
}
|
||||
|
||||
// Rewrite last source to nest next join on right side.
|
||||
if lhs, ok := source.(*JoinClause); ok {
|
||||
source = &JoinClause{
|
||||
X: lhs.X,
|
||||
Operator: lhs.Operator,
|
||||
Y: &JoinClause{
|
||||
X: lhs.Y,
|
||||
Operator: operator,
|
||||
Y: y,
|
||||
Constraint: constraint,
|
||||
},
|
||||
Constraint: lhs.Constraint,
|
||||
}
|
||||
} else {
|
||||
source = &JoinClause{X: source, Operator: operator, Y: y, Constraint: constraint}
|
||||
}
|
||||
source = &JoinClause{X: source, Operator: operator, Y: y, Constraint: constraint}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2055,38 +2055,36 @@ func TestParser_ParseStatement(t *testing.T) {
|
|||
},
|
||||
},
|
||||
})
|
||||
/*
|
||||
// This one doesn't work right now because our stringify of this statement is wrong.
|
||||
AssertParseStatement(t, `SELECT * FROM X INNER JOIN Y ON true INNER JOIN Z ON false`, &parser.SelectStatement{
|
||||
Select: pos(0),
|
||||
Columns: []*parser.ResultColumn{
|
||||
{Star: pos(7)},
|
||||
},
|
||||
From: pos(9),
|
||||
Source: &parser.JoinClause{
|
||||
AssertParseStatement(t, `SELECT * FROM X INNER JOIN Y ON true INNER JOIN Z ON false`, &parser.SelectStatement{
|
||||
Select: pos(0),
|
||||
Columns: []*parser.ResultColumn{
|
||||
{Star: pos(7)},
|
||||
},
|
||||
From: pos(9),
|
||||
Source: &parser.JoinClause{
|
||||
X: &parser.JoinClause{
|
||||
X: &parser.QualifiedTableName{
|
||||
Name: &parser.Ident{NamePos: pos(14), Name: "X"},
|
||||
},
|
||||
Operator: &parser.JoinOperator{Inner: pos(16), Join: pos(22)},
|
||||
Y: &parser.JoinClause{
|
||||
X: &parser.QualifiedTableName{
|
||||
Name: &parser.Ident{NamePos: pos(27), Name: "Y"},
|
||||
},
|
||||
Operator: &parser.JoinOperator{Inner: pos(37), Join: pos(43)},
|
||||
Y: &parser.QualifiedTableName{
|
||||
Name: &parser.Ident{NamePos: pos(48), Name: "Z"},
|
||||
},
|
||||
Constraint: &parser.OnConstraint{
|
||||
On: pos(50),
|
||||
X: &parser.BoolLit{ValuePos: pos(53), Value: false},
|
||||
},
|
||||
Y: &parser.QualifiedTableName{
|
||||
Name: &parser.Ident{NamePos: pos(27), Name: "Y"},
|
||||
},
|
||||
Constraint: &parser.OnConstraint{
|
||||
On: pos(29),
|
||||
X: &parser.BoolLit{ValuePos: pos(32), Value: true},
|
||||
},
|
||||
},
|
||||
})*/
|
||||
Operator: &parser.JoinOperator{Inner: pos(37), Join: pos(43)},
|
||||
Y: &parser.QualifiedTableName{
|
||||
Name: &parser.Ident{NamePos: pos(48), Name: "Z"},
|
||||
},
|
||||
Constraint: &parser.OnConstraint{
|
||||
On: pos(50),
|
||||
X: &parser.BoolLit{ValuePos: pos(53), Value: false},
|
||||
},
|
||||
},
|
||||
})
|
||||
AssertParseStatement(t, `SELECT * FROM foo LEFT OUTER JOIN bar`, &parser.SelectStatement{
|
||||
Select: pos(0),
|
||||
Columns: []*parser.ResultColumn{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue