alamb commented on code in PR #8021:
URL: https://github.com/apache/arrow-rs/pull/8021#discussion_r2261110415


##########
parquet-variant-compute/src/variant_get/output/primitive.rs:
##########
@@ -0,0 +1,171 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use crate::variant_get::output::OutputBuilder;
+use crate::VariantArray;
+use arrow::error::Result;
+
+use arrow::array::{
+    Array, ArrayRef, ArrowPrimitiveType, AsArray, BinaryViewArray, 
NullBufferBuilder,
+    PrimitiveArray,
+};
+use arrow::compute::{cast_with_options, CastOptions};
+use arrow::datatypes::Int32Type;
+use arrow_schema::{ArrowError, FieldRef};
+use parquet_variant::{Variant, VariantPath};
+use std::marker::PhantomData;
+use std::sync::Arc;
+
+/// Trait for Arrow primitive types that can be used in the output builder
+///
+/// This just exists to add a generic way to convert from Variant to the 
primitive type
+pub(super) trait ArrowPrimitiveVariant: ArrowPrimitiveType {
+    /// Try to extract the primitive value from a Variant, returning None if it
+    /// cannot be converted
+    ///
+    /// TODO: figure out how to handle coercion/casting
+    fn from_variant(variant: &Variant) -> Option<Self::Native>;
+}
+
+/// Outputs Primitive arrays
+pub(super) struct PrimitiveOutputBuilder<'a, T: ArrowPrimitiveVariant> {
+    /// What path to extract
+    path: VariantPath<'a>,
+    /// Returned output type
+    as_type: FieldRef,
+    /// Controls the casting behavior (e.g. error vs substituting null on cast 
error).
+    cast_options: CastOptions<'a>,
+    /// Phantom data for the primitive type
+    _phantom: PhantomData<T>,
+}
+
+impl<'a, T: ArrowPrimitiveVariant> PrimitiveOutputBuilder<'a, T> {
+    pub(super) fn new(
+        path: VariantPath<'a>,
+        as_type: FieldRef,
+        cast_options: CastOptions<'a>,
+    ) -> Self {
+        Self {
+            path,
+            as_type,
+            cast_options,
+            _phantom: PhantomData,
+        }
+    }
+}
+
+impl<'a, T: ArrowPrimitiveVariant> OutputBuilder for 
PrimitiveOutputBuilder<'a, T> {
+    fn partially_shredded(
+        &self,
+        variant_array: &VariantArray,
+        _metadata: &BinaryViewArray,
+        _value_field: &BinaryViewArray,
+        typed_value: &ArrayRef,
+    ) -> arrow::error::Result<ArrayRef> {
+        // build up the output array element by element

Review Comment:
   This is an excellent call -- I have updated the names to match the shredding 
specification



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