Weijun-H commented on code in PR #25107:
URL: https://github.com/apache/datafusion/pull/25107#discussion_r3977021963


##########
datafusion/physical-plan/src/sorts/stream.rs:
##########
@@ -377,13 +377,15 @@ impl Iterator for IncrementalSortIterator {
     }
 
     fn size_hint(&self) -> (usize, Option<usize>) {
-        let num_rows = self.batch.num_rows();
+        let num_rows = self.batch.num_rows().saturating_sub(self.cursor);
         let batch_size = self.batch_size;
         let num_batches = num_rows.div_ceil(batch_size);
         (num_batches, Some(num_batches))
     }
 }
 
+impl ExactSizeIterator for IncrementalSortIterator {}

Review Comment:
   Could we omit `ExactSizeIterator` here? `next()` returns `Some(Err(_))` 
without advancing state when expression evaluation or sorting fails, so it can 
yield more items than `len()` promises. The remaining-row fix is valid on the 
success path, but does not establish an exact count on errors.



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