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

types: fix converting decimal to datetime and timestamp #9899

Merged
merged 2 commits into from
Mar 30, 2019

Conversation

Debiancc
Copy link
Contributor

@Debiancc Debiancc commented Mar 26, 2019

What problem does this PR solve?

fix #9770

What is changed and how it works?

In Datum.convertToMysqlTime function add KindMysqlDecimal switch case, and convert decimal to string then parse to Time

Check List

Tests

mysql> INSERT INTO t1 VALUES (20010101100000.1234566);
Query OK, 1 row affected (0.00 sec)

mysql> select * from t1;
+----------------------------+
| a                          |
+----------------------------+
| 2001-01-01 10:00:00.123456 |
| 2001-01-01 10:00:00.123457 |
| 2001-01-01 10:00:00.123457 |
+----------------------------+
3 rows in set (0.00 sec)

mysql> select tidb_version();
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version()                                                                                                                                                                                                                                                                                                                             |
| Release Version: v3.0.0-beta-251-gb4cc3e489-dirty
Git Commit Hash: b4cc3e48934afaefbf6d5f65b5414b8b65117234
Git Branch: master
UTC Build Time: 2019-03-26 07:10:09
GoVersion: go version go1.12.1 darwin/amd64
Race Enabled: false
TiKV Min Version: 2.1.0-alpha.1-ff3dd160846b7d1aed9079c389fc188f7f5ea13e
Check Table Before Drop: false |

1 row in set (0.00 sec)

Side effects

  • Possible performance regression

@CLAassistant
Copy link

CLAassistant commented Mar 26, 2019

CLA assistant check
All committers have signed the CLA.

@codecov
Copy link

codecov bot commented Mar 26, 2019

Codecov Report

Merging #9899 into master will increase coverage by 0.0757%.
The diff coverage is 100%.

@@               Coverage Diff                @@
##             master      #9899        +/-   ##
================================================
+ Coverage   77.4516%   77.5273%   +0.0757%     
================================================
  Files           404        404                
  Lines         81722      81726         +4     
================================================
+ Hits          63295      63360        +65     
+ Misses        13703      13660        -43     
+ Partials       4724       4706        -18

@qw4990 qw4990 self-requested a review March 27, 2019 02:43
@qw4990 qw4990 added component/expression contribution This PR is from a community contributor. type/bugfix This PR fixes a bug. labels Mar 27, 2019
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.

Thanks for your contribution.
Could you please add some unit tests in types/datum_test.go and expression/integration_test.go.

@qw4990
Copy link
Contributor

qw4990 commented Mar 27, 2019

CREATE TABLE t2(a TIMESTAMP);
INSERT INTO t2 VALUES (20010101100000.1234567);

And besides MysqlTime, when TiDB converts a Decimal to Timestamp, it will generate a similar error like ERROR 1105 (HY000): cannot convert datum from decimal to type timestamp..

This problem should have the same reason with MysqlTime.
Could you please fix this problem 😺

@Debiancc
Copy link
Contributor Author

CREATE TABLE t2(a TIMESTAMP);
INSERT INTO t2 VALUES (20010101100000.1234567);

And besides MysqlTime, when TiDB converts a Decimal to Timestamp, it will generate a similar error like ERROR 1105 (HY000): cannot convert datum from decimal to type timestamp..

This problem should have the same reason with MysqlTime.
Could you please fix this problem 😺

Sure, i will fix that and cover test later.

@qw4990
Copy link
Contributor

qw4990 commented Mar 29, 2019

/rebuild

@qw4990 qw4990 requested review from XuHuaiyu and alivxxx March 29, 2019 08:25
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
Copy link
Contributor

qw4990 commented Mar 29, 2019

/rebuild

@qw4990
Copy link
Contributor

qw4990 commented Mar 29, 2019

@Debiancc There are some CI problems, but it seems that they are not caused by this PR.
Could you please resolve these conflicts and rebase this PR to the latest Master branch.

@qw4990
Copy link
Contributor

qw4990 commented Mar 29, 2019

/rebuild

Copy link
Contributor

@alivxxx alivxxx left a comment

Choose a reason for hiding this comment

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

LGTM

@alivxxx alivxxx added the status/LGT2 Indicates that a PR has LGTM 2. label Mar 29, 2019
@zz-jason zz-jason changed the title fix(#9770): Datum.convertToMysqlTime supported decimal type types: fix converting decimal to datetime and timestamp Mar 29, 2019
Copy link
Member

@zz-jason zz-jason left a comment

Choose a reason for hiding this comment

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

LGTM

@zz-jason
Copy link
Member

/run-all-tests

@zz-jason
Copy link
Member

/run-unit-test

@zz-jason zz-jason merged commit 424995d into pingcap:master Mar 30, 2019
@zz-jason
Copy link
Member

@Debiancc please cherry pick this change to release 2.1

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. status/LGT2 Indicates that a PR has LGTM 2. type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Converting decimal to datetime or timestamp when insert is not compatible with MySQL
5 participants