sdf-jkl commented on code in PR #9599:
URL: https://github.com/apache/arrow-rs/pull/9599#discussion_r3003775883


##########
parquet-variant-compute/src/variant_to_arrow.rs:
##########
@@ -714,22 +707,22 @@ macro_rules! define_variant_to_primitive_builder {
             }
 
             fn append_value(&mut self, $value: &Variant<'_, '_>) -> 
Result<bool> {
-                if let Some(v) = $value_transform {
+                if let Some(v) = variant_cast_with_options(
+                    $value,
+                    self.cast_options,
+                    |$value| $value_transform,
+                    |value| {
+                        format!(
+                            "Failed to extract primitive of type {type_name} 
from variant {value:?} at path VariantPath([])",
+                            type_name = $type_name
+                        )
+                    },
+                )? {
                     self.builder.append_value(v);
                     Ok(true)
                 } else {
-                    if treat_invalid_as_null(self.cast_options, $value) {
-                        // Safe casting (or variant null): append null on 
conversion failure
-                        self.builder.append_null();
-                        Ok(false)
-                    } else {
-                        // Unsafe casting: return error on conversion failure
-                        Err(ArrowError::CastError(format!(
-                            "Failed to extract primitive of type {} from 
variant {:?} at path VariantPath([])",
-                            $type_name,
-                            $value
-                        )))
-                    }
+                    self.builder.append_null();
+                    Ok(false)

Review Comment:
   Very true. I thought about using match, it's much more readable. Why didn't 
I do it :disappointed: 



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