superserious-dev commented on code in PR #8081: URL: https://github.com/apache/arrow-rs/pull/8081#discussion_r2261018868
########## parquet-variant-compute/src/cast_to_variant.rs: ########## @@ -40,17 +41,19 @@ macro_rules! primitive_conversion { }}; } -/// Convert the input array to a `VariantArray` row by row, -/// transforming each element with `cast_fn` +/// Convert the input array to a `VariantArray` row by row, using `method` +/// to downcast the generic array to a specific array type and `cast_fn` +/// to transform each element to a type compatible with Variant +/// Note that `cast_fn` returns a result because it could fail. macro_rules! cast_conversion { - ($t:ty, $cast_fn:expr, $input:expr, $builder:expr) => {{ - let array = $input.as_primitive::<$t>(); + ($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)); + let cast_value = $cast_fn(array.value(i))?; Review Comment: A potential downside to this tweak is that it forces the caller's closure to handle a Result even if the cast is known to be infallible, like the case of f16 -> f32. -- 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