-
-
Notifications
You must be signed in to change notification settings - Fork 213
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
resolve aliases in subqueries in function arguments #1838
Conversation
{ | ||
Query: `SELECT if(0, "abc", 456)`, | ||
Expected: []sql.Row{ | ||
{456}, |
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 should be a string, but the TestEvaluation doesn't go through the schema[0].Convert code path.
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.
should we 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.
or is it just bad test setup
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.
I think it's just bad test setup, when the results are written to the shell we use the writerIters, but not for evaluation.
I can add it in a separate PR, and see how many failures we get
@@ -123,6 +123,30 @@ func reorderProjection(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.Sc | |||
}) | |||
} | |||
|
|||
// findDeferredColumns is a function that searches through a projection's expressions and checks if there are any | |||
// subqueries that reference the deferred column. Additionally, we have to check for subqueries in functions arguments | |||
func findDeferredColumns(exprs ...sql.Expression) []column { |
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.
is there any reason not to just transform.Expr
for each of these?
t.Run("if() type is correct", func(t *testing.T) { | ||
handler.ComInitDB(dummyConn, "test") | ||
var result *sqltypes.Result | ||
err := handler.ComQuery(dummyConn, "select if(1, 123, 'def')", func(res *sqltypes.Result, more bool) error { |
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.
should be do (0, "def", 123)
-> "123
?
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.
The old code had return n.ifTrue.Type()
, which was already Text, so it didn't actually test the new code I added.
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, could probably add more tests, but we need a dedicated expression typing module before realistically fixing the long tail
The rule
reorderProjection
also replaces subqueries with getfields in projections when they are used by subqueries, but it did not check for function expressions.This meant that aliases in subqueries as arguments to functions threw a
"x" could not be found
error.This PR just has the section of
reorderProjection
that is supposed to find deferredColumns also look at the arguments of functions recursively (because we can nest functions).Additionally, there was another schema type bug:
MySQL returns an Integer type for if statement, and if either argument is a String, it always returns a String.
fix for: dolthub/dolt#6174