paleolimbot commented on code in PR #8673:
URL: https://github.com/apache/arrow-rs/pull/8673#discussion_r2536358880
##########
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)
+ }
Review Comment:
This definitely solves the problem of writing APIs that need to propgagate
extension metadata without constantly pairing a FieldRef. It may be worth
starting with the internal struct and the methods like you have here and moving
to a trait when there's a case that arises elsewhere that also needs that
concept? (I'm not very good at predicting where things should go inside the
arrow-rs crates)
--
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]