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

Support cross-timezone timestamp comparison via coercsion #11711

Merged
merged 6 commits into from
Jul 31, 2024

Conversation

jeffreyssmith2nd
Copy link
Contributor

@jeffreyssmith2nd jeffreyssmith2nd commented Jul 29, 2024

Which issue does this PR close?

Closes #11653

This PR closes the above issue, but also slightly relaxes the rules further. It also enables the UNION function to handle different timezones, where it coerces to whatever timezone is on the left side. It does not change the rules around arithmetic on times with timezones.

Rationale for this change

What changes are included in this PR?

Are these changes tested?

Are there any user-facing changes?

@github-actions github-actions bot added logical-expr Logical plan and expressions optimizer Optimizer rules sqllogictest SQL Logic Tests (.slt) and removed optimizer Optimizer rules labels Jul 29, 2024
@jeffreyssmith2nd jeffreyssmith2nd marked this pull request as ready for review July 29, 2024 18:00
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thank you @jeffreyssmith2nd -- this looks pretty good to me. I had one question about the intent of coercing with UTC that I think should probably be addressed before merge, but otherwise this looks good to me.

Thank you

datafusion/expr/src/type_coercion/binary.rs Show resolved Hide resolved
datafusion/expr/src/type_coercion/binary.rs Outdated Show resolved Hide resolved
datafusion/expr/src/type_coercion/binary.rs Show resolved Hide resolved
datafusion/expr/src/type_coercion/binary.rs Show resolved Hide resolved
datafusion/expr/src/type_coercion/binary.rs Show resolved Hide resolved
@alamb alamb changed the title Ease restrictions on cross-timezone interaction Ease restrictions on cross-timezone comparison Jul 29, 2024
@alamb alamb changed the title Ease restrictions on cross-timezone comparison Support cross-timezone timestamp comparison via coercsion Jul 30, 2024
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thanks @jeffreyssmith2nd -- this looks great to me 🙏

I'll plan to merge it tomorrow unless anyone else would like time to comment or review

@alamb alamb merged commit ae2ca6a into apache:main Jul 31, 2024
25 checks passed
@alamb
Copy link
Contributor

alamb commented Jul 31, 2024

Thanks again @jeffreyssmith2nd

///
/// An example of this is binary comparisons (<, >, ==, etc). Arrow stores timestamps
/// as relative to UTC epoch, and then adds the timezone as an offset. As a result, we can always
/// do a binary comparison between the two times.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is only true as long as the timezone is present. If tz is None, then the timestamp is not necessarily relative to UTC epoch (but an "arbitrary" epoch).

FWIW, I think the changes you've done here make sense (*) - I'm just not sure if the original behavior of coercing a (None, Some(tz)) or a (Some(tz), None) are correct. Or well, I'm pretty sure it's not guaranteed to be correct, but maybe it's convenient enough to exist 🤷

(*): though is there need for the "strict" check to exist? I'd assume coercing two timestamps with timezones would always be fine, given they are always UTC-epoch based.

Copy link
Contributor

Choose a reason for hiding this comment

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

Or well, I'm pretty sure it's not guaranteed to be correct, but maybe it's convenient enough to exist 🤷

I think it at least has guaranteed semantics 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
logical-expr Logical plan and expressions sqllogictest SQL Logic Tests (.slt)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow comparison of Timestamps with different Timezones
3 participants