scovich commented on code in PR #8673:
URL: https://github.com/apache/arrow-rs/pull/8673#discussion_r2550192658


##########
parquet-variant-compute/src/variant_array.rs:
##########
@@ -733,6 +736,91 @@ impl From<ShreddedVariantFieldArray> for StructArray {
     }
 }
 
+/// A typed array reference that pairs an [`ArrayRef`] with its [`Field`] 
metadata.
+///
+/// This struct is used to represent the `typed_value` field in shredded 
variant arrays,
+/// where we need to preserve both the array data and its field metadata (such 
as field
+/// name, data type, nullability, and extension type information).
+///
+/// The separation of array data and field metadata allows for proper handling 
of:
+/// - Field names when working with struct fields
+/// - Nullability information for proper null handling
+/// - Extension type metadata (e.g., UUID extension on FixedSizeBinary)
+/// - Data type information for casting and validation
+#[derive(Debug, Clone)]
+pub struct TypedArrayRef {
+    inner: ArrayRef,
+    field: FieldRef,
+}
+
+impl TypedArrayRef {
+    pub fn inner(&self) -> &ArrayRef {
+        &self.inner
+    }
+
+    pub fn into_inner(self) -> ArrayRef {
+        self.inner
+    }
+
+    pub fn field(&self) -> &FieldRef {
+        &self.field
+    }
+
+    // note: these methods below make me want to impl Array for 
TypedArrayRef...
+    pub fn slice(&self, offset: usize, length: usize) -> Self {
+        let Self { inner, field } = self;
+
+        Self {
+            inner: inner.slice(offset, length),
+            field: Arc::clone(field),
+        }
+    }
+
+    pub fn is_valid(&self, index: usize) -> bool {
+        self.inner.is_valid(index)
+    }
+}
+
+impl From<ArrayRef> for TypedArrayRef {
+    fn from(inner: ArrayRef) -> Self {
+        let data_type = inner.data_type().clone();
+
+        Self {
+            inner,
+            field: Arc::new(Field::new("typed_value", data_type, true)),
+        }
+    }
+}
+
+impl PartialEq for TypedArrayRef {
+    #[allow(clippy::op_ref)]
+    fn eq(&self, other: &Self) -> bool {
+        &self.inner == &other.inner && self.field == other.field
+    }
+}

Review Comment:
   I have vague memories of hitting head-scratchy bugs in comparison-wielding 
code like this, and was informed there are actually rustc bugs involved. Might 
it be https://github.com/rust-lang/rust/issues/31740?



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