alamb commented on code in PR #7855:
URL: https://github.com/apache/arrow-rs/pull/7855#discussion_r2187136506


##########
arrow-array/src/array/union_array.rs:
##########
@@ -781,13 +781,23 @@ impl Array for UnionArray {
         };
 
         if fields.len() <= 1 {
-            return self
+            if let Some(logical_nulls) = self
                 .fields
                 .iter()
                 .flatten()
                 .map(Array::logical_nulls)
                 .next()
-                .flatten();
+                .flatten()
+            {
+                if logical_nulls.len() != self.len() {

Review Comment:
   I think you can make this significiantly simpler and just add a single check 
for dense nulls. This works for me locally:
   
   ```rust
               return self
                   .fields
                   .iter()
                   .flatten()
                   .map(Array::logical_nulls)
                   .next()
                   .flatten()
                   .map(|logical_nulls| {
                       if self.is_dense() {
                           // Dense union: gather nulls based on offsets
                           self.gather_nulls(vec![(0, logical_nulls)]).into()
                       } else {
                           // Sparse union: use the logical nulls directly
                           logical_nulls
                       }
                   })
   ```



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