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

Feature: function about convert_timezone #16177

Closed
TCeason opened this issue Aug 2, 2024 · 6 comments · Fixed by #16181
Closed

Feature: function about convert_timezone #16177

TCeason opened this issue Aug 2, 2024 · 6 comments · Fixed by #16181
Assignees
Labels
C-feature Category: feature good first issue Category: good first issue

Comments

@TCeason
Copy link
Collaborator

TCeason commented Aug 2, 2024

Summary

Now Databend support to_timestamp can convert string to current timezone with setting timezone.

And convert_timezone is support to convert given time to target timezone.

ref: https://docs.snowflake.com/en/sql-reference/functions/convert_timezone

convert_timezone('target_timezone', 'timestamp');
@TCeason TCeason added C-feature Category: feature good first issue Category: good first issue labels Aug 2, 2024
@florann
Copy link
Contributor

florann commented Aug 3, 2024

Hey,
I would like to work on this issue.
Can you please assign it to me ?

florann added a commit to florann/databend that referenced this issue Aug 4, 2024
@florann
Copy link
Contributor

florann commented Aug 4, 2024

Hello,
My pull request is ready with all check done and just waiting for a review.
Tanks.

@TCeason
Copy link
Collaborator Author

TCeason commented Aug 4, 2024

Hello,

My pull request is ready with all check done and just waiting for a review.

Tanks.

Need test :) you can add it in datetime_tz.test in suite dir

@florann
Copy link
Contributor

florann commented Aug 4, 2024

I think something is wrong with this new method "convert_timezone".
I tried different tests and every of them ends "this function does not exist" :/

@TCeason
Copy link
Collaborator Author

TCeason commented Aug 4, 2024

I think something is wrong with this new method "convert_timezone". I tried different tests and every of them ends "this function does not exist" :/

You can read this doc first: https://docs.databend.com/guides/community/contributor/how-to-write-scalar-functions

And then can ref function: "to_timestamp": https://github.com/datafuselabs/databend/blob/4b2e844c728f9f4875ce3f61458e7a7d1c6554f4/src/query/functions/src/scalars/datetime.rs#L146

Now ctx.func_ctx.tz.tz is a user setting timezone.

In convert_timezone, we should :

  1. cast the string to timestamp
  2. convert the timestamp with target timezone.

After impl the function, add test in https://github.com/datafuselabs/databend/blob/4cd1de74fa42a31bb61d0d7d46b7c108a11471ac/tests/sqllogictests/suites/query/functions/02_0012_function_datetimes_tz.test#L658

@TCeason
Copy link
Collaborator Author

TCeason commented Nov 5, 2024

convert_timezone with three args is hard to impl now. Because now databend only store timestamp in storage.

github-merge-queue bot pushed a commit that referenced this issue Nov 5, 2024
* Feature: function about convert_timezone #16177

* Correction trait type

* Formatting the function

* Solving compiling issue

* Correcting file format

* adding tests

* Correction unti test

* Correction unit tests 2

* Correction unit tests 3

* Correction unit tests 4

* Correction unit tests 5

* Correction unit tests 6

* Correction unit tests 6

* Implementation of convert_timezone

* Correction registry and error handling

* Correction eval function

* Correction eval function 2

* Correction eval function 3

* Correction eval function 4

* Correction eval function 5

* Correction eval function 6

* Correction eval function 7

* Correction eval function 8

* Correction eval function 9

* Correction eval function 11

* Correction eval function 12

* Correction eval function 13 + add of the 3 arguments function version

* Code formatting

* Correction third parameter convert_timezone()

* Correction type

* Correction 1

* Correction 2

* Adding unit test

* Adding unit test 2

* Correciton unit test 4

* Correciton unit test 5

* Correciton unit test 6

* Correciton unit test 7

* Correction unit test 8

* Correction checked expr

* Correction convert_timezone

* Correction convert_timezone 2

* Correction convert_timezone 3

* Correction convert_timezone 4

* Correction convert_timezone 5

* Correction convert_timezone 6

* Correction convert_timezone 7

* Correction convert_timezone 8

* Correction convert_timezone 9

* Correction convert_timezone 10

* Correction convert_timezone 11

* Correction convert_timezone 12

* Correction convert_timezone 12

* Correction convert_timezone 13

* Unit test

* Unit test 2

* Unit test 3

* Unit test 4

* Unit test 5

* Unit test 6

* Unit test 7

* feat: convert_timezone(target_timezone, ts)

* add some check

* if error output push default

---------

Co-authored-by: TCeason <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature Category: feature good first issue Category: good first issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants