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: handle mixed offsets and names zones in CONVERT_TZ #28528

Merged
merged 4 commits into from
Oct 23, 2021

Conversation

dveeden
Copy link
Contributor

@dveeden dveeden commented Oct 1, 2021

  • Support mixed named timezones and UTC offsets
  • Add support for +14:00
  • Support SYSTEM timezone

What problem does this PR solve?

This fixes the issues as reported in #8311

This fixes mixing named timezones like Europe/Moscow and UTC offsets like +01:00.

It also fixes support for the +14:00 timezone.

Check List

Tests

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

Documentation

  • Affects user behaviors
  • Changes MySQL compatibility

Release note

`CONVERT_TZ()` now supports mixing named timezones and UTC offsets

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Oct 1, 2021

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • kennytm
  • mjonss

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 1, 2021
@mjonss
Copy link
Contributor

mjonss commented Oct 1, 2021

The CI found a broken test:

 builtin_time_test.go:2683:
     c.Assert(result, Equals, test.expect, Commentf("convert_tz(\"%v\", \"%s\", \"%s\")", test.t, test.fromTz, test.toTz))
 ... obtained string = "2004-01-01 12:00:00"
 ... expected string = ""
 ... convert_tz("2004-01-01 12:00:00", "+00:00", "GMT")

So this could probably be fixed and extended for testing this change too.

@dveeden
Copy link
Contributor Author

dveeden commented Oct 1, 2021

/cc @mjonss

@ti-chi-bot ti-chi-bot requested a review from mjonss October 1, 2021 14:01
@dveeden dveeden force-pushed the convert_tz_mixed branch 2 times, most recently from aeb0352 to 8e64c21 Compare October 1, 2021 14:13
Copy link
Contributor

@mjonss mjonss left a comment

Choose a reason for hiding this comment

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

LGTM, if you have time, then I would suggest adding named time zones to the tests as well, like 'Europe/Amsterdam', 'Asia/Shanghai'.

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Oct 1, 2021
@mjonss
Copy link
Contributor

mjonss commented Oct 1, 2021

Hmm, looks like it still has a bug, when adding one test with daylight saving time transition:

builtin_time_test.go:2690:
    c.Assert(result, Equals, test.expect, Commentf("convert_tz(\"%v\", \"%s\", \"%s\")", test.t, test.fromTz, test.toTz))
... obtained string = "2021-10-31 04:00:00"
... expected string = "2021-10-31 02:00:00"
... convert_tz("2021-10-31 02:00:00", "Europe/Amsterdam", "+02:00")

Fixed by adding:

t = t.In(time.UTC)

last in the else branch of fromTzMatched.

@bb7133
Copy link
Member

bb7133 commented Oct 2, 2021

LGTM, please address the comments from @mjonss

@bolt-juri-gavshin
Copy link

I would also recommend adding unit test equivalents of the following SQL clauses, if possible:

SELECT convert_tz('2021-10-31 02:59:59', 'Europe/Amsterdam', '+02:00'); -- return value is the same as input
SELECT convert_tz('2021-10-31 03:00:00', 'Europe/Amsterdam', '+01:00'); -- return value is the same as input

SELECT convert_tz('2021-10-31 02:59:59', '+02:00', 'Europe/Amsterdam'); -- return value is the same as input
SELECT convert_tz('2021-10-31 03:00:00', '+01:00', 'Europe/Amsterdam'); -- return value is the same as input

expression/builtin_time.go Outdated Show resolved Hide resolved
@dveeden dveeden requested a review from kennytm October 12, 2021 05:32
Copy link
Contributor

@kennytm kennytm left a comment

Choose a reason for hiding this comment

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

LGTM, but I'd prefer the more uniform approach using time.FixedZone, so that a the conversion code itself always work on two *time.Locations, and doesn't need many if conditions.

@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Oct 14, 2021
- Support mixed named timezones and UTC offsets
- Add support for +14:00

Co-authored-by: kennytm <[email protected]>
@dveeden
Copy link
Contributor Author

dveeden commented Oct 22, 2021

/assign @kennytm

@dveeden
Copy link
Contributor Author

dveeden commented Oct 22, 2021

[2021-10-22T12:39:20.570Z] FAIL: builtin_time_test.go:2636: testEvaluatorSuite.TestConvertTz
[2021-10-22T12:39:20.570Z] 
[2021-10-22T12:39:20.570Z] builtin_time_test.go:2706:
[2021-10-22T12:39:20.570Z]     c.Assert(result, Equals, test.expect, Commentf("convert_tz(\"%v\", \"%s\", \"%s\")", test.t, test.fromTz, test.toTz))
[2021-10-22T12:39:20.570Z] ... obtained string = "2021-10-22 15:00:00"
[2021-10-22T12:39:20.570Z] ... expected string = "2021-10-22 03:00:00"
[2021-10-22T12:39:20.570Z] ... convert_tz("2021-10-22 10:00:00", "Europe/Tallinn", "SYSTEM")
 MySQL  127.0.0.1:4000 ssl  test  SQL > SELECT CONVERT_TZ("2021-10-22 10:00:00", "Europe/Tallinn", "Asia/Shanghai");
+----------------------------------------------------------------------+
| CONVERT_TZ("2021-10-22 10:00:00", "Europe/Tallinn", "Asia/Shanghai") |
+----------------------------------------------------------------------+
| 2021-10-22 15:00:00                                                  |
+----------------------------------------------------------------------+
1 row in set (0.0017 sec)
$ TZ=Asia/Shanghai date --date="TZ=\"Europe/Tallinn\" 2021-10-22 10:00:00" 
Fri 22 Oct 15:00:00 CST 2021

So looks like the expected string is wrong somehow.

@kennytm
Copy link
Contributor

kennytm commented Oct 23, 2021

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: a2107ee

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Oct 23, 2021
@ti-chi-bot ti-chi-bot merged commit 465d2e7 into pingcap:master Oct 23, 2021
@dveeden
Copy link
Contributor Author

dveeden commented Nov 1, 2021

/label needs-cherry-pick-5.2

ti-srebot pushed a commit to ti-srebot/tidb that referenced this pull request Nov 1, 2021
@ti-srebot
Copy link
Contributor

cherry pick to release-5.2 in PR #29311

@guo-shaoge guo-shaoge added the needs-cherry-pick-release-5.3 Type: Need cherry pick to release-5.3 label Feb 21, 2022
ti-srebot pushed a commit to ti-srebot/tidb that referenced this pull request Feb 21, 2022
@ti-srebot
Copy link
Contributor

cherry pick to release-5.3 in PR #32501

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-cherry-pick-release-5.2 needs-cherry-pick-release-5.3 Type: Need cherry pick to release-5.3 release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants