Skip to content

Commit c920a5b

Browse files
committed
bench: add date_part millisecond, microsecond and nanosecond cases for times, intervals, durations and timezones
1 parent 702803d commit c920a5b

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

  • datafusion/functions/benches/datetime_expressions

‎datafusion/functions/benches/datetime_expressions/date_part.rs‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,10 @@ fn criterion_benchmark(c: &mut Criterion) {
244244
let duration_ns_nulls =
245245
Arc::new(generate_duration_nanosecond_array_with_nulls(&mut rng)) as ArrayRef;
246246

247+
let ts_ns_tz =
248+
Arc::new(generate_timestamp_ns_array(&mut rng).with_timezone("America/New_York"))
249+
as ArrayRef;
250+
247251
let udf = date_part();
248252

249253
for part in ["year", "month", "week", "day", "hour", "minute"] {
@@ -365,6 +369,39 @@ fn criterion_benchmark(c: &mut Criterion) {
365369
);
366370
}
367371

372+
// Durations past `i32::MAX` milliseconds or microseconds overflow `Int32`, so
373+
// only `nanosecond` runs on them
374+
for (part, return_type) in [
375+
("millisecond", DataType::Int32),
376+
("microsecond", DataType::Int32),
377+
("nanosecond", DataType::Int64),
378+
] {
379+
let mut arrays = vec![
380+
("ns_tz", &ts_ns_tz),
381+
("time32_ms", &time32_ms),
382+
("time64_ns", &time64_ns),
383+
("interval_dt", &interval_dt),
384+
("interval_mdn", &interval_mdn),
385+
("duration_ns_small", &duration_ns_small),
386+
];
387+
if part == "nanosecond" {
388+
arrays.extend([
389+
("duration_ns", &duration_ns),
390+
("duration_ns_nulls", &duration_ns_nulls),
391+
]);
392+
}
393+
for (name, array) in arrays {
394+
bench_date_part(
395+
c,
396+
&udf,
397+
&format!("date_part_{part}_{name}_1000"),
398+
part,
399+
Arc::clone(array),
400+
return_type.clone(),
401+
);
402+
}
403+
}
404+
368405
for part in ["quarter", "isoyear", "doy", "dow", "isodow"] {
369406
bench_date_part(
370407
c,

0 commit comments

Comments
 (0)