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: Added support to cast string without time #3494

Merged
merged 2 commits into from
Jan 9, 2023
Merged

Conversation

gaelwjl
Copy link
Contributor

@gaelwjl gaelwjl commented Jan 8, 2023

Which issue does this PR close?

Closes #3492

Rationale for this change

Support cast string like 2022-01-08

What changes are included in this PR?

arrow-rs/arrow-cast/src/parse.rs

Are there any user-facing changes?

No

@github-actions github-actions bot added the arrow Changes to the arrow crate label Jan 8, 2023
@gaelwjl gaelwjl changed the title Dev Fix: Added support to cast string without time Jan 8, 2023
arrow-cast/src/parse.rs Outdated Show resolved Hide resolved
Copy link
Member

@viirya viirya 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.

It would be better if you can add this into accepted input format of the doc of string_to_timestamp_nanos.

@gaelwjl gaelwjl force-pushed the dev branch 2 times, most recently from 3d413c4 to ff7a32a Compare January 9, 2023 08:49
@gaelwjl gaelwjl requested a review from viirya January 9, 2023 08:51
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 @csphile and @viirya

Would it be possible to also update the doc comment's "Examples of accepted inputs" to include this as well?

https://github.com/apache/arrow-rs/pull/3494/files#diff-cd568dd408cf11db340aa0259545de48fca7a0c0ac680bb9ff9a34956bab52b1R33-R39

@alamb
Copy link
Contributor

alamb commented Jan 9, 2023

🤔 there appears to be a test failure: https://github.com/apache/arrow-rs/actions/runs/3872149018/jobs/6603268102


---- parse::tests::string_to_timestamp_no_timezone stdout ----
Error parsing timestamp '2020-09-08': CastError("Error parsing '2020-09-08' as timestamp")
thread 'parse::tests::string_to_timestamp_no_timezone' panicked at 'called `Result::unwrap()` on an `Err` value: CastError("Error parsing '2020-09-08' as timestamp")', arrow-cast/src/parse.rs:514:43

@gaelwjl
Copy link
Contributor Author

gaelwjl commented Jan 9, 2023

Fixed, I think adding "00:00:00" is necessary since NaiveDateTime::parse_from_str cannot accept %Y-%m-%d

Comment on lines 126 to 127
if let Ok(ts) =
NaiveDateTime::parse_from_str(&format!("{} 00:00:00", s), "%Y-%m-%d %H:%M:%S")
Copy link
Contributor

Choose a reason for hiding this comment

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

this allocates a new string which might take some serious time -- perhaps it would be possible to parse using NaiveDate and then convert the NaiveDate to a NaiveDateTime ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review. PTAL

@gaelwjl gaelwjl force-pushed the dev branch 3 times, most recently from d919414 to f6807e8 Compare January 9, 2023 14:12
arrow-cast/src/parse.rs Outdated Show resolved Hide resolved
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.

Awesome -- thank you so much @csphile and @viirya

// without a timezone specifier as a local time, only date
// Example: 2020-09-08
if let Ok(dt) = NaiveDate::parse_from_str(s, "%Y-%m-%d") {
if let Some(ts) = dt.and_hms_opt(0, 0, 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@alamb alamb merged commit fb36dd9 into apache:master Jan 9, 2023
@ursabot
Copy link

ursabot commented Jan 9, 2023

Benchmark runs are scheduled for baseline = 592d7a3 and contender = fb36dd9. fb36dd9 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.

Support casting strings like '2001-01-01' to timestamp
4 participants