ethan-tyler commented on code in PR #9220:
URL: https://github.com/apache/arrow-rs/pull/9220#discussion_r2732618308


##########
arrow-cast/src/cast/mod.rs:
##########
@@ -5718,6 +5718,418 @@ mod tests {
         assert_eq!(dict_array.values().len(), 3);
     }
 
+    #[test]
+    fn test_cast_string_array_to_dict_utf8_view() {
+        let array = StringArray::from(vec![Some("one"), None, Some("three"), 
Some("one")]);
+
+        let cast_type =
+            DataType::Dictionary(Box::new(DataType::UInt16), 
Box::new(DataType::Utf8View));
+        let cast_array = cast(&array, &cast_type).unwrap();
+        assert_eq!(cast_array.data_type(), &cast_type);
+
+        let dict_array = cast_array
+            .as_any()
+            .downcast_ref::<DictionaryArray<UInt16Type>>()
+            .unwrap();
+        assert_eq!(dict_array.values().data_type(), &DataType::Utf8View);
+        assert_eq!(dict_array.values().len(), 2); // "one" and "three" 
deduplicated
+
+        let typed = dict_array.downcast_dict::<StringViewArray>().unwrap();
+        let actual: Vec<Option<&str>> = typed.into_iter().collect();
+        assert_eq!(actual, vec![Some("one"), None, Some("three"), 
Some("one")]);
+
+        let keys = dict_array.keys();
+        assert!(keys.is_null(1));
+        assert_eq!(keys.value(0), keys.value(3));
+        assert_ne!(keys.value(0), keys.value(2));
+    }
+
+    #[test]
+    fn test_cast_string_array_to_dict_utf8_view_null_vs_literal_null() {
+        let array = StringArray::from(vec![Some("one"), None, Some("null"), 
Some("one")]);
+
+        let cast_type =
+            DataType::Dictionary(Box::new(DataType::UInt16), 
Box::new(DataType::Utf8View));
+        let cast_array = cast(&array, &cast_type).unwrap();
+        assert_eq!(cast_array.data_type(), &cast_type);
+
+        let dict_array = cast_array
+            .as_any()
+            .downcast_ref::<DictionaryArray<UInt16Type>>()
+            .unwrap();
+        assert_eq!(dict_array.values().data_type(), &DataType::Utf8View);
+        assert_eq!(dict_array.values().len(), 2);
+
+        let typed = dict_array.downcast_dict::<StringViewArray>().unwrap();
+        let actual: Vec<Option<&str>> = typed.into_iter().collect();
+        assert_eq!(actual, vec![Some("one"), None, Some("null"), Some("one")]);
+
+        let keys = dict_array.keys();
+        assert!(keys.is_null(1));
+        assert_eq!(keys.value(0), keys.value(3));
+        assert_ne!(keys.value(0), keys.value(2));
+    }
+
+    #[test]
+    fn test_cast_string_view_array_to_dict_utf8_view_null_vs_literal_null() {
+        let array = StringArray::from(vec![Some("one"), None, Some("null"), 
Some("one")]);
+        let view = cast(&array, &DataType::Utf8View).unwrap();

Review Comment:
   Updated the view input tests to construct `StringViewArray/BinaryViewArray` 
directly, they strictly test View → Dictionary. To avoid duplication the null 
vs literal‑null case stays only in the StringArray -> Dictionary(Utf8View) test 
.



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