Skip to content

Optimize date_part Minute by avoiding unnecessary computation #14043

@jayzhan211

Description

@jayzhan211

Is your feature request related to a problem or challenge?

Open an issue to track the status of this optimization

Related
#13449
apache/arrow-rs#6746

Describe the solution you'd like

I guess there are some changes in arrow-rs left to do.

Describe alternatives you've considered

No response

Additional context

impl ExtractDatePartExt for PrimitiveArray<TimestampSecondType> {
    fn date_part(&self, part: DatePart) -> Result<Int32Array, ArrowError> {
        // TimestampSecond only encodes number of seconds, so these will always be 0
        let array =
            if let DatePart::Millisecond | DatePart::Microsecond | DatePart::Nanosecond = part {
                Int32Array::new(vec![0; self.len()].into(), self.nulls().cloned())
            } else if let Some(tz) = get_tz(self.data_type())? {
                let map_func = get_date_time_part_extract_fn(part);
                self.unary_opt(|d| {
                    timestamp_s_to_datetime(d)
                        .map(|c| Utc.from_utc_datetime(&c).with_timezone(&tz))
                        .map(map_func)
                })
            } else {
                let map_func = get_date_time_part_extract_fn(part);
                self.unary_opt(|d| timestamp_s_to_datetime(d).map(map_func))
            };
        Ok(array)
    }
}

If I remember correctly, we need to switch timestamp_s_to_datetime to timestamp_s_to_time and extract the data from Minute

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions