Skip to content

date_part using an interval returns an incorrect result #7182

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

Closed
delamarch3 opened this issue Feb 23, 2025 · 1 comment · Fixed by #7189
Closed

date_part using an interval returns an incorrect result #7182

delamarch3 opened this issue Feb 23, 2025 · 1 comment · Fixed by #7189
Assignees
Labels

Comments

@delamarch3
Copy link
Contributor

Describe the bug

It looks like date_part using an interval will return the whole interval instead of taking out the part.

To Reproduce

use arrow::array::{Int32Array, IntervalMonthDayNanoArray, TimestampSecondArray};
use arrow::compute::{date_part, DatePart};
use arrow::datatypes::IntervalMonthDayNano;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let array = TimestampSecondArray::from(vec![305]); // 5 minutes, 5 seconds
    let result = date_part(&array, DatePart::Second)?
        .as_any()
        .downcast_ref::<Int32Array>()
        .unwrap()
        .iter()
        .collect::<Vec<Option<i32>>>();
    assert_eq!(result, &[Some(5)]); // As expected

    let array = IntervalMonthDayNanoArray::from(vec![
        IntervalMonthDayNano::new(0, 0, 305 * 1_000_000_000), // 0 months, 0 days, 305 seconds
    ]);
    let res: Vec<Option<i32>> = date_part(&array, DatePart::Second)?
        .as_any()
        .downcast_ref::<Int32Array>()
        .unwrap()
        .iter()
        .collect::<Vec<Option<i32>>>();
    assert_eq!(res, &[Some(5)]); // Fails, result is 305

    Ok(())
}

Expected behavior

date_part returns the requested part.

Additional context

apache/datafusion#14817

@delamarch3
Copy link
Contributor Author

take

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant