Skip to content

date_part using an interval returns an incorrect result #7182

@delamarch3

Description

@delamarch3

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions