You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by dh...@apache.org on 2023/01/25 18:30:32 UTC
[arrow-datafusion] branch fix_limit created (now d8590c0d1)
This is an automated email from the ASF dual-hosted git repository.
dheres pushed a change to branch fix_limit
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git
at d8590c0d1 Fix limit when size of batch to poll == batch size
This branch includes the following new commits:
new d8590c0d1 Fix limit when size of batch to poll == batch size
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[arrow-datafusion] 01/01: Fix limit when size of batch to poll == batch size
Posted by dh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
dheres pushed a commit to branch fix_limit
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git
commit d8590c0d1c6c12a59c971fb9d7fa19d7e52e13ba
Author: Daniƫl Heres <da...@coralogix.com>
AuthorDate: Wed Jan 25 19:30:21 2023 +0100
Fix limit when size of batch to poll == batch size
---
datafusion/core/src/physical_plan/limit.rs | 38 +++++++++++++++++++++++++++---
1 file changed, 35 insertions(+), 3 deletions(-)
diff --git a/datafusion/core/src/physical_plan/limit.rs b/datafusion/core/src/physical_plan/limit.rs
index 3fa900ca1..7f38e9201 100644
--- a/datafusion/core/src/physical_plan/limit.rs
+++ b/datafusion/core/src/physical_plan/limit.rs
@@ -417,7 +417,7 @@ impl LimitStream {
loop {
let poll = input.poll_next_unpin(cx);
let poll = poll.map_ok(|batch| {
- if batch.num_rows() <= self.skip {
+ if batch.num_rows() < self.skip {
self.skip -= batch.num_rows();
RecordBatch::new_empty(input.schema())
} else {
@@ -449,7 +449,8 @@ impl LimitStream {
if self.fetch == 0 {
self.input = None; // clear input so it can be dropped early
None
- } else if batch.num_rows() <= self.fetch {
+ } else if batch.num_rows() < self.fetch {
+ //
self.fetch -= batch.num_rows();
Some(batch)
} else {
@@ -542,7 +543,8 @@ mod tests {
#[tokio::test]
async fn limit_early_shutdown() -> Result<()> {
let batches = vec![
- test::make_partition(5),
+ //test::make_partition(5),
+ test::make_partition(6),
test::make_partition(10),
test::make_partition(15),
test::make_partition(20),
@@ -571,6 +573,36 @@ mod tests {
Ok(())
}
+ #[tokio::test]
+ async fn limit_equals_batch_size() -> Result<()> {
+ let batches = vec![
+ test::make_partition(6),
+ test::make_partition(6),
+ test::make_partition(6),
+ ];
+ let input = test::exec::TestStream::new(batches);
+
+ let index = input.index();
+ assert_eq!(index.value(), 0);
+
+ // limit of six needs to consume the entire first record batch
+ // (5 rows) and 1 row from the second (1 row)
+ let baseline_metrics = BaselineMetrics::new(&ExecutionPlanMetricsSet::new(), 0);
+ let limit_stream =
+ LimitStream::new(Box::pin(input), 0, Some(6), baseline_metrics);
+ assert_eq!(index.value(), 0);
+
+ let results = collect(Box::pin(limit_stream)).await.unwrap();
+ let num_rows: usize = results.into_iter().map(|b| b.num_rows()).sum();
+ // Only 6 rows should have been produced
+ assert_eq!(num_rows, 6);
+
+ // Only the first batch should be consumed
+ assert_eq!(index.value(), 1);
+
+ Ok(())
+ }
+
// test cases for "skip"
async fn skip_and_fetch(skip: usize, fetch: Option<usize>) -> Result<usize> {
let session_ctx = SessionContext::new();