klion26 commented on code in PR #8105:
URL: https://github.com/apache/arrow-rs/pull/8105#discussion_r2289911840


##########
parquet-variant-compute/src/type_conversion.rs:
##########
@@ -0,0 +1,166 @@
+// 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.
+
+//! Module for transforming a typed arrow `Array` to `VariantArray`.
+
+/// Convert the input array of a specific primitive type to a `VariantArray`
+/// row by row
+#[macro_export]
+macro_rules! primitive_conversion {
+    ($t:ty, $input:expr, $builder:expr) => {{
+        let array = $input.as_primitive::<$t>();
+        for i in 0..array.len() {
+            if array.is_null(i) {
+                $builder.append_null();
+                continue;
+            }
+            $builder.append_variant(Variant::from(array.value(i)));
+        }
+    }};
+}
+
+/// Convert the value at a specific index in the given array into a `Variant`.
+#[macro_export]
+macro_rules! primitive_conversion_single_value {
+    ($t:ty, $input:expr, $index:expr) => {{
+        let array = $input.as_primitive::<$t>();
+        if array.is_null($index) {
+            return Variant::Null;
+        }
+        Variant::from(array.value($index))
+    }};
+}
+
+/// Convert the input array to a `VariantArray` row by row, using `method`
+/// requiring a generic type to downcast the generic array to a specific
+/// array type and `cast_fn` to transform each element to a type compatible 
with Variant
+#[macro_export]
+macro_rules! generic_conversion_array {
+    ($t:ty, $method:ident, $cast_fn:expr, $input:expr, $builder:expr) => {{
+        let array = $input.$method::<$t>();
+        for i in 0..array.len() {
+            if array.is_null(i) {
+                $builder.append_null();
+                continue;
+            }
+            let cast_value = $cast_fn(array.value(i));
+            $builder.append_variant(Variant::from(cast_value));
+        }
+    }};
+}
+
+/// Convert the value at a specific index in the given array into a `Variant`,
+/// using `method` requiring a generic type to downcast the generic array
+/// to a specific array type and `cast_fn` to transform the element.
+#[macro_export]
+macro_rules! generic_conversion_single_value {
+    ($t:ty, $method:ident, $cast_fn:expr, $input:expr, $index:expr) => {{
+        let array = $input.$method::<$t>();
+        if array.is_null($index) {
+            return Variant::Null;
+        }
+        let cast_value = $cast_fn(array.value($index));
+        Variant::from(cast_value)
+    }};
+}
+
+/// Convert the input array to a `VariantArray` row by row, using `method`
+/// not requiring a generic type to downcast the generic array to a specific
+/// array type and `cast_fn` to transform each element to a type compatible 
with Variant
+#[macro_export]
+macro_rules! non_generic_conversion_array {
+    ($method:ident, $cast_fn:expr, $input:expr, $builder:expr) => {{
+        let array = $input.$method();

Review Comment:
   Added in a separate commit. The code looks cleaner than before. In the new 
version, there's something changed for the user. If we want to use the 
`primitive_conversion` macro, we may need to import the three macros(encounter 
this in `parquet-variant-compute/src/variant_get/output.variant.rs`).



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

Reply via email to