Skip to content

Commit b807629

Browse files
committed
Copy functions in when using std rng
1 parent 6bc0f61 commit b807629

1 file changed

Lines changed: 29 additions & 3 deletions

File tree

‎datafusion/functions-aggregate/benches/array_agg.rs‎

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,43 @@ use std::sync::Arc;
1919

2020
use arrow::array::{
2121
Array, ArrayRef, ArrowPrimitiveType, AsArray, ListArray, NullBufferBuilder,
22+
PrimitiveArray,
2223
};
2324
use arrow::datatypes::{Field, Int64Type};
24-
use arrow::util::bench_util::create_primitive_array;
2525
use criterion::{black_box, criterion_group, criterion_main, Criterion};
2626
use datafusion_expr::Accumulator;
2727
use datafusion_functions_aggregate::array_agg::ArrayAggAccumulator;
2828

2929
use arrow::buffer::OffsetBuffer;
30-
use arrow::util::test_util::seedable_rng;
3130
use rand::distributions::{Distribution, Standard};
32-
use rand::Rng;
31+
use rand::prelude::StdRng;
32+
use rand::{Rng, SeedableRng};
33+
34+
/// Seedable rng for reproducibility, copied from arrow-rs
35+
fn seedable_rng() -> StdRng {
36+
StdRng::seed_from_u64(42)
37+
}
38+
39+
/// Create a primitive array of a given size and null density
40+
///
41+
/// copied from arrow-rs
42+
fn create_primitive_array<T>(size: usize, null_density: f32) -> PrimitiveArray<T>
43+
where
44+
T: ArrowPrimitiveType,
45+
Standard: Distribution<T::Native>,
46+
{
47+
let mut rng = seedable_rng();
48+
49+
(0..size)
50+
.map(|_| {
51+
if rng.gen::<f32>() < null_density {
52+
None
53+
} else {
54+
Some(rng.gen())
55+
}
56+
})
57+
.collect()
58+
}
3359

3460
fn merge_batch_bench(c: &mut Criterion, name: &str, values: ArrayRef) {
3561
let list_item_data_type = values.as_list::<i32>().values().data_type().clone();

0 commit comments

Comments
 (0)