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


##########
parquet-variant-compute/src/variant_get.rs:
##########
@@ -999,152 +1207,48 @@ mod test {
         f64
     );
 
-    /// Return a VariantArray that represents a partially "shredded" variant 
for bool
-    fn partially_shredded_bool_variant_array() -> ArrayRef {
-        let (metadata, string_value) = {
-            let mut builder = parquet_variant::VariantBuilder::new();
-            builder.append_value("n/a");
-            builder.finish()
-        };
-
-        let nulls = NullBuffer::from(vec![
-            true,  // row 0 non null
-            false, // row 1 is null
-            true,  // row 2 non null
-            true,  // row 3 non null
-        ]);
-
-        // metadata is the same for all rows
-        let metadata = 
BinaryViewArray::from_iter_values(std::iter::repeat_n(&metadata, 4));
-
-        // See 
https://docs.google.com/document/d/1pw0AWoMQY3SjD7R4LgbPvMjG_xSCtXp3rZHkVp9jpZ4/edit?disco=AAABml8WQrY
-        // about why row1 is an empty but non null, value.
-        let values = BinaryViewArray::from(vec![
-            None,                // row 0 is shredded, so no value
-            Some(b"" as &[u8]),  // row 1 is null, so empty value (why?)
-            Some(&string_value), // copy the string value "N/A"
-            None,                // row 3 is shredded, so no value
-        ]);
-
-        let typed_value = BooleanArray::from(vec![
+    
partially_shredded_variant_array_gen!(partially_shredded_bool_variant_array, || 
{
+        arrow::array::BooleanArray::from(vec![
             Some(true),  // row 0 is shredded, so it has a value
             None,        // row 1 is null, so no value
             None,        // row 2 is a string, so no typed value
             Some(false), // row 3 is shredded, so it has a value
-        ]);
-
-        let struct_array = StructArrayBuilder::new()
-            .with_field("metadata", Arc::new(metadata), false)
-            .with_field("typed_value", Arc::new(typed_value), true)
-            .with_field("value", Arc::new(values), true)
-            .with_nulls(nulls)
-            .build();
-
-        Arc::new(struct_array)
-    }
-
-    /// Return a VariantArray that represents a partially "shredded" variant 
for fixed size binary
-    fn partially_shredded_fixed_size_binary_variant_array() -> ArrayRef {
-        let (metadata, string_value) = {
-            let mut builder = parquet_variant::VariantBuilder::new();
-            builder.append_value("n/a");
-            builder.finish()
-        };
-
-        // Create the null buffer for the overall array
-        let nulls = NullBuffer::from(vec![
-            true,  // row 0 non null
-            false, // row 1 is null
-            true,  // row 2 non null
-            true,  // row 3 non null
-        ]);
-
-        // metadata is the same for all rows
-        let metadata = 
BinaryViewArray::from_iter_values(std::iter::repeat_n(&metadata, 4));
-
-        // See 
https://docs.google.com/document/d/1pw0AWoMQY3SjD7R4LgbPvMjG_xSCtXp3rZHkVp9jpZ4/edit?disco=AAABml8WQrY
-        // about why row1 is an empty but non null, value.
-        let values = BinaryViewArray::from(vec![
-            None,                // row 0 is shredded, so no value
-            Some(b"" as &[u8]),  // row 1 is null, so empty value
-            Some(&string_value), // copy the string value "N/A"
-            None,                // row 3 is shredded, so no value
-        ]);
-
-        // Create fixed size binary array with 3-byte values
-        let data = vec![
-            1u8, 2u8, 3u8, // row 0 is shredded
-            0u8, 0u8, 0u8, // row 1 is null (value doesn't matter)
-            0u8, 0u8, 0u8, // row 2 is a string (value doesn't matter)
-            4u8, 5u8, 6u8, // row 3 is shredded
-        ];
-        let typed_value_nulls = arrow::buffer::NullBuffer::from(vec![
-            true,  // row 0 has value
-            false, // row 1 is null
-            false, // row 2 is string
-            true,  // row 3 has value
-        ]);
-        let typed_value = FixedSizeBinaryArray::try_new(
-            3, // byte width
-            arrow::buffer::Buffer::from(data),
-            Some(typed_value_nulls),
-        )
-        .expect("should create fixed size binary array");
-
-        let struct_array = StructArrayBuilder::new()
-            .with_field("metadata", Arc::new(metadata), false)
-            .with_field("typed_value", Arc::new(typed_value), true)
-            .with_field("value", Arc::new(values), true)
-            .with_nulls(nulls)
-            .build();
-
-        Arc::new(struct_array)
-    }
-
-    /// Return a VariantArray that represents a partially "shredded" variant 
for UTF8
-    fn partially_shredded_utf8_variant_array() -> ArrayRef {
-        let (metadata, string_value) = {
-            let mut builder = parquet_variant::VariantBuilder::new();
-            builder.append_value("n/a");
-            builder.finish()
-        };
-
-        // Create the null buffer for the overall array
-        let nulls = NullBuffer::from(vec![
-            true,  // row 0 non null
-            false, // row 1 is null
-            true,  // row 2 non null
-            true,  // row 3 non null
-        ]);
-
-        // metadata is the same for all rows
-        let metadata = 
BinaryViewArray::from_iter_values(std::iter::repeat_n(&metadata, 4));
-
-        // See 
https://docs.google.com/document/d/1pw0AWoMQY3SjD7R4LgbPvMjG_xSCtXp3rZHkVp9jpZ4/edit?disco=AAABml8WQrY
-        // about why row1 is an empty but non null, value.
-        let values = BinaryViewArray::from(vec![
-            None,                // row 0 is shredded, so no value
-            Some(b"" as &[u8]),  // row 1 is null, so empty value
-            Some(&string_value), // copy the string value "N/A"
-            None,                // row 3 is shredded, so no value
-        ]);
+        ])
+    });
+
+    partially_shredded_variant_array_gen!(

Review Comment:
   thank you for reducing the boilerplate



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