scovich commented on code in PR #8166: URL: https://github.com/apache/arrow-rs/pull/8166#discussion_r2313747249
########## parquet-variant-compute/src/variant_array.rs: ########## @@ -102,31 +105,57 @@ impl VariantArray { ))); }; - // Find the value field, if present - let value = inner - .column_by_name("value") - .map(|v| { - v.as_binary_view_opt().ok_or_else(|| { - ArrowError::NotYetImplemented(format!( - "VariantArray 'value' field must be BinaryView, got {}", - v.data_type() - )) - }) - }) - .transpose()?; - - // Find the typed_value field, if present - let typed_value = inner.column_by_name("typed_value"); + // Extract value and typed_value fields + let value = if let Some(value_col) = inner.column_by_name("value") { + if let Some(binary_view) = value_col.as_binary_view_opt() { + Some(binary_view.clone()) + } else { + return Err(ArrowError::NotYetImplemented(format!( + "VariantArray 'value' field must be BinaryView, got {}", + value_col.data_type() + ))); + } + } else { + None + }; + let typed_value = inner.column_by_name("typed_value").cloned(); // Note these clones are cheap, they just bump the ref count - let inner = inner.clone(); - let shredding_state = - ShreddingState::try_new(metadata.clone(), value.cloned(), typed_value.cloned())?; - Ok(Self { + inner: inner.clone(), + metadata: metadata.clone(), + shredding_state: ShreddingState::try_new(metadata.clone(), value, typed_value)?, + }) + } + + #[allow(unused)] + pub(crate) fn from_parts( + metadata: BinaryViewArray, + value: Option<BinaryViewArray>, + typed_value: Option<ArrayRef>, + nulls: Option<NullBuffer>, + ) -> Self { + let mut builder = + StructArrayBuilder::new().with_field("metadata", Arc::new(metadata.clone())); + if let Some(value) = value.clone() { + builder = builder.with_field("value", Arc::new(value)); + } + if let Some(typed_value) = typed_value.clone() { + builder = builder.with_field("typed_value", typed_value); + } + if let Some(nulls) = nulls { Review Comment: Those other two are present in both `inner` and `shredding_state`, hence the`clone` calls. The `nulls` are only used once, so no `clone` needed. -- 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