scovich commented on code in PR #8179:
URL: https://github.com/apache/arrow-rs/pull/8179#discussion_r2289375837
##########
parquet-variant-compute/src/variant_get/output/variant.rs:
##########
@@ -44,40 +85,103 @@ impl OutputBuilder for VariantOutputBuilder<'_> {
_value_field: &BinaryViewArray,
typed_value: &ArrayRef,
) -> arrow::error::Result<ArrayRef> {
- // in this case dispatch on the typed_value and
- // TODO macro'ize this using downcast! to handle all other primitive
types
// TODO(perf): avoid builders entirely (and write the raw variant
directly as we know the metadata is the same)
- let mut array_builder = VariantArrayBuilder::new(variant_array.len());
match typed_value.data_type() {
+ DataType::Int8 => {
+ cast_partially_shredded_primitive!(
+ typed_value,
+ variant_array,
+ Int8Type,
+ DataType::Int8
+ )
+ }
Review Comment:
aside: I'm a bit surprised that `fmt` didn't simplify these match arms:
```suggestion
DataType::Int8 => cast_partially_shredded_primitive!(
typed_value,
variant_array,
Int8Type,
DataType::Int8
),
```
##########
parquet-variant-compute/src/variant_get/output/variant.rs:
##########
@@ -18,11 +18,52 @@
use crate::variant_get::output::OutputBuilder;
use crate::{VariantArray, VariantArrayBuilder};
use arrow::array::{Array, ArrayRef, AsArray, BinaryViewArray};
-use arrow::datatypes::Int32Type;
+use arrow::datatypes::{
+ Float16Type, Float32Type, Float64Type, Int16Type, Int32Type, Int64Type,
Int8Type, UInt16Type,
+ UInt32Type, UInt64Type, UInt8Type,
+};
use arrow_schema::{ArrowError, DataType};
use parquet_variant::{Variant, VariantPath};
use std::sync::Arc;
+macro_rules! cast_perfectly_shredded_primitive {
+ ($typed_value:expr, $variant_array:expr, $arrow_type:ty, $data_type:expr)
=> {{
+ let mut array_builder = VariantArrayBuilder::new($variant_array.len());
+ let primitive_array = $typed_value.as_primitive::<$arrow_type>();
+ for i in 0..$variant_array.len() {
+ if primitive_array.is_null(i) {
+ array_builder.append_null();
+ } else {
+ let value = primitive_array.value(i);
+ array_builder.append_variant(Variant::from(value));
+ }
+ }
Review Comment:
if
https://github.com/apache/arrow-rs/pull/8105/files#diff-ed469f33b865066aa56a96aa5279ce67d4bf85ea34c7a8c12ffb16afef107b6fR23-R31
merges, this simplifies to:
```suggestion
primitive_conversion_array!($arrow_type, $typed_value,
array_builder);
```
TBD whether it's worth defining the macro just to turn 3 lines into one?
--
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]