-
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
expression: fix unix_timestamp
function which is not compatible with Mysql
#9751
Conversation
Codecov Report
@@ Coverage Diff @@
## master #9751 +/- ##
================================================
+ Coverage 77.2106% 77.2378% +0.0272%
================================================
Files 405 405
Lines 81661 81662 +1
================================================
+ Hits 63051 63074 +23
+ Misses 13933 13919 -14
+ Partials 4677 4669 -8 |
b3ba91a
to
793ce9d
Compare
For unit test, you can reference cases in |
793ce9d
to
79daae1
Compare
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
e15b724
to
17c0043
Compare
PTAL @lamxTyler @eurekaka |
if _, ok := args[0].(*Column); ok { | ||
retDecimal = types.UnspecifiedLength | ||
} else { | ||
tmpStr, _, err := args[0].EvalString(ctx, chunk.Row{}) |
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.
Consider this case: args[0] is a scalar function, but it refers to other columns. Directly calling args[0].EvalString()
would cause a nil pointer deference panic because the input Row
is empty in this case.
A simple SQL can be:
select unix_timestamp(concat(a+b)) from t;
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.
You're right, I think that some scalar functions would panic. And the test passing surprises we.
Can we eval it here for scalar function like concat
?
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 general scalar function, I think we can not. We can specially handle the GetVar
function in the non-prepare statements. However, it's better to check how mysql handle this scenario in their codebase.
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 general scalar function, I think we can not. We can specially handle the
GetVar
function in the non-prepare statements. However, it's better to check how mysql handle this scenario in their codebase.
Agree with you, we have better check the code in MySQL. And I think GetVar
is not the only function we need to handle.
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.
An off-topic finding: concat
seems to have bug currently
mysql> select concat(a+b) from t;
ERROR 1054 (42S22): Unknown column 'b' in 'field list'
mysql> select concat(a, b) from t;
ERROR 1054 (42S22): Unknown column 'b' in 'field list'
mysql> select unix_timestamp(concat(a+b)) from t;
ERROR 1054 (42S22): Unknown column 'b' in 'field list'
it reports error in parser.
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.
@eurekaka
Do you forget the column b when create table t?
mysql> create table t(a int, b int);
Query OK, 0 rows affected (0.04 sec)
mysql> select concat(a+b) from t;
Empty set (0.00 sec)
mysql> select concat(a, b) from t;
Empty set (0.01 sec)
mysql> select unix_timestamp(concat(a+b)) from t;
Empty set (0.01 sec)
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.
😭 My fault.
PTAL @wjhuang2016 |
This PR rely on a issue #10168, and it's complex to fix it. |
Since there is no way to determine if an expression is |
What problem does this PR solve?
fix #9729
What is changed and how it works?
The implement of the original only considers the case of
Constant
. We need to consider the case such asselect unix_timestamp(@1)
I found that it's hard to build a test for such sistuation, maybe some one could tell we how to add the test?
Check List
Tests
Code changes
Side effects
Related changes