-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
ast, plan: return error when the arg of VALUES() function is not a column #7817
Conversation
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
/run-all-tests |
case *ast.ValuesExpr: | ||
if v.Column == nil { | ||
g.err = ErrUnknownColumn.GenWithStackByArgs("", "VALUES() function") | ||
} |
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.
For ValuesExpr
, if v.Column
is valid, shall we extract it and return this valid ColumnNameExpr
as what we do in PositionExpr
branch?
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.
Seems not.
i.e.
MySQL:
set @@sql_mode='only_full_group_by';
mysql> SELECT a AS b FROM t GROUP BY VALUES(b);
ERROR 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'test.t.a' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
If we return ColumnNameExpr here, the check for only_full_group_by will be passed, this is not compatible with MySQL.
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.
related issue:
#7822
ast/expressions.go
Outdated
@@ -927,7 +927,10 @@ func (n *ValuesExpr) Accept(v Visitor) (Node, bool) { | |||
if !ok { | |||
return n, false | |||
} | |||
n.Column = node.(*ColumnNameExpr) | |||
n.Column, ok = node.(*ColumnNameExpr) | |||
if !ok { |
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 prefer to put this check in ColumnNameExpr
branch of gbyResolver::Leave
, i.e, for a ColumnNameExpr
, if the extracted result is not ColumnNameExpr
, we should report error.
Accept
acts as a general walker, it should not involve detailed visitor logic IMHO.
PTAL @eurekaka |
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
/run-all-tests |
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
PTAL @eurekaka @winoros
What problem does this PR solve?
Before this PR:
After this PR:
What is changed and how it works?
Before this PR, we assume that the argument for VALUES must be a
ColumnNameExpr
,which is promised as the example above shows.
This PR checks the type of argument for VALUES, if it's not a
ColumnNameExpr
, we will raise an error.Check List
Tests
Code changes
Side effects
none
Related changes
none