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

Add timezone abstraction #2909

Merged
merged 4 commits into from Oct 24, 2022
Merged

Conversation

tustvold
Copy link
Contributor

Which issue does this PR close?

Part of #2594
Part of #599
Part of #1380

Rationale for this change

The existing logic was very tricky to understand, as it relied on applying offsets to NaiveDateTime. This is very easy to accidental mess up, adding instead of subtracting, forgetting to apply it, etc...

It also was complicating splitting up the crates, as the logic was split across multiple locations

What changes are included in this PR?

Uses the chrono timezone plumbing to provide type safe timezone APIs

Are there any user-facing changes?

No

@@ -1470,23 +1470,6 @@ mod tests {
assert_eq!(array1, array2);
}

#[cfg(feature = "chrono-tz")]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test is moved to timezone.rs with some tweaks


#[cfg(feature = "chrono-tz")]
#[test]
fn test_using_chrono_tz_and_utc_naive_date_time() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test is moved to timezone.rs

@github-actions github-actions bot added the arrow Changes to the arrow crate label Oct 21, 2022

/// Parses a fixed offset of the form "+09:00"
fn parse_fixed_offset(tz: &str) -> Result<FixedOffset, ArrowError> {
if tz.len() != 6 {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure why we are so strict on this, +0900 is a valid timezone, but there was an explicit test for this so 🤷

Copy link
Contributor

Choose a reason for hiding this comment

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

i think we could submit another pr to extend this to support more fixedoffset formats. chrono supports these:
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, there was just an explicit test that +0930 was not accepted, which made me think the lack of support was intentional

Copy link
Contributor

Choose a reason for hiding this comment

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

just submitted a ticket, i can implement this after the pr merged

Comment on lines +191 to +199
/// Converts an [`ArrowPrimitiveType`] to [`DateTime<Tz>`]
pub fn as_datetime_with_timezone<T: ArrowPrimitiveType>(
v: i64,
tz: Tz,
) -> Option<DateTime<Tz>> {
let naive = as_datetime::<T>(v)?;
Some(Utc.from_utc_datetime(&naive).with_timezone(&tz))
}

Copy link
Contributor

Choose a reason for hiding this comment

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

this could enable displaying Timestamp with timezone 👍

@waitingkuo
Copy link
Contributor

looks great to me, thank you @tustvold

@waitingkuo
Copy link
Contributor

waitingkuo commented Oct 24, 2022

the return data types for timestamp_[sometimeunit]_to_datetime are changed to Option<NaiveDatetime> in #2894

https://github.com/apache/arrow-rs/pull/2909/files#diff-fe32c157c2dda897288cc93386e455e6a0bdc0c63ce14776053a894ca61665ebR100-R142

i've tried to rebase this branch from master and it worked well

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.

Looks like a nice change to me

// specific language governing permissions and limitations
// under the License.

//! Timezone for timestamp arrays
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is worth documenting somewhere what enabling the chrono-tz feature of arrow does (and what the expected behavior differences are when it is / isn't present)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It isn't a new feature and is already documented

@@ -49,6 +49,7 @@ arrow-buffer = { version = "25.0.0", path = "../arrow-buffer" }
arrow-schema = { version = "25.0.0", path = "../arrow-schema" }
arrow-data = { version = "25.0.0", path = "../arrow-data" }
chrono = { version = "0.4", default-features = false, features = ["clock"] }
chrono-tz = { version = "0.7", optional = true }
Copy link
Contributor

Choose a reason for hiding this comment

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

I verified we added an equivalent feature to arrow/Cargo.toml so people can activate this feature from arrow

@tustvold tustvold merged commit d9fd1d5 into apache:master Oct 24, 2022
@ursabot
Copy link

ursabot commented Oct 25, 2022

Benchmark runs are scheduled for baseline = 7e5d4a1 and contender = d9fd1d5. d9fd1d5 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on ec2-t3-xlarge-us-east-2] ec2-t3-xlarge-us-east-2
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on test-mac-arm] test-mac-arm
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on ursa-i9-9960x] ursa-i9-9960x
[Skipped ⚠️ Benchmarking of arrow-rs-commits is not supported on ursa-thinkcentre-m75q] ursa-thinkcentre-m75q
Buildkite builds:
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java

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.

None yet

4 participants