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 Date32/Date64 minus Interval #3962

Closed
Tracked by #3958
alamb opened this issue Mar 27, 2023 · 3 comments · Fixed by #3974
Closed
Tracked by #3958

Support Date32/Date64 minus Interval #3962

alamb opened this issue Mar 27, 2023 · 3 comments · Fixed by #3974
Labels
arrow Changes to the arrow crate enhancement Any new improvement worthy of a entry in the changelog good first issue Good for newcomers

Comments

@alamb
Copy link
Contributor

alamb commented Mar 27, 2023

Is your feature request related to a problem or challenge? Please describe what you are trying to do.
One may like to find out "2 days ago" by computing a date - Interval.

while adding Date to intervals is supported, subtracting is not

Describe the solution you'd like
I would like subtract_dyn not to panic:

fn add_interval_date() {
    let arr = Arc::new(Date32Array::from(vec![
        1_000_000,
    ])) as ArrayRef;

    // Would like to add and subtract intervals:

    // would like to add and substract 1 day
    let interval_array = Arc::new(IntervalDayTimeArray::from(vec![
        Some(IntervalDayTimeType::make_value(0, 1)),
    ])) as ArrayRef;

    // input:
    // +------------+
    // | input      |
    // +------------+
    // | 4707-11-29 |
    // +------------+
    println!(
        "input:\n{}",
        pretty_format_columns("input", &[arr.clone()]).unwrap()
    );

    // interval:
    // +-------------------------------------------------+
    // | interval                                        |
    // +-------------------------------------------------+
    // | 0 years 0 mons 0 days 0 hours 0 mins 0.001 secs |
    // +-------------------------------------------------+
    println!(
        "interval:\n{}",
        pretty_format_columns("interval", &[interval_array.clone()]).unwrap()
    );


    // add:
    // +------------+
    // | out        |
    // +------------+
    // | 4707-11-29 |
    // +------------+
    let new_arr = add_dyn(&arr, interval_array.as_ref()).unwrap();
    println!(
        "add:\n{}",
        pretty_format_columns("out", &[new_arr]).unwrap()
    );

    // panics"
    // thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: CastError("Unsupported data type Date32, Interval(DayTime)")', src/main.rs:154:63
    let new_arr = subtract_dyn(&arr, interval_array.as_ref()).unwrap();
    println!(
        "sub:\n{}",
        pretty_format_columns("out", &[new_arr]).unwrap()
    );
}

Describe alternatives you've considered

Additional context

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

alamb commented Mar 27, 2023

I think this is a good first issue because the semantics are well defined and there are some existing examples

@alamb alamb added the good first issue Good for newcomers label Mar 27, 2023
@SinanGncgl
Copy link
Contributor

Hi, I would like to take this if it is okay for you? Thank you.

@SinanGncgl
Copy link
Contributor

I linked a pr so that you can review and I can fix if you want any changes, thank you!

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 good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants