kosiew commented on code in PR #21151:
URL: https://github.com/apache/datafusion/pull/21151#discussion_r3025725747


##########
datafusion/functions-aggregate/src/min_max.rs:
##########
@@ -1270,4 +1270,104 @@ mod tests {
         assert_eq!(max_result, ScalarValue::Utf8(Some("🦀".to_string())));
         Ok(())
     }
+
+    fn dict_scalar(key_type: DataType, inner: ScalarValue) -> ScalarValue {
+        ScalarValue::Dictionary(Box::new(key_type), Box::new(inner))
+    }
+
+    #[test]
+    fn test_min_max_dictionary_without_coercion() -> Result<()> {
+        let values = StringArray::from(vec!["b", "c", "a", "d"]);
+        let keys = Int32Array::from(vec![Some(0), Some(1), Some(2), Some(3)]);
+        let dict_array =
+            DictionaryArray::try_new(keys, Arc::new(values) as 
ArrayRef).unwrap();
+        let dict_array_ref = Arc::new(dict_array) as ArrayRef;
+
+        // Pass the raw Dictionary type — no get_min_max_result_type() unwrap.
+        let dict_type = dict_array_ref.data_type().clone();
+
+        let mut min_acc = MinAccumulator::try_new(&dict_type)?;
+        min_acc.update_batch(&[Arc::clone(&dict_array_ref)])?;
+        let min_result = min_acc.evaluate()?;
+        assert_eq!(
+            min_result,
+            dict_scalar(DataType::Int32, 
ScalarValue::Utf8(Some("a".to_string())))
+        );
+
+        let mut max_acc = MaxAccumulator::try_new(&dict_type)?;
+        max_acc.update_batch(&[Arc::clone(&dict_array_ref)])?;
+        let max_result = max_acc.evaluate()?;
+        assert_eq!(
+            max_result,
+            dict_scalar(DataType::Int32, 
ScalarValue::Utf8(Some("d".to_string())))
+        );
+        Ok(())
+    }
+
+    #[test]
+    fn test_min_max_dictionary_with_nulls() -> Result<()> {
+        let values = StringArray::from(vec!["b", "c", "a"]);
+        let keys = Int32Array::from(vec![None, Some(0), None, Some(1), 
Some(2)]);
+        let dict_array =
+            DictionaryArray::try_new(keys, Arc::new(values) as 
ArrayRef).unwrap();
+        let dict_array_ref = Arc::new(dict_array) as ArrayRef;

Review Comment:
   The three new tests look good, but they repeat the same dictionary array 
setup pattern.
   
   A small helper that builds a DictionaryArray and ArrayRef pair could make 
these tests easier to read and keep future dictionary min/max cases cheaper to 
add.



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