jayzhan211 commented on code in PR #27595:
URL: https://github.com/apache/datafusion/pull/27595#discussion_r4696640516


##########
datafusion/physical-plan/src/coalesce/mod.rs:
##########
@@ -307,6 +344,77 @@ mod tests {
         assert_next_batch_values(&mut coalescer, vec![1, 4, 5]);
     }
 
+    #[test]
+    fn test_push_batch_with_indices_and_fetch() {
+        let batch = uint32_batch(0..8);
+        let indices = UInt32Array::from(vec![7, 1, 5, 3]);
+        let mut coalescer = LimitedBatchCoalescer::new(batch.schema(), 100, 
Some(3));
+
+        assert_eq!(
+            coalescer.push_batch_with_indices(batch, &indices).unwrap(),
+            PushBatchStatus::LimitReached,
+        );
+        coalescer.finish().unwrap();
+        assert_next_batch_values(&mut coalescer, vec![7, 1, 5]);
+    }
+
+    #[test]
+    fn test_push_batch_with_indices_fetch_boundaries() {
+        let batch1 = uint32_batch(0..4);
+        let batch2 = uint32_batch(4..8);
+        let mut coalescer = LimitedBatchCoalescer::new(batch1.schema(), 2, 
Some(5));
+
+        assert_eq!(
+            coalescer
+                .push_batch_with_indices(batch1, &UInt32Array::from(vec![3, 
1]))
+                .unwrap(),
+            PushBatchStatus::Continue,
+        );
+        assert_eq!(
+            coalescer
+                .push_batch_with_indices(batch2, &UInt32Array::from(vec![2, 0, 
3, 1]))
+                .unwrap(),
+            PushBatchStatus::LimitReached,
+        );
+        coalescer.finish().unwrap();
+        assert_next_batch_values(&mut coalescer, vec![3, 1]);
+        assert_next_batch_values(&mut coalescer, vec![6, 4, 7]);
+    }
+
+    #[test]
+    fn test_push_batch_with_indices_empty_and_invalid() {
+        let batch = uint32_batch(0..4);
+        let mut coalescer = LimitedBatchCoalescer::new(batch.schema(), 2, 
None);
+        assert_eq!(
+            coalescer
+                .push_batch_with_indices(batch, 
&UInt32Array::from(Vec::<u32>::new()))
+                .unwrap(),
+            PushBatchStatus::Continue,
+        );
+        assert!(coalescer.is_empty());
+
+        for invalid_indices in [
+            Arc::new(BooleanArray::from(vec![true])) as Arc<dyn Array>,
+            Arc::new(UInt32Array::from(vec![4])) as Arc<dyn Array>,
+        ] {
+            let batch = uint32_batch(0..4);
+            let mut coalescer = LimitedBatchCoalescer::new(batch.schema(), 2, 
Some(1));
+            assert!(
+                coalescer
+                    .push_batch_with_indices(batch.clone(), 
invalid_indices.as_ref())
+                    .is_err()
+            );
+            assert_eq!(
+                coalescer
+                    .push_batch_with_indices(batch, 
&UInt32Array::from(vec![0]))
+                    .unwrap(),
+                PushBatchStatus::LimitReached,
+            );
+            coalescer.finish().unwrap();
+            assert_next_batch_values(&mut coalescer, vec![0]);
+        }
+    }

Review Comment:
   Optional cleanup: nothing tests a push after `LimitReached`. Removing the 
early return for "limit already reached" still passes every test here, and then 
a second push panics on `debug_assert!(remaining > 0)`. This test catches it:
   
   ```suggestion
       }
   
       #[test]
       fn test_push_batch_with_indices_after_limit_reached() {
           let batch = uint32_batch(0..8);
           let mut coalescer = LimitedBatchCoalescer::new(batch.schema(), 100, 
Some(2));
           assert_eq!(
               coalescer
                   .push_batch_with_indices(batch.clone(), 
&UInt32Array::from(vec![0, 1]))
                   .unwrap(),
               PushBatchStatus::LimitReached,
           );
           assert_eq!(
               coalescer
                   .push_batch_with_indices(batch, &UInt32Array::from(vec![4, 
5]))
                   .unwrap(),
               PushBatchStatus::LimitReached,
           );
           coalescer.finish().unwrap();
           assert_next_batch_values(&mut coalescer, vec![0, 1]);
           assert!(coalescer.next_completed_batch().is_none());
       }
   ```
   



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to