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

Simplify datetime conversion #5006

Merged
merged 3 commits into from
Oct 30, 2023
Merged

Conversation

tustvold
Copy link
Contributor

Which issue does this PR close?

Closes #.

Rationale for this change

Follow up to #4773

What changes are included in this PR?

Are there any user-facing changes?

@tustvold tustvold added the development-process Related to development process of arrow-rs label Oct 30, 2023
@@ -427,13 +427,9 @@ impl Field {
quote! { ::chrono::naive::NaiveDateTime::from_timestamp_millis(vals[i]).unwrap() }
}
Some(ThirdPartyType::ChronoNaiveDate) => {
// NaiveDateTime::UNIX_EPOCH.num_days_from_ce() == 719163
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As this is a proc macro we would need to explicitly declare all the types and the Datelike trait. It seemed simpler to just define it

::chrono::naive::NaiveDate::from_num_days_from_ce_opt(vals[i]
+ ((::chrono::naive::NaiveDate::from_ymd_opt(1970, 1, 1).unwrap()
.signed_duration_since(
::chrono::naive::NaiveDate::from_ymd_opt(0, 12, 31).unwrap()
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 caused me some confusion, but it is because days start counting at 1, not zero 😅

::chrono::naive::NaiveDate::from_ymd_opt(0, 12, 31).unwrap()
)
).num_days()) as i32).unwrap()
::chrono::naive::NaiveDate::from_num_days_from_ce_opt(vals[i] + 719163).unwrap()
Copy link
Contributor

Choose a reason for hiding this comment

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

can this overflow?

Copy link
Contributor Author

@tustvold tustvold Oct 30, 2023

Choose a reason for hiding this comment

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

Technically yes, practically no, unless you're handling dates in the year 11 million 😄

Copy link
Contributor

Choose a reason for hiding this comment

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

so in debug builds (or w/ overflow checks) this panics when reading 3rd-party / untrusted input

Copy link
Contributor Author

@tustvold tustvold Oct 30, 2023

Choose a reason for hiding this comment

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

Correct, the implementation added in #4773 I would describe as an MVP

Copy link
Contributor

Choose a reason for hiding this comment

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

ahhh, this is what it is for, interesting.

Either way, I would be happy if we don't introduce more panicky code paths. IIRC there's checked_add which pretty much solves the issue and the parquet error struct probably has some variant that would be fitting.

@tustvold tustvold merged commit be093cb into apache:master Oct 30, 2023
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
development-process Related to development process of arrow-rs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants