askoa commented on code in PR #3622:
URL: https://github.com/apache/arrow-rs/pull/3622#discussion_r1096543630
##########
arrow/src/util/bench_util.rs:
##########
@@ -145,6 +146,71 @@ pub fn create_string_dict_array<K: ArrowDictionaryKeyType>(
data.iter().map(|x| x.as_deref()).collect()
}
+/// Create primitive run array for given logical and physical array lengths
+pub fn create_primitive_run_array<R: RunEndIndexType, V: ArrowPrimitiveType>(
+ logical_array_len: usize,
+ physical_array_len: usize,
+) -> RunArray<R> {
+ // typical length of each run
+ let run_len = logical_array_len / physical_array_len;
+
+ // Some runs should have extra length
+ let mut run_len_extra = logical_array_len % physical_array_len;
+
+ let mut values: Vec<V::Native> = (0..physical_array_len)
+ .flat_map(|s| {
+ let mut take_len = run_len;
+ if run_len_extra > 0 {
+ take_len += 1;
+ run_len_extra -= 1;
+ }
+ std::iter::repeat(V::Native::from_usize(s).unwrap()).take(take_len)
+ })
+ .collect();
+ while values.len() < logical_array_len {
+ let last_val = values[values.len() - 1];
+ values.push(last_val);
+ }
+ let mut builder = PrimitiveRunBuilder::<R,
V>::with_capacity(physical_array_len);
+ builder.extend(values.into_iter().map(Some));
+
+ builder.finish()
+}
+
+/// Create string array to be used by run array builder. The string array
+/// will result in run array with physial length of `physical_array_len`
+/// and logical length of `logical_array_len`
+pub fn create_string_array_for_runs(
+ physical_array_len: usize,
+ logical_array_len: usize,
+ string_len: usize,
+) -> Vec<String> {
+ let mut rng = thread_rng();
Review Comment:
it should be `>=`.
--
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]