alamb commented on code in PR #12059:
URL: https://github.com/apache/arrow-rs/pull/12059#discussion_r4670602427


##########
arrow-select/src/interleave.rs:
##########
@@ -312,6 +351,24 @@ fn interleave_dictionaries<K: ArrowDictionaryKeyType>(
     Ok(Arc::new(array))
 }
 
+/// Interleaves dictionary keys without copying their shared values array.
+fn interleave_shared_dictionary<K: ArrowDictionaryKeyType>(
+    dictionaries: &[&DictionaryArray<K>],
+    indices: &[(usize, usize)],
+    shared_values: &ArrayRef,
+) -> Result<ArrayRef, ArrowError> {
+    let key_arrays: Vec<&dyn Array> = dictionaries
+        .iter()
+        .map(|dictionary| dictionary.keys() as &dyn Array)
+        .collect();
+    let keys = interleave_primitive::<K>(&key_arrays, indices, 
dictionaries[0].keys().data_type())?;
+    // SAFETY: every non-null key came from a dictionary backed by 
`shared_values`.

Review Comment:
   probably technically we should make this function unsafe too as it requires 
shared_values to be the same for all input dictionaries



##########
arrow-select/src/interleave.rs:
##########
@@ -264,33 +264,72 @@ fn interleave_dictionaries<K: ArrowDictionaryKeyType>(
     let dictionaries: Vec<_> = arrays.iter().map(|x| 
x.as_dictionary::<K>()).collect();
     let (should_merge, has_overflow) =
         should_merge_dictionary_values::<K>(&dictionaries, indices.len());
-    if !should_merge {
-        return if has_overflow {
-            interleave_fallback(arrays, indices)
+    let strategy = if should_merge {
+        DictionaryInterleaveStrategy::MergeDictionaries
+    } else {
+        let first_values = dictionaries[0].values();
+        if dictionaries
+            .iter()
+            .skip(1)
+            .all(|dictionary| Arc::ptr_eq(first_values, dictionary.values()))
+        {
+            DictionaryInterleaveStrategy::SharedDictionary
+        } else if has_overflow {
+            DictionaryInterleaveStrategy::Fallback
         } else {
+            DictionaryInterleaveStrategy::FallbackDictionary
+        }
+    };
+
+    match strategy {

Review Comment:
   thank you -- I find this much easier to read now



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

Reply via email to