jecsand838 commented on code in PR #8348:
URL: https://github.com/apache/arrow-rs/pull/8348#discussion_r2360439152


##########
arrow-avro/src/schema.rs:
##########
@@ -970,13 +973,59 @@ fn merge_extras(schema: Value, mut extras: 
JsonMap<String, Value>) -> Value {
     }
 }
 
+#[inline]
+fn is_avro_json_null(v: &Value) -> bool {
+    matches!(v, Value::String(s) if s == "null")
+}
+
 fn wrap_nullable(inner: Value, null_order: Nullability) -> Value {
     let null = Value::String("null".into());
-    let elements = match null_order {
-        Nullability::NullFirst => vec![null, inner],
-        Nullability::NullSecond => vec![inner, null],
-    };
-    Value::Array(elements)
+    match inner {
+        Value::Array(mut union) => {
+            union.retain(|v| !is_avro_json_null(v));
+            match null_order {
+                Nullability::NullFirst => {
+                    let mut out = Vec::with_capacity(union.len() + 1);
+                    out.push(null);
+                    out.extend(union);
+                    Value::Array(out)
+                }
+                Nullability::NullSecond => {
+                    union.push(null);
+                    Value::Array(union)
+                }
+            }

Review Comment:
   This is much cleaner. 
   
   > (I guess it should really be called Nullability::NullLast?)
   
   100% That change is coming. Just wanted to get a dedicated follow-up PR for 
it.



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