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 cast <> String to interval #3643

Closed
alamb opened this issue Jan 31, 2023 · 3 comments · Fixed by #3762
Closed

Support cast <> String to interval #3643

alamb opened this issue Jan 31, 2023 · 3 comments · Fixed by #3762
Labels
arrow Changes to the arrow crate enhancement Any new improvement worthy of a entry in the changelog

Comments

@alamb
Copy link
Contributor

alamb commented Jan 31, 2023

Is your feature request related to a problem or challenge? Please describe what you are trying to do.

In DataFusion, we support SQL syntax like INTERVAL 3 months that is then converted into Intervals (I think originally contributed by @ovr).

However we currently only support converting individual values (rather than arrays)

Describe the solution you'd like
I would like the arrow cast kernel https://docs.rs/arrow-cast/32.0.0/arrow_cast/cast/fn.cast.html to support casting to/from strings and intervals

DataType::Interval(_) <----> DataType::Utf8/DataType::LargeUtf8

There is some subtlety related to parsing intervals (like if a given interval type can fit a specific range and precision)

Describe alternatives you've considered

Additional context
The datafusion parse_interval logic is here: https://github.com/apache/arrow-datafusion/blob/1f7885bb48dd33ce7b9df995214393bbff080e08/datafusion/common/src/parsers.rs#L115-L266

I think it would be fairly straightforward to port (along with tests) to arrow-rs

I don't think arrow should have the logic that tries to auto-detect the type of the interval -- in DataFusion I think we could simply change the code to try parsing the string as different types of intervals and use the one that first succeeds.

@alamb alamb added the enhancement Any new improvement worthy of a entry in the changelog label Jan 31, 2023
@alamb alamb added the arrow Changes to the arrow crate label Jan 31, 2023
@alamb
Copy link
Contributor Author

alamb commented Jan 31, 2023

Related PR in datafusion: apache/datafusion#5117

@doki23
Copy link
Contributor

doki23 commented Feb 23, 2023

I'm interesting in this issue, may I take it?

@alamb
Copy link
Contributor Author

alamb commented Feb 23, 2023

That would be great -- thank you @doki23

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 enhancement Any new improvement worthy of a entry in the changelog
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants