This is an automated email from the ASF dual-hosted git repository.
mbrobbel pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/main by this push:
new 20ccf5feec [Variant] feat: Support typed_access for Boolean (#8346)
20ccf5feec is described below
commit 20ccf5feec8a31bebf5b69f7c8113ad7ed194154
Author: Alex Huang <[email protected]>
AuthorDate: Mon Sep 15 12:46:18 2025 +0300
[Variant] feat: Support typed_access for Boolean (#8346)
# Which issue does this PR close?
- Closes #8329.
# Rationale for this change
# What changes are included in this PR?
# Are these changes tested?
Yes
# Are there any user-facing changes?
If there are user-facing changes then we may require documentation to be
updated before approving the PR.
If there are any breaking changes to public APIs, please call them out.
---
parquet-variant-compute/src/variant_array.rs | 5 +++
parquet-variant-compute/src/variant_get.rs | 63 ++++++++++++++++++++++++++++
2 files changed, 68 insertions(+)
diff --git a/parquet-variant-compute/src/variant_array.rs
b/parquet-variant-compute/src/variant_array.rs
index 17b0adbdd0..0ec1f5cda4 100644
--- a/parquet-variant-compute/src/variant_array.rs
+++ b/parquet-variant-compute/src/variant_array.rs
@@ -590,6 +590,11 @@ impl StructArrayBuilder {
/// returns the non-null element at index as a Variant
fn typed_value_to_variant(typed_value: &ArrayRef, index: usize) -> Variant<'_,
'_> {
match typed_value.data_type() {
+ DataType::Boolean => {
+ let boolean_array = typed_value.as_boolean();
+ let value = boolean_array.value(index);
+ Variant::from(value)
+ }
DataType::Int8 => {
primitive_conversion_single_value!(Int8Type, typed_value, index)
}
diff --git a/parquet-variant-compute/src/variant_get.rs
b/parquet-variant-compute/src/variant_get.rs
index 7774d13670..9b4b7bbd7d 100644
--- a/parquet-variant-compute/src/variant_get.rs
+++ b/parquet-variant-compute/src/variant_get.rs
@@ -472,6 +472,23 @@ mod test {
numeric_partially_shredded_test!(f64,
partially_shredded_float64_variant_array);
}
+ #[test]
+ fn get_variant_partially_shredded_bool_as_variant() {
+ let array = partially_shredded_bool_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::from(true));
+ assert!(!result.is_valid(1));
+ assert_eq!(result.value(2), Variant::from("n/a"));
+ assert_eq!(result.value(3), Variant::from(false));
+ }
+
/// Shredding: extract a value as an Int32Array
#[test]
fn get_variant_shredded_int32_as_int32_safe_cast() {
@@ -874,6 +891,52 @@ 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 = 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))
+ .with_field("typed_value", Arc::new(typed_value))
+ .with_field("value", Arc::new(values))
+ .with_nulls(nulls)
+ .build();
+
+ Arc::new(
+ VariantArray::try_new(Arc::new(struct_array)).expect("should
create variant array"),
+ )
+ }
+
/// Builds struct arrays from component fields
///
/// TODO: move to arrow crate