Skip to content
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

Closed
wants to merge 4 commits into from

Conversation

wjhuang2016
Copy link
Member

@wjhuang2016 wjhuang2016 commented Mar 15, 2019

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 as select 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

@codecov
Copy link

codecov bot commented Mar 15, 2019

Codecov Report

Merging #9751 into master will increase coverage by 0.0272%.
The diff coverage is 100%.

@@               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

@morgo morgo added contribution This PR is from a community contributor. component/expression labels Mar 17, 2019
expression/builtin_time.go Outdated Show resolved Hide resolved
expression/builtin_time.go Outdated Show resolved Hide resolved
@eurekaka
Copy link
Contributor

eurekaka commented Mar 19, 2019

For unit test, you can reference cases in expression/builtin_time_test.go to mock input, or you can add tests using SQL, see also expression/integration_test.go.

Copy link
Contributor

@qw4990 qw4990 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@qw4990 qw4990 added the status/LGT1 Indicates that a PR has LGTM 1. label Mar 20, 2019
@qw4990
Copy link
Contributor

qw4990 commented Mar 29, 2019

PTAL @lamxTyler @eurekaka

if _, ok := args[0].(*Column); ok {
retDecimal = types.UnspecifiedLength
} else {
tmpStr, _, err := args[0].EvalString(ctx, chunk.Row{})
Copy link
Member

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;

Copy link
Member Author

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?

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Contributor

@eurekaka eurekaka Apr 4, 2019

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.

Copy link
Member Author

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)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😭 My fault.

@qw4990
Copy link
Contributor

qw4990 commented May 7, 2019

PTAL @wjhuang2016

@wjhuang2016
Copy link
Member Author

PTAL @wjhuang2016

This PR rely on a issue #10168, and it's complex to fix it.
I think it's better to set this PR as DO NOT MERGE until we find a good way to determine whether a getVar func is a ConstItem.

@qw4990 qw4990 closed this May 7, 2019
@qw4990 qw4990 reopened this May 7, 2019
@qw4990 qw4990 added the wontfix This issue will not be fixed. label May 7, 2019
@alivxxx alivxxx removed their request for review July 18, 2019 06:03
@qw4990 qw4990 removed the status/LGT1 Indicates that a PR has LGTM 1. label Aug 5, 2019
@qw4990
Copy link
Contributor

qw4990 commented Aug 5, 2019

Since there is no way to determine if an expression is const accurately, we close this issue temporarily.

@qw4990 qw4990 closed this Aug 5, 2019
@wjhuang2016 wjhuang2016 deleted the fix_unixtimestamp branch November 17, 2022 11:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/expression contribution This PR is from a community contributor. wontfix This issue will not be fixed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

unix_timestamp is not compatible with Mysql
5 participants