superserious-dev commented on code in PR #8081: URL: https://github.com/apache/arrow-rs/pull/8081#discussion_r2260876999
########## 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: New tweak to the macro here. Made `cast_fn` fallible so that an ArrowError::CastError can be returned if something goes wrong. -- 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