Copilot commented on code in PR #10046:
URL: https://github.com/apache/arrow-rs/pull/10046#discussion_r3396543482
##########
arrow/src/util/bench_util.rs:
##########
@@ -871,3 +873,81 @@ pub fn create_f64_array_with_seed(size: usize,
nan_density: f32, seed: u64) -> F
})
.collect()
}
+
+/// Create a FixedSizeList array of primitive values
+///
+/// Arguments:
+/// - `size`: number of fixed-size lists in the array
+/// - `null_density`: density of nulls in the fixed-size list array (row-level
nulls)
+/// - `value_null_density`: density of nulls in the primitive values inside
each list
+/// - `list_size`: fixed size of each list element
+pub fn create_primitive_fixed_size_list_array<T>(
+ size: usize,
+ null_density: f32,
+ value_null_density: f32,
+ list_size: i32,
+) -> FixedSizeListArray
+where
+ T: ArrowPrimitiveType,
+ StandardUniform: Distribution<T::Native>,
+{
+ let mut rng = seedable_rng();
+ let list_size_usize = list_size as usize;
+ let values: PrimitiveArray<T> = (0..size * list_size_usize)
+ .map(|_| {
+ if rng.random::<f32>() < value_null_density {
+ None
+ } else {
+ Some(rng.random())
+ }
+ })
+ .collect();
+ let field = Arc::new(Field::new("item", T::DATA_TYPE, value_null_density >
0.0));
+ let nulls = (null_density > 0.0).then(|| {
+ NullBuffer::new(arrow_buffer::BooleanBuffer::collect_bool(size, |_| {
+ rng.random::<f32>() >= null_density
+ }))
+ });
+ FixedSizeListArray::new(field, list_size, Arc::new(values), nulls)
+}
+
+/// Create a Map array with string keys and primitive values
+///
+/// Arguments:
+/// - `size`: number of map entries in the array
+/// - `null_density`: density of nulls in the map array (row-level nulls)
+/// - `max_map_size`: maximum number of key-value pairs per map entry
+/// (actual size is random between 0 and max_map_size)
+/// - `key_len`: length of each random string key
+pub fn create_string_map_array<T>(
+ size: usize,
+ null_density: f32,
+ max_map_size: usize,
+ key_len: usize,
+) -> MapArray
+where
+ T: ArrowPrimitiveType,
+ StandardUniform: Distribution<T::Native>,
+{
+ let mut rng = seedable_rng();
+ let mut builder = builder::MapBuilder::new(
+ None,
+ builder::StringBuilder::new(),
+ builder::PrimitiveBuilder::<T>::new(),
+ );
Review Comment:
`builder::MapBuilder` / `builder::StringBuilder` /
`builder::PrimitiveBuilder` won’t resolve here: `use crate::array::*;`
re-exports the builder types, but not a `builder` module. This will fail to
compile for the benchmarks.
##########
arrow/src/util/bench_util.rs:
##########
@@ -871,3 +873,81 @@ pub fn create_f64_array_with_seed(size: usize,
nan_density: f32, seed: u64) -> F
})
.collect()
}
+
+/// Create a FixedSizeList array of primitive values
+///
+/// Arguments:
+/// - `size`: number of fixed-size lists in the array
+/// - `null_density`: density of nulls in the fixed-size list array (row-level
nulls)
+/// - `value_null_density`: density of nulls in the primitive values inside
each list
+/// - `list_size`: fixed size of each list element
+pub fn create_primitive_fixed_size_list_array<T>(
+ size: usize,
+ null_density: f32,
+ value_null_density: f32,
+ list_size: i32,
+) -> FixedSizeListArray
+where
+ T: ArrowPrimitiveType,
+ StandardUniform: Distribution<T::Native>,
+{
+ let mut rng = seedable_rng();
+ let list_size_usize = list_size as usize;
+ let values: PrimitiveArray<T> = (0..size * list_size_usize)
+ .map(|_| {
Review Comment:
`list_size` is an `i32` and is cast to `usize` before any validation. If a
negative `list_size` is passed, this will wrap to a huge `usize` and can
attempt an enormous allocation (`size * list_size_usize`) before
`FixedSizeListArray::new` has a chance to reject the negative size.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]