Jefffrey commented on code in PR #10436:
URL: https://github.com/apache/arrow-rs/pull/10436#discussion_r3793429190


##########
arrow-cast/src/cast/dictionary.rs:
##########
@@ -561,3 +701,319 @@ where
     }
     Ok(Arc::new(b.finish()))
 }
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+
+    /// Casting a dictionary to a view type has two implementations: building 
one view per row
+    /// directly against the values buffer, and `unpack_dictionary`. Which one 
runs depends on
+    /// how the row count compares to the dictionary size, so these helpers 
pin both branches of
+    /// that choice for each arm.
+    ///
+    /// `values` must have 6 entries; the returned key sets sit either side of 
the threshold.
+    fn keys_taking_direct_path() -> Int32Array {
+        // 2 keys < 6/2 values -> views are built directly per row
+        Int32Array::from_iter([Some(0), Some(3)])
+    }
+
+    fn keys_taking_unpack_path() -> Int32Array {
+        // 6 keys >= 6/2 values -> unpack_dictionary
+        Int32Array::from_iter([Some(0), Some(3), None, Some(1), Some(2), 
Some(0)])
+    }
+
+    fn cast_dict(values: ArrayRef, keys: Int32Array, to_type: &DataType) -> 
ArrayRef {
+        let dict = DictionaryArray::<Int32Type>::try_new(keys, 
values).unwrap();
+        assert!(can_cast_types(dict.data_type(), to_type));
+        let casted = cast(&dict, to_type).unwrap();
+        assert_eq!(casted.data_type(), to_type);
+        casted
+    }
+
+    #[test]
+    fn test_dict_to_view_both_paths_agree() {

Review Comment:
   > the keys can't be the same since their ratio to values determines the 
path, so i only varied the key count
   
   we probably could keep the same keys and just vary the dictionary values size



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