alamb commented on code in PR #13226:
URL: https://github.com/apache/datafusion/pull/13226#discussion_r1829624764


##########
test-utils/src/array_gen/random_data.rs:
##########
@@ -0,0 +1,102 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use arrow::array::ArrowPrimitiveType;
+use arrow::datatypes::{
+    i256, Date32Type, Date64Type, Decimal128Type, Decimal256Type, Float32Type,
+    Float64Type, Int16Type, Int32Type, Int64Type, Int8Type, IntervalDayTime,
+    IntervalDayTimeType, IntervalMonthDayNano, IntervalMonthDayNanoType,
+    IntervalYearMonthType, Time32MillisecondType, Time32SecondType,
+    Time64MicrosecondType, Time64NanosecondType, UInt16Type, UInt32Type, 
UInt64Type,
+    UInt8Type,
+};
+use rand::distributions::Standard;
+use rand::prelude::Distribution;
+use rand::rngs::StdRng;
+use rand::Rng;
+
+/// Generate corresponding NativeType value randomly according to
+/// ArrowPrimitiveType.
+pub trait RandomNativeData: ArrowPrimitiveType {
+    fn generate_random_native_data(rng: &mut StdRng) -> Self::Native;
+}
+
+macro_rules! basic_random_data {
+    ($ARROW_TYPE: ty) => {
+        impl RandomNativeData for $ARROW_TYPE
+        where
+            Standard: Distribution<Self::Native>,
+        {
+            #[inline]
+            fn generate_random_native_data(rng: &mut StdRng) -> Self::Native {
+                rng.gen::<Self::Native>()
+            }
+        }
+    };
+}
+
+basic_random_data!(Int8Type);
+basic_random_data!(Int16Type);
+basic_random_data!(Int32Type);
+basic_random_data!(Int64Type);
+basic_random_data!(UInt8Type);
+basic_random_data!(UInt16Type);
+basic_random_data!(UInt32Type);
+basic_random_data!(UInt64Type);
+basic_random_data!(Float32Type);
+basic_random_data!(Float64Type);
+basic_random_data!(Date32Type);
+basic_random_data!(Time32SecondType);
+basic_random_data!(Time32MillisecondType);
+basic_random_data!(Time64MicrosecondType);
+basic_random_data!(Time64NanosecondType);
+basic_random_data!(IntervalYearMonthType);
+basic_random_data!(Decimal128Type);
+
+impl RandomNativeData for Date64Type {

Review Comment:
   👍 



##########
datafusion/functions-aggregate/src/min_max/min_max_bytes.rs:
##########
@@ -338,6 +338,10 @@ impl GroupsAccumulator for MinMaxBytesAccumulator {
 /// This is a heuristic to avoid allocating too many small buffers
 fn capacity_to_view_block_size(data_capacity: usize) -> u32 {
     let max_block_size = 2 * 1024 * 1024;
+    // Avoid block size equal to zero when calling `with_fixed_block_size()`.
+    if data_capacity == 0 {
+        return 1;

Review Comment:
   I bet there is something / somewhere that is passing in an empty batch -- 
and a small optimization might be to avoid doing so. 
   
   Do you happen to have the stack trace still around?



##########
test-utils/src/array_gen/decimal.rs:
##########
@@ -0,0 +1,92 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use arrow::array::{ArrayRef, PrimitiveArray, PrimitiveBuilder, UInt32Array};
+use arrow::datatypes::{i256, Decimal128Type, Decimal256Type};
+use rand::rngs::StdRng;
+use rand::Rng;
+
+/// Randomly generate decimal arrays
+pub struct DecimalArrayGenerator {

Review Comment:
   This is really nice



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to