Skip to content

Commit b2fd2d3

Browse files
authored
bench: add to_char_array_date32 (#22007)
## Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123. --> - Closes #. ## Rationale for this change <!-- Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed. Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes. --> ## What changes are included in this PR? <!-- There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR. --> Benchmark for #21948 ## Are these changes tested? <!-- We typically require tests for all PRs in order to: 1. Prevent the code from being accidentally broken by subsequent changes 2. Serve as another way to document the expected behavior of the code If tests are not included in your PR, please explain why (for example, are they covered by existing tests)? --> ## Are there any user-facing changes? <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. --> <!-- If there are any breaking changes to public APIs, please add the `api change` label. -->
1 parent 1601ba3 commit b2fd2d3

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

datafusion/functions/benches/to_char.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,66 @@ fn criterion_benchmark(c: &mut Criterion) {
278278
)
279279
})
280280
});
281+
282+
// These bellow 02 benchmarks use Date32 data with format strings that contain
283+
// time specifiers (%H, %M, %S, ...). Arrow's Date32 formatter cannot
284+
// handle time specifiers and falls back to a Date64 cast.
285+
286+
// Covers full fallback (every row triggers the cast)
287+
c.bench_function("to_char_array_date32_datetime_patterns_1000", |b| {
288+
let mut rng = rand::rng();
289+
let data_arr = generate_date32_array(&mut rng);
290+
let batch_len = data_arr.len();
291+
let data = ColumnarValue::Array(Arc::new(data_arr) as ArrayRef);
292+
let patterns = ColumnarValue::Array(Arc::new(generate_datetime_pattern_array(
293+
&mut rng,
294+
)) as ArrayRef);
295+
296+
b.iter(|| {
297+
black_box(
298+
to_char()
299+
.invoke_with_args(ScalarFunctionArgs {
300+
args: vec![data.clone(), patterns.clone()],
301+
arg_fields: vec![
302+
Field::new("a", data.data_type(), true).into(),
303+
Field::new("b", patterns.data_type(), true).into(),
304+
],
305+
number_rows: batch_len,
306+
return_field: Field::new("f", DataType::Utf8, true).into(),
307+
config_options: Arc::clone(&config_options),
308+
})
309+
.expect("to_char should work on valid values"),
310+
)
311+
})
312+
});
313+
314+
// Covers partial fallback (roughly half the rows trigger it)
315+
c.bench_function("to_char_array_date32_mixed_patterns_1000", |b| {
316+
let mut rng = rand::rng();
317+
let data_arr = generate_date32_array(&mut rng);
318+
let batch_len = data_arr.len();
319+
let data = ColumnarValue::Array(Arc::new(data_arr) as ArrayRef);
320+
let patterns = ColumnarValue::Array(Arc::new(generate_mixed_pattern_array(
321+
&mut rng,
322+
)) as ArrayRef);
323+
324+
b.iter(|| {
325+
black_box(
326+
to_char()
327+
.invoke_with_args(ScalarFunctionArgs {
328+
args: vec![data.clone(), patterns.clone()],
329+
arg_fields: vec![
330+
Field::new("a", data.data_type(), true).into(),
331+
Field::new("b", patterns.data_type(), true).into(),
332+
],
333+
number_rows: batch_len,
334+
return_field: Field::new("f", DataType::Utf8, true).into(),
335+
config_options: Arc::clone(&config_options),
336+
})
337+
.expect("to_char should work on valid values"),
338+
)
339+
})
340+
});
281341
}
282342

283343
criterion_group!(benches, criterion_benchmark);

0 commit comments

Comments
 (0)