scovich commented on code in PR #8446:
URL: https://github.com/apache/arrow-rs/pull/8446#discussion_r2379838038
##########
parquet-variant-compute/src/variant_array.rs:
##########
@@ -901,65 +934,119 @@ impl StructArrayBuilder {
}
}
+/// A simple wrapper that provides VariantBuilderExt for building a single
variant value
+///
+/// This is used specifically by VariantArray::value to build a single variant
from shredded data
+/// without the complexity of array-level state management.
+struct SingleValueVariantBuilder<'m> {
+ value_builder: ValueBuilder,
+ metadata_builder: ReadOnlyMetadataBuilder<'m>,
+}
+
+impl<'m> SingleValueVariantBuilder<'m> {
+ fn new(metadata: VariantMetadata<'m>) -> Self {
+ Self {
+ value_builder: ValueBuilder::new(),
+ metadata_builder: ReadOnlyMetadataBuilder::new(metadata),
+ }
+ }
+
+ fn into_bytes(self) -> Vec<u8> {
+ self.value_builder.into_inner()
+ }
+
+ fn parent_state(&mut self) -> ParentState<'_, ()> {
+ ParentState::variant(&mut self.value_builder, &mut
self.metadata_builder)
+ }
+}
+
+impl VariantBuilderExt for SingleValueVariantBuilder<'_> {
+ type State<'a>
+ = ()
+ where
+ Self: 'a;
+
+ fn append_null(&mut self) {
+ self.value_builder.append_null();
+ }
+
+ fn append_value<'m, 'v>(&mut self, value: impl Into<Variant<'m, 'v>>) {
+ ValueBuilder::append_variant_bytes(self.parent_state(), value.into());
+ }
+
+ fn try_new_list(&mut self) -> Result<ListBuilder<'_, Self::State<'_>>,
ArrowError> {
+ Ok(ListBuilder::new(self.parent_state(), false))
+ }
+
+ fn try_new_object(&mut self) -> Result<ObjectBuilder<'_, Self::State<'_>>,
ArrowError> {
+ Ok(ObjectBuilder::new(self.parent_state(), false))
+ }
+}
+
/// returns the non-null element at index as a Variant
-fn typed_value_to_variant<'a>(
- typed_value: &'a ArrayRef,
+fn typed_value_to_variant(
+ typed_value: &ArrayRef,
value: Option<&BinaryViewArray>,
index: usize,
-) -> VariantArrayValue<'a, 'a> {
- let data_type = typed_value.data_type();
- if value.is_some_and(|v| !matches!(data_type, DataType::Struct(_)) &&
v.is_valid(index)) {
- // Only a partially shredded struct is allowed to have values for both
columns
- panic!("Invalid variant, conflicting value and typed_value");
- }
Review Comment:
This check moved to the bottom of the method (after struct has already been
handled and returned early)
--
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]