jayzhan211 commented on code in PR #27664:
URL: https://github.com/apache/datafusion/pull/27664#discussion_r4680343288


##########
datafusion/physical-plan/src/aggregates/group_values/multi_group_by/mod.rs:
##########
@@ -1162,11 +1176,25 @@ impl<const STREAMING: bool> GroupValues for 
GroupValuesColumn<STREAMING> {
             return Ok(());
         }
         if !STREAMING {
-            self.vectorized_intern(cols, groups)
+            self.vectorized_intern::<INSERT>(cols, groups)
         } else {
-            self.scalarized_intern(cols, groups)
+            self.scalarized_intern::<INSERT>(cols, groups)
         }
     }
+}
+
+impl<const STREAMING: bool> GroupValues for GroupValuesColumn<STREAMING> {
+    fn intern(&mut self, cols: &[ArrayRef], groups: &mut Vec<usize>) -> 
Result<()> {
+        self.probe::<true>(cols, groups)
+    }
+
+    fn lookup(&mut self, cols: &[ArrayRef], groups: &mut Vec<usize>) -> 
Result<()> {

Review Comment:
   Could you add a `lookup` test on a single dictionary column? With that 
schema, `probe` can return early through `try_map_dictionary_groups`, before 
the `INSERT` dispatch. So `lookup` there is correct only because that fast path 
never inserts, and no test checks it. The test below covers the fast path, the 
vectorized fallback (unstored value, null key) and a new values array. It 
passes on this head and fails if the fast path returns wrong ids.
   
   <details>
   <summary>Test for <code>multi_group_by::tests</code> (ran on this head; 
clippy clean)</summary>
   
   ```rs
   #[test]
   fn lookup_single_dictionary_column() -> Result<()> {
       let schema = Arc::new(Schema::new(vec![Field::new(
           "d",
           DataType::Dictionary(Box::new(DataType::Int32), 
Box::new(DataType::Utf8)),
           true,
       )]));
       let mut group_values = GroupValuesColumn::<false>::try_new(schema)?;
       let dict = |keys: Vec<Option<i32>>, values: &ArrayRef| -> Vec<ArrayRef> {
           vec![Arc::new(DictionaryArray::<Int32Type>::new(
               Int32Array::from(keys),
               Arc::clone(values),
           ))]
       };
       let values: ArrayRef = Arc::new(StringArray::from(vec!["a", "b", "c"]));
       let mut groups = vec![];
       group_values
           .intern(&dict(vec![Some(0), Some(1), Some(0)], &values), &mut 
groups)?;
       assert_eq!(groups, vec![0, 1, 0]);
   
       // Every key is cached for this values array, so this takes
       // `try_map_dictionary_groups`, which returns before the `INSERT` 
dispatch.
       group_values.lookup(&dict(vec![Some(1), Some(0)], &values), &mut 
groups)?;
       assert_eq!(groups, vec![1, 0]);
   
       // An unstored value and a null key fall back to the vectorized path.
       let keys = vec![Some(0), Some(2), None, Some(1)];
       group_values.lookup(&dict(keys, &values), &mut groups)?;
       assert_eq!(groups, vec![0, MISSING_GROUP, MISSING_GROUP, 1]);
   
       // A new values array is hashed again and compared uncached.
       let values: ArrayRef = Arc::new(StringArray::from(vec!["c", "a"]));
       group_values.lookup(&dict(vec![Some(0), Some(1)], &values), &mut 
groups)?;
       assert_eq!(groups, vec![MISSING_GROUP, 0]);
       assert_eq!(group_values.len(), 2);
       Ok(())
   }
   ```
   </details>



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