Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions native/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions native/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ bytes = { version = "1.11.1" }
parquet = { version = "59.2.0", default-features = false, features = ["experimental"] }
datafusion = { version = "55.1.0", default-features = false, features = ["unicode_expressions", "crypto_expressions", "nested_expressions", "parquet"] }
datafusion-datasource = { version = "55.1.0" }
datafusion-functions = { version = "55.1.0", default-features = false, features = ["datetime_expressions"] }
datafusion-physical-expr-adapter = { version = "55.1.0" }
datafusion-spark = { version = "55.1.0", features = ["core"] }
datafusion-comet-spark-expr = { path = "spark-expr" }
Expand Down
1 change: 1 addition & 0 deletions native/spark-expr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ edition = { workspace = true }
arrow = { workspace = true }
chrono = { workspace = true }
datafusion = { workspace = true }
datafusion-functions = { workspace = true }
datafusion-spark = { workspace = true }
num = { workspace = true }
regex = { workspace = true }
Expand Down
36 changes: 31 additions & 5 deletions native/spark-expr/benches/date_trunc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,57 @@
use arrow::array::{ArrayRef, Date32Array};
use criterion::{criterion_group, criterion_main, Criterion};
use datafusion_comet_spark_expr::date_trunc_dyn;
use std::sync::Arc;
use std::{hint::black_box, sync::Arc};

fn criterion_benchmark(c: &mut Criterion) {
let date_array = create_date_array();
let modern_dates: ArrayRef = Arc::new(create_modern_date_array());
let mixed_range_null_dates: ArrayRef = Arc::new(create_mixed_range_null_date_array());

let mut group = c.benchmark_group("date_trunc");

// Benchmark each truncation format
for format in ["YEAR", "QUARTER", "MONTH", "WEEK"] {
let array_ref: ArrayRef = Arc::new(date_array.clone());
group.bench_function(format!("date_trunc_{}", format.to_lowercase()), |b| {
b.iter(|| date_trunc_dyn(&array_ref, format.to_string()).unwrap());
b.iter(|| {
black_box(date_trunc_dyn(black_box(&modern_dates), format.to_string()).unwrap())
});
});
group.bench_function(
format!("date_trunc_{}_mixed_range_null", format.to_lowercase()),
|b| {
b.iter(|| {
black_box(
date_trunc_dyn(black_box(&mixed_range_null_dates), format.to_string())
.unwrap(),
)
});
},
);
}

group.finish();
}

fn create_date_array() -> Date32Array {
fn create_modern_date_array() -> Date32Array {
// Create 10000 dates spanning several years (more realistic workload)
// Days since Unix epoch: range from 0 (1970-01-01) to ~19000 (2022)
let dates: Vec<i32> = (0..10000).map(|i| (i * 2) % 19000).collect();
Date32Array::from(dates)
}

fn create_mixed_range_null_date_array() -> Date32Array {
// Mix ordinary modern dates with dates around year 3333, which are outside
// DataFusion's TimestampNanosecond range, and nulls.
let dates: Vec<Option<i32>> = (0..10000)
.map(|i| match i % 10 {
0 | 1 => None,
2 | 3 => Some(497_826 + (i * 17) % 365),
_ => Some((i * 2) % 19000),
})
.collect();
Date32Array::from(dates)
}

fn config() -> Criterion {
Criterion::default()
}
Expand Down
Loading