-
-
Notifications
You must be signed in to change notification settings - Fork 209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update some analyzer rules and expression behavior to deal with tuples in a more principled way. #560
Conversation
…s in a more principled way. Subquery expression nodes can now return tuples. InSubquery expression nodes can work with tuples as expected. An analyzer validation step now returns operand errors in more cases, expecting almost all expressions to return one column, but special casing certain operators and functions which support tuples. Added some TODO tests for cases where our tuple comparisons are still not behaving as we want them to. In particular, null safe vs. non-null safe comparisons and type coercion of tuple subtypes in comparisons still need work.
@@ -531,22 +558,38 @@ func validateSubqueryColumns(ctx *sql.Context, a *Analyzer, n sql.Node, scope *S | |||
return true | |||
} | |||
|
|||
outerScopeRowLen := len(schemas(n.Children())) | |||
plan.InspectExpressionsWithNode(s.Query, func(n sql.Node, e sql.Expression) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This portion of the validation never actually worked, because the if condition down below as !valid
and this block never touched valid
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just a couple commens
enginetest/queries.go
Outdated
Query: "SELECT 1 FROM DUAL WHERE (1, 2) in ((3, 4), (5, 6), (1, 2))", | ||
Expected: []sql.Row{{1}}, | ||
}, | ||
// TODO |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move to BrokenQueries?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same below
Expected: []sql.Row{{1}}, | ||
}, | ||
{ | ||
Query: "SELECT 1 FROM DUAL WHERE (1, 2) in ((3, 4), (5, 6), (1, 2))", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing a false case for IN for tuple literals
Also should have a couple NOT IN cases
Expected: []sql.Row{{1}}, | ||
}, | ||
{ | ||
Query: "SELECT 1 FROM DUAL WHERE (null, null) <=> (select 1, 4 from dual where false)", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we expect <=> to work with nulls in tuples, e..g (null, null) <=> (select null, null)
? Need a test if so, a BrokenQueries test if not
Expected: []sql.Row{{1}}, | ||
}, | ||
{ | ||
Query: "SELECT (((1,2),3)) = (((1,2),3)) from dual", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoa, is this standard SQL? Tuples can nest?
sql/analyzer/validation_rules.go
Outdated
func validateSubqueryColumns(ctx *sql.Context, a *Analyzer, n sql.Node, scope *Scope) (sql.Node, error) { | ||
func validateOperands(ctx *sql.Context, a *Analyzer, n sql.Node, scope *Scope) (sql.Node, error) { | ||
// Validate that the number of columns in an operand or a top level | ||
// expression are as expected. The currently rules are: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
current rules
if ok && len(s.Query.Schema()) != 1 { | ||
valid = false | ||
var err error | ||
plan.Inspect(n, func(n sql.Node) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not plan.InspectExpressions?
… debug analyzer output.
Subquery expression nodes can now return tuples.
InSubquery expression nodes can work with tuples as expected.
An analyzer validation step now returns operand errors in more cases, expecting
almost all expressions to return one column, but special casing certain
operators and functions which support tuples.
Added some TODO tests for cases where our tuple comparisons are still not
behaving as we want them to. In particular, null safe vs. non-null safe
comparisons and type coercion of tuple subtypes in comparisons still need work.