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

feat(query): support timezone #4878

Merged
merged 17 commits into from
May 7, 2022
Merged

Conversation

Veeupup
Copy link
Contributor

@Veeupup Veeupup commented Apr 15, 2022

I hereby agree to the terms of the CLA available at: https://databend.rs/dev/policies/cla/

Summary

this is part of #4651 , make databend work with timezone.

And now, we only store UTC timestamp in microseconds in databend, and then we will display with timezone.
and all functions with timestamp will be the corresponding logic with timezone.
such as in UTC, timestamp is 2022-04-30 22:00:00 and then in Asia/Shanghai, it should be 2022-05-01 06:00:00. and when we call tostartofmonth, the first will output 2022-04-01 and the latter will be 2022-05-01. Others will be the same logic.

  • serialization with timezone
  • deserialization with timezone
  • display with timezone
    • mysql
  • datetime function
    • number function
    • round function
    • week function
    • cast function
    • interval function
  • stateless test with timezone

Changelog

  • New Feature

Related Issues

Fixes #4651

@vercel
Copy link

vercel bot commented Apr 15, 2022

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/databend/databend/2SUHukz1A4kVtMP3ekGi4SPvEBnA
✅ Preview: Ignored

@mergify
Copy link
Contributor

mergify bot commented Apr 15, 2022

@vercel[bot] is not allowed to run commands

@mergify
Copy link
Contributor

mergify bot commented Apr 15, 2022

Thanks for the contribution!
I have applied any labels matching special text in your PR Changelog.

Please review the labels and make any necessary changes.

@mergify mergify bot added the pr-feature this PR introduces a new feature to the codebase label Apr 15, 2022
@Veeupup Veeupup force-pushed the output_with_timezone branch from 73a041c to 05ffd05 Compare April 18, 2022 03:52
@vercel
Copy link

vercel bot commented Apr 18, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Updated
databend ⬜️ Ignored (Inspect) May 7, 2022 at 8:41AM (UTC)

Veeupup added 3 commits May 2, 2022 20:58
Signed-off-by: Veeupup <code@tanweime.com>
Signed-off-by: Veeupup <code@tanweime.com>
Signed-off-by: Veeupup <code@tanweime.com>
@Veeupup Veeupup force-pushed the output_with_timezone branch from 05ffd05 to 47c25eb Compare May 5, 2022 03:33
Veeupup added 4 commits May 5, 2022 12:37
Signed-off-by: Veeupup <code@tanweime.com>
Signed-off-by: Veeupup <code@tanweime.com>
Signed-off-by: Veeupup <code@tanweime.com>
Signed-off-by: Veeupup <code@tanweime.com>
@Veeupup Veeupup changed the title feat: make output with timezone rightly feat(query): support timezone May 5, 2022
Signed-off-by: Veeupup <code@tanweime.com>
@Veeupup
Copy link
Contributor Author

Veeupup commented May 6, 2022

@sundy-li @b41sh there are many details to deal with, so comments are welcome if u can help me to check it

common/io/src/format_settings.rs Outdated Show resolved Hide resolved
@@ -66,23 +69,27 @@ pub fn cast_column_field(
column_with_field: &ColumnWithField,
from_type: &DataTypeImpl,
target_type: &DataTypeImpl,
func_ctx: &FunctionContext,
Copy link
Member

Choose a reason for hiding this comment

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

How about putting func_ctx as the first argument?

Copy link
Member

Choose a reason for hiding this comment

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

We can do this little refactor in another PR

Veeupup added 6 commits May 6, 2022 15:39
Signed-off-by: Veeupup <code@tanweime.com>
Signed-off-by: Veeupup <code@tanweime.com>
Signed-off-by: Veeupup <code@tanweime.com>
Signed-off-by: Veeupup <code@tanweime.com>
@Veeupup Veeupup marked this pull request as ready for review May 6, 2022 10:21
@Veeupup
Copy link
Contributor Author

Veeupup commented May 6, 2022

with lots of codes and logic modified, I suggest maybe u can first check the stateless-test datetime_tz to check the logic of different timezone
tests/suites/0_stateless/02_function/02_0012_function_datetimes_tz.sql
@sundy-li @b41sh

@Veeupup
Copy link
Contributor Author

Veeupup commented May 6, 2022

We need more stateless-test to test corner cases of differents timezone in the future

Signed-off-by: Veeupup <code@tanweime.com>
@BohuTANG BohuTANG removed their request for review May 6, 2022 13:04
Signed-off-by: Veeupup <code@tanweime.com>
Copy link
Member

@BohuTANG BohuTANG left a comment

Choose a reason for hiding this comment

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

💯

@leiysky
Copy link
Contributor

leiysky commented May 7, 2022

I'd like to know if we support DST(Daylight Saving Time) or not?

As soon as timezone is introduced, the implementation of datetime functions(e.g. date add) should take care of DST.

@Veeupup
Copy link
Contributor Author

Veeupup commented May 7, 2022

@leiysky I did not add stateless-test about DST now. We use chrono and chnoro_tz crate to deal with datetime convert between different timezones. And it seems that chrono_tz has done with it : D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need-review pr-feature this PR introduces a new feature to the codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature: Adapt to different countries support user change timezone
7 participants