Skip to content

Support cast <> String to interval #3643

Closed

Description

@alamb

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.

Activity

  1. alamb commented on Jan 31, 2023

    @alamb
    ContributorAuthor

    Related PR in datafusion: apache/datafusion#5117

  2. doki23 commented on Feb 23, 2023

    @doki23
    Contributor

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

  3. alamb commented on Feb 23, 2023

    @alamb
    ContributorAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    arrowChanges to the arrow crateenhancementNew feature/addition

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions