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

Fix incorrect cast Timestamp with Timezone #4201

Merged
merged 8 commits into from
May 12, 2023

Conversation

aprimadi
Copy link
Contributor

@aprimadi aprimadi commented May 11, 2023

Which issue does this PR close?

Closes apache/datafusion#5952.
Closes #1936

Rationale for this change

N/A

What changes are included in this PR?

N/A

Are there any user-facing changes?

No

@github-actions github-actions bot added the arrow Changes to the arrow crate label May 11, 2023
@tustvold
Copy link
Contributor

tustvold commented May 11, 2023

Thank you for this, I'm not sure this logic is correct, however.

If both quantities have timezones, no adjustment should be necessary, as they are already normalized to UTC.

The complexity arises when converting between timestamps where one doesn't have a timezone. This requires some care, especially to handle timezones that don't have fixed offsets.

In the forward direction I think this involves doing something like

let from_tz = from_tz.parse()?;
array.unary_opt(|i| {
    T::make_value(as_datetime_with_timezone(i, from_tz)?.naive_local())
})

And in the reverse direction

let to_tz = to_tz.parse()?;
array.unary_opt(|i| {
    let local = as_datetime(i);
    let offset = to_tz.offset_from_local_datetime(&local).single()?;
    T::make_value(local + offset.fix())
})

Let me know if you get stuck, timezones are wild...

@aprimadi
Copy link
Contributor Author

@tustvold Yes sorry it's not done yet. I have problem compiling in my macbook pro (see Discord). That's why I checked in the code that isn't even compiling yet so I can switch to my Linux machine.

@aprimadi
Copy link
Contributor Author

Thank you for the feedback @tustvold. Very helpful.

@aprimadi aprimadi marked this pull request as ready for review May 11, 2023 17:37
arrow-cast/src/cast.rs Outdated Show resolved Hide resolved
arrow-cast/src/cast.rs Outdated Show resolved Hide resolved
tustvold
tustvold previously approved these changes May 12, 2023
Copy link
Contributor

@tustvold tustvold left a comment

Choose a reason for hiding this comment

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

This is great, really awesome work

arrow-cast/src/cast.rs Show resolved Hide resolved
arrow-cast/src/cast.rs Outdated Show resolved Hide resolved
arrow-cast/src/cast.rs Outdated Show resolved Hide resolved
arrow-cast/src/cast.rs Outdated Show resolved Hide resolved
@tustvold tustvold dismissed their stale review May 12, 2023 12:44

None conversion

Copy link
Contributor

@tustvold tustvold left a comment

Choose a reason for hiding this comment

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

I think we just need to move the tests and this is ready to go, returning UTC time when stripping the timezone is what we currently do, and is consistent with the parsing kernels, so 👍 from me

arrow/tests/array_cast.rs Outdated Show resolved Hide resolved
@tustvold tustvold merged commit d012bb2 into apache:master May 12, 2023
@tustvold
Copy link
Contributor

Thanks again 👍

@aprimadi
Copy link
Contributor Author

Thanks for the quick review @tustvold and very helpful feedback along the way. 🍻

@alamb
Copy link
Contributor

alamb commented Jun 1, 2024

See related discussion #5827

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

Successfully merging this pull request may close these issues.

Incorrect Scalar Timezone Coercion Cast Kernel Ignores Timezone
3 participants