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 bug which Float type is not effective in AddDate & SubDate function #7840

Merged
merged 6 commits into from
Oct 12, 2018

Conversation

lzmhhh123
Copy link
Contributor

@lzmhhh123 lzmhhh123 commented Oct 8, 2018

What problem does this PR solve?

Before this pr, there are some bugs in AddDate & SubDate function like follow

tidb(localhost:4000) > SELECT TIME('20:20:20.1') + INTERVAL .6 SECOND;
ERROR 2013 (HY000): Lost connection to MySQL server during query

tidb(localhost:4000) > select adddate("2011-01-01 00:00:00", interval 10.1 SECOND);
+------------------------------------------------------+
| adddate("2011-01-01 00:00:00", interval 10.1 SECOND) |
+------------------------------------------------------+
| 2011-01-01 00:00:10                                  |
+------------------------------------------------------+
1 row in set (0.00 sec)

What is changed and how it works?

After this pr, the queries are like follow

tidb(localhost:4000) > SELECT TIME('20:20:20.1') + INTERVAL .6 SECOND;
+-----------------------------------------+
| TIME('20:20:20.1') + INTERVAL .6 SECOND |
+-----------------------------------------+
| 2018-10-08 20:20:20.700000              |
+-----------------------------------------+
1 row in set (0.01 sec)

tidb(localhost:4000) > select adddate("2011-01-01 00:00:00", interval 10.1 SECOND);
+------------------------------------------------------+
| adddate("2011-01-01 00:00:00", interval 10.1 SECOND) |
+------------------------------------------------------+
| 2011-01-01 00:00:10.100000                           |
+------------------------------------------------------+
1 row in set (0.00 sec)

All these results are same as MySQL.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)

Code changes

  • Has exported function/method change
  • Has exported variable/fields change

@lzmhhh123 lzmhhh123 changed the title types: fix bug which Float type is not effort in AddDate & SubDate function types: fix bug which Float type is not effective in AddDate & SubDate function Oct 8, 2018
@@ -2707,6 +2719,11 @@ func (c *addDateFunctionClass) getFunction(ctx sessionctx.Context, args []Expres
baseBuiltinFunc: bf,
baseDateArithmitical: newDateArighmeticalUtil(),
}
case dateEvalTp == types.ETInt && intervalEvalTp == types.ETDecimal:
Copy link
Member

Choose a reason for hiding this comment

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

Could you extract a function to check if we should use Decimal math, there are some redundant code, and it's easy to make mistake to write compose equal condition.

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

@XuHuaiyu @tiancaiamao PTAL

@tiancaiamao
Copy link
Contributor

/run-all-tests

@tiancaiamao
Copy link
Contributor

/run-all-tests

@tiancaiamao
Copy link
Contributor

/run-all-tests

@tiancaiamao
Copy link
Contributor

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants