Skip to content

Commit 3ed377a

Browse files
authored
bench: introduce create_hash benchmarks (#25952)
## 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. --> - N/A — adds missing benchmark coverage. ## Rationale for this change `create_hashes()` has no dedicated benchmarks, making it hard to measure the impact of changes to hashing logic. covers all existing datatypes <!-- 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. Please explain the problem you are trying to solve in terms of the user-visible behavior, rather than the implementation. For example, "The code in `foo.rs` doesn't handle nulls" is a symptom of the implementation. "COUNT(DISTINCT) returns wrong results when the column contains nulls" is the user-visible problem. --> ## What changes are included in this PR? adds benchmarks for every datatype thats covered by `create_hashes()` <!-- 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. --> ## What is the testing strategy for this PR? n/a <!-- 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 Briefly describe how this PR is tested, and point to the specific tests you added. For example: 'This new feature is covered by the `sqllogictest` cases added in `foo.slt`'. If this PR does not add tests, explain why. For example, if the change is already covered by existing tests, please mention it. You should also check the `codecov` bot reply on this PR to confirm the changed code is exercised. --> ## Are there any user-facing changes? no <!-- 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 64de4fc commit 3ed377a

1 file changed

Lines changed: 64 additions & 4 deletions

File tree

‎datafusion/common/benches/with_hashes.rs‎

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
//! Benchmarks for `with_hashes` function
1919
2020
use arrow::array::{
21-
Array, ArrayRef, ArrowPrimitiveType, DictionaryArray, GenericStringArray, Int32Array,
22-
Int64Array, ListArray, MapArray, NullBufferBuilder, OffsetSizeTrait, PrimitiveArray,
23-
RunArray, StringViewArray, StructArray, UnionArray, make_array,
21+
Array, ArrayRef, ArrowPrimitiveType, DictionaryArray, FixedSizeListArray,
22+
GenericStringArray, Int32Array, Int64Array, ListArray, ListViewArray, MapArray,
23+
NullArray, NullBufferBuilder, OffsetSizeTrait, PrimitiveArray, RunArray,
24+
StringViewArray, StructArray, UnionArray, make_array,
2425
};
2526
use arrow::buffer::{NullBuffer, OffsetBuffer, ScalarBuffer};
2627
use arrow::datatypes::{
@@ -127,6 +128,21 @@ fn criterion_benchmark(c: &mut Criterion) {
127128
array: create_run_array::<Int32Type>(BATCH_SIZE),
128129
supports_nulls: true,
129130
},
131+
BenchData {
132+
name: "null",
133+
array: Arc::new(NullArray::new(BATCH_SIZE)),
134+
supports_nulls: false,
135+
},
136+
BenchData {
137+
name: "list_view_array",
138+
array: list_view_array(BATCH_SIZE),
139+
supports_nulls: true,
140+
},
141+
BenchData {
142+
name: "fixed_size_list_array",
143+
array: fixed_size_list_array(BATCH_SIZE),
144+
supports_nulls: true,
145+
},
130146
];
131147

132148
for BenchData {
@@ -603,5 +619,49 @@ where
603619
)
604620
}
605621

606-
criterion_group!(benches, criterion_benchmark, sliced_array_benchmark);
622+
fn list_view_array(num_rows: usize) -> ArrayRef {
623+
let elements_per_row = 5;
624+
let values = primitive_array::<Int64Type>(num_rows * elements_per_row);
625+
let offsets: ScalarBuffer<i32> = (0..num_rows)
626+
.map(|i| (i * elements_per_row) as i32)
627+
.collect();
628+
let sizes: ScalarBuffer<i32> =
629+
(0..num_rows).map(|_| elements_per_row as i32).collect();
630+
Arc::new(ListViewArray::new(
631+
Arc::new(Field::new("item", DataType::Int64, true)),
632+
offsets,
633+
sizes,
634+
values,
635+
None,
636+
))
637+
}
638+
639+
fn fixed_size_list_array(num_rows: usize) -> ArrayRef {
640+
let list_size = 4;
641+
Arc::new(FixedSizeListArray::new(
642+
Arc::new(Field::new("item", DataType::Int64, true)),
643+
list_size as i32,
644+
primitive_array::<Int64Type>(num_rows * list_size),
645+
None,
646+
))
647+
}
648+
649+
/// Heterogeneous key columns
650+
fn mixed_columns_benchmark(c: &mut Criterion) {
651+
let pool = StringPool::new(100, 64);
652+
let int64 = primitive_array::<Int64Type>(BATCH_SIZE);
653+
let utf8 = pool.string_array::<i32>(BATCH_SIZE);
654+
let utf8_view = pool.string_view_array(BATCH_SIZE);
655+
let arrays = vec![int64, utf8, utf8_view];
656+
c.bench_function("mixed: 3 columns (int64, utf8, utf8_view)", |b| {
657+
do_hash_test(b, &arrays)
658+
});
659+
}
660+
661+
criterion_group!(
662+
benches,
663+
criterion_benchmark,
664+
sliced_array_benchmark,
665+
mixed_columns_benchmark
666+
);
607667
criterion_main!(benches);

0 commit comments

Comments
 (0)