Skip to content

str_to_date function push down (for poc)#1960

Merged
JaySon-Huang merged 18 commits intopingcap:v5.0.1_may_pocfrom
JaySon-Huang:str_to_date_pushdown_hotfix
May 23, 2021
Merged

str_to_date function push down (for poc)#1960
JaySon-Huang merged 18 commits intopingcap:v5.0.1_may_pocfrom
JaySon-Huang:str_to_date_pushdown_hotfix

Conversation

@JaySon-Huang
Copy link
Contributor

@JaySon-Huang JaySon-Huang commented May 22, 2021

A cherry-pick to POC branch for #1961


Signed-off-by: JaySon-Huang jayson.hjs@gmail.com

What problem does this PR solve?

Issue Number: #1942

Problem Summary:

What is changed and how it works?

Proposal: xxx

What's Changed:

Related changes

  • PR to update pingcap/docs/pingcap/docs-cn:
  • Need to cherry-pick to the release branch:

Check List

Tests

  • Unit test

Side effects

Release note

  • Support str_to_date push down

Signed-off-by: JaySon-Huang <jayson.hjs@gmail.com>
@JaySon-Huang JaySon-Huang self-assigned this May 22, 2021
Copy link
Contributor Author

@JaySon-Huang JaySon-Huang left a comment

Choose a reason for hiding this comment

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

Four test cases not passed.
All passed now.

Signed-off-by: JaySon-Huang <jayson.hjs@gmail.com>
Signed-off-by: JaySon-Huang <jayson.hjs@gmail.com>
Signed-off-by: JaySon-Huang <jayson.hjs@gmail.com>
Signed-off-by: JaySon-Huang <jayson.hjs@gmail.com>
@JaySon-Huang JaySon-Huang changed the title [WIP] str_to_date function push down str_to_date function push down May 23, 2021
Signed-off-by: JaySon-Huang <jayson.hjs@gmail.com>
@JaySon-Huang
Copy link
Contributor Author

JaySon-Huang commented May 23, 2021

I have found some different behavior of str_to_date under some inputs between MariaDB 10.3.14 and TiDB 5.0.0

'%b' should be case insensitive

> -- 10.3.14-MariaDB %b should be case insensitive
> select str_to_date('31/may/2016 12:34:56.1234', "%d/%b/%Y %H:%i:%S.%f")
+------------------------------------------------------------------+
| str_to_date('31/may/2016 12:34:56.1234', "%d/%b/%Y %H:%i:%S.%f") |
+------------------------------------------------------------------+
| 2016-05-31 12:34:56.123400                                       |
+------------------------------------------------------------------+
> -- tidb 5.0.0 %b should be case insensitive, but tidb not support
> select str_to_date('31/may/2016 12:34:56.1234', "%d/%b/%Y %H:%i:%S.%f")
+------------------------------------------------------------------+
| str_to_date('31/may/2016 12:34:56.1234', "%d/%b/%Y %H:%i:%S.%f") |
+------------------------------------------------------------------+
| <null>                                                           |
+------------------------------------------------------------------+

'%M' should be case insensitive

> -- 10.3.14-MariaDB %M should be case insensitive
> select str_to_date("30/april/2016 12:34:56.", "%d/%M/%Y %H:%i:%s.%f")
+----------------------------------------------------------------+
| str_to_date("30/april/2016 12:34:56.", "%d/%M/%Y %H:%i:%s.%f") |
+----------------------------------------------------------------+
| 2016-04-30 12:34:56                                            |
+----------------------------------------------------------------+
> -- tidb 5.0.0 %M should be case insensitive, but tidb not support
> select str_to_date("30/april/2016 12:34:56.", "%d/%M/%Y %H:%i:%s.%f")
+----------------------------------------------------------------+
| str_to_date("30/april/2016 12:34:56.", "%d/%M/%Y %H:%i:%s.%f") |
+----------------------------------------------------------------+
| <null>                                                         |
+----------------------------------------------------------------+

Parsing empty string

> -- 10.3.14-MariaDB empty string, MariaDB return a date
> select str_to_date("   ", " ")
+-------------------------+
| str_to_date("   ", " ") |
+-------------------------+
| 0000-00-00              |
+-------------------------+
> -- tidb 5.0.0 empty string, tidb return a datetime
> select str_to_date("   ", " ")
+-------------------------+
| str_to_date("   ", " ") |
+-------------------------+
| 0000-00-00 00:00:00     |
+-------------------------+

The day that is not exists in real world

> -- 10.3.14-MariaDB A date "Feb 30th"/"April 31th" not exists int real world, can be parsed in Mariadb
> select str_to_date("30/Feb/2016 12:34:56.1234", "%d/%b/%Y %H:%i:%S.%f")
+------------------------------------------------------------------+
| str_to_date("30/Feb/2016 12:34:56.1234", "%d/%b/%Y %H:%i:%S.%f") |
+------------------------------------------------------------------+
| 2016-02-30 12:34:56.123400                                       |
+------------------------------------------------------------------+
> select str_to_date("31/April/2016 12:34:56.", "%d/%M/%Y %H:%i:%s.%f")
+----------------------------------------------------------------+
| str_to_date("31/April/2016 12:34:56.", "%d/%M/%Y %H:%i:%s.%f") |
+----------------------------------------------------------------+
| 2016-04-31 12:34:56.000000                                     |
+----------------------------------------------------------------+
> -- tidb 5.0.0 A date "Feb 30th"/"April 31th" not exists int real world, can not be parsed in tidb
> select str_to_date("30/Feb/2016 12:34:56.1234", "%d/%b/%Y %H:%i:%S.%f")
+------------------------------------------------------------------+
| str_to_date("30/Feb/2016 12:34:56.1234", "%d/%b/%Y %H:%i:%S.%f") |
+------------------------------------------------------------------+
| <null>                                                           |
+------------------------------------------------------------------+
> select str_to_date("31/April/2016 12:34:56.", "%d/%M/%Y %H:%i:%s.%f")
+----------------------------------------------------------------+
| str_to_date("31/April/2016 12:34:56.", "%d/%M/%Y %H:%i:%s.%f") |
+----------------------------------------------------------------+
| <null>                                                         |
+----------------------------------------------------------------+

The "Feb 29th" for leap year

> -- 10.3.14-MariaDB "Feb 29th" for leap year and non leap year can be parsed in Mariadb
> select str_to_date("29/Feb/2020 12:34:56.", "%d/%b/%Y %H:%i:%s.%f")
+--------------------------------------------------------------+
| str_to_date("29/Feb/2020 12:34:56.", "%d/%b/%Y %H:%i:%s.%f") |
+--------------------------------------------------------------+
| 2020-02-29 12:34:56                                          |
+--------------------------------------------------------------+
> select str_to_date("29/Feb/2021 12:34:56.", "%d/%b/%Y %H:%i:%s.%f")
+--------------------------------------------------------------+
| str_to_date("29/Feb/2021 12:34:56.", "%d/%b/%Y %H:%i:%s.%f") |
+--------------------------------------------------------------+
| 2021-02-29 12:34:56.000000                                   |
+--------------------------------------------------------------+
> -- tidb 5.0.0 Only "Feb 29th" of leap year can be parsed, non leap year parse error
> select str_to_date("29/Feb/2020 12:34:56.", "%d/%b/%Y %H:%i:%s.%f")
+--------------------------------------------------------------+
| str_to_date("29/Feb/2020 12:34:56.", "%d/%b/%Y %H:%i:%s.%f") |
+--------------------------------------------------------------+
| 2020-02-29 12:34:56                                          |
+--------------------------------------------------------------+
> select str_to_date("29/Feb/2021 12:34:56.", "%d/%b/%Y %H:%i:%s.%f")
+--------------------------------------------------------------+
| str_to_date("29/Feb/2021 12:34:56.", "%d/%b/%Y %H:%i:%s.%f") |
+--------------------------------------------------------------+
| <null>                                                       |
+--------------------------------------------------------------+

The '%%' pattern (https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_date-format)

> -- %% Both tidb and mariadb can not handle '%%' properly
> -- https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_date-format
> -- 10.3.14-MariaDB
> select str_to_date("01/Feb/2016 % 23:45:54", "%d/%b/%Y %% %H:%i:%S")
+---------------------------------------------------------------+
| str_to_date("01/Feb/2016 % 23:45:54", "%d/%b/%Y %% %H:%i:%S") |
+---------------------------------------------------------------+
| <null>                                                        |
+---------------------------------------------------------------+
> -- tidb 5.0.0
> select str_to_date("01/Feb/2016 % 23:45:54", "%d/%b/%Y %% %H:%i:%S")
+---------------------------------------------------------------+
| str_to_date("01/Feb/2016 % 23:45:54", "%d/%b/%Y %% %H:%i:%S") |
+---------------------------------------------------------------+
| <null>                                                        |
+---------------------------------------------------------------+

TiDB version

> select tidb_version();
+-------------------------------------------------------------------+
| tidb_version()                                                    |
+-------------------------------------------------------------------+
| Release Version: v5.0.0                                           |
| Edition: Community                                                |
| Git Commit Hash: bdac0885cd11bdf571aad9353bfc24e13554b91c         |
| Git Branch: heads/refs/tags/v5.0.0                                |
| UTC Build Time: 2021-04-06 16:36:29                               |
| GoVersion: go1.13                                                 |
| Race Enabled: false                                               |
| TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306 |
| Check Table Before Drop: false                                    |
+-------------------------------------------------------------------+

@JaySon-Huang JaySon-Huang added the CHERRY-PICK cherry pick label May 23, 2021
@JaySon-Huang JaySon-Huang changed the title str_to_date function push down str_to_date function push down (for poc) May 23, 2021
Signed-off-by: JaySon-Huang <jayson.hjs@gmail.com>
Signed-off-by: JaySon-Huang <jayson.hjs@gmail.com>
Signed-off-by: JaySon-Huang <jayson.hjs@gmail.com>
Signed-off-by: JaySon-Huang <jayson.hjs@gmail.com>
Signed-off-by: JaySon-Huang <jayson.hjs@gmail.com>
Signed-off-by: JaySon-Huang <jayson.hjs@gmail.com>
Signed-off-by: JaySon-Huang <jayson.hjs@gmail.com>
Signed-off-by: JaySon-Huang <jayson.hjs@gmail.com>
Signed-off-by: JaySon-Huang <jayson.hjs@gmail.com>
Signed-off-by: JaySon-Huang <jayson.hjs@gmail.com>
Copy link
Contributor

@zanmato1984 zanmato1984 left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-srebot ti-srebot added the status/LGT1 Indicates that a PR has LGTM 1. label May 23, 2021
@JaySon-Huang JaySon-Huang merged commit 6240d74 into pingcap:v5.0.1_may_poc May 23, 2021
@JaySon-Huang JaySon-Huang deleted the str_to_date_pushdown_hotfix branch May 23, 2021 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CHERRY-PICK cherry pick status/LGT1 Indicates that a PR has LGTM 1.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants