Skip to content

Commit a5631c8

Browse files
committed
chore: update test
1 parent e0eb0fd commit a5631c8

2 files changed

Lines changed: 24 additions & 9 deletions

File tree

datafusion/functions/benches/to_char.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,11 +279,11 @@ fn criterion_benchmark(c: &mut Criterion) {
279279
})
280280
});
281281

282-
// These two benchmarks use Date32 data with format strings that contain
282+
// These bellow 02 benchmarks use Date32 data with format strings that contain
283283
// time specifiers (%H, %M, %S, ...). Arrow's Date32 formatter cannot
284-
// handle time specifiers, so every row falls back to a Date64 cast.
285-
// They specifically target the optimization in commit 7a58a0311 (cast the
286-
// whole array once on first failure instead of slicing per row).
284+
// handle time specifiers and falls back to a Date64 cast.
285+
286+
// Covers full fallback (every row triggers the cast)
287287
c.bench_function("to_char_array_date32_datetime_patterns_1000", |b| {
288288
let mut rng = rand::rng();
289289
let data_arr = generate_date32_array(&mut rng);
@@ -311,6 +311,7 @@ fn criterion_benchmark(c: &mut Criterion) {
311311
})
312312
});
313313

314+
// Covers partial fallback (roughly half the rows trigger it)
314315
c.bench_function("to_char_array_date32_mixed_patterns_1000", |b| {
315316
let mut rng = rand::rng();
316317
let data_arr = generate_date32_array(&mut rng);

datafusion/functions/src/datetime/to_char.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,10 @@ fn to_char_array(args: &[ColumnarValue]) -> Result<ColumnarValue> {
265265

266266
buffer.clear();
267267

268+
// We'd prefer to write directly to the StringBuilder's internal buffer,
269+
// but the write might fail, and there's no easy way to ensure a partial
270+
// write is removed from the buffer. So instead we write to a temporary
271+
// buffer and `append_value` on success.
268272
match formatter.value(idx).write(&mut buffer) {
269273
Ok(()) => builder.append_value(&buffer),
270274
Err(_) if data_type == &Date32 => {
@@ -313,11 +317,21 @@ mod tests {
313317

314318
#[test]
315319
fn test_array_array() {
316-
let array_array_data = vec![(
317-
Arc::new(Date32Array::from(vec![18506, 18507])) as ArrayRef,
318-
StringArray::from(vec!["%Y::%m::%d", "%Y::%m::%d %S::%M::%H %f"]),
319-
StringArray::from(vec!["2020::09::01", "2020::09::02 00::00::00 000000000"]),
320-
)];
320+
let array_array_data = vec![
321+
(
322+
Arc::new(Date32Array::from(vec![18506, 18507])) as ArrayRef,
323+
StringArray::from(vec!["%Y::%m::%d", "%Y::%m::%d %S::%M::%H %f"]),
324+
StringArray::from(vec![
325+
"2020::09::01",
326+
"2020::09::02 00::00::00 000000000",
327+
]),
328+
),
329+
(
330+
Arc::new(Date32Array::from(vec![18506, 18507])) as ArrayRef,
331+
StringArray::from(vec!["%Y::%m::%d %H:%M:%S", "%d-%m-%Y %H:%M"]),
332+
StringArray::from(vec!["2020::09::01 00:00:00", "02-09-2020 00:00"]),
333+
),
334+
];
321335

322336
for (value, format, expected) in array_array_data {
323337
let batch_len = value.len();

0 commit comments

Comments
 (0)