klion26 commented on code in PR #7965:
URL: https://github.com/apache/arrow-rs/pull/7965#discussion_r2218376504


##########
parquet-variant-compute/src/variant_get.rs:
##########
@@ -177,4 +192,209 @@ mod test {
             r#"{"inner_field": 1234}"#,
         );
     }
+
+    /// Shredding: extract a value as a VariantArray
+    #[test]
+    fn get_variant_shredded_int32_as_variant() {
+        let array = shredded_int32_variant_array();
+        let options = GetOptions::new();
+        let result = variant_get(&array, options).unwrap();
+
+        // expect the result is a VariantArray
+        let result: &VariantArray = result.as_any().downcast_ref().unwrap();
+        assert_eq!(result.len(), 4);
+
+        // Expect the values are the same as the original values
+        assert_eq!(result.value(0), Variant::Int32(34));
+        assert!(!result.is_valid(1));
+        assert_eq!(result.value(2), Variant::from("N/A"));
+        assert_eq!(result.value(3), Variant::Int32(100));
+    }
+
+    /// Shredding: extract a value as an Int32Array
+    #[test]
+    fn get_variant_shredded_int32_as_int32() {
+        // Extract the typed value as Int32Array
+        let array = shredded_int32_variant_array();
+        let options = GetOptions::new()
+            // specify we want the typed value as Int32
+            .with_as_type(Some(Field::new("typed_value", DataType::Int32, 
true)));
+        let result = variant_get(&array, options).unwrap();
+        let expected: ArrayRef = Arc::new(Int32Array::from(vec![Some(34), 
None, None, Some(100)]));
+        assert_eq!(&result, &expected)
+    }
+
+    /// Perfect Shredding: extract the typed value as a VariantArray
+    #[test]
+    fn get_variant_perfectly_shredded_int32_as_variant() {
+        let array = perfectly_shredded_int32_variant_array();
+        let options = GetOptions::new();
+        let result = variant_get(&array, options).unwrap();
+
+        // expect the result is a VariantArray
+        let result: &VariantArray = result.as_any().downcast_ref().unwrap();
+        assert_eq!(result.len(), 3);
+
+        // Expect the values are the same as the original values
+        assert_eq!(result.value(0), Variant::Int32(1));

Review Comment:
   If the `GetOptions` points to the leaf node, will the `result` here be equal 
to the `result` in test `get_variant_perfectly_shredded_int32_as_int32`



-- 
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: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to