You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@drill.apache.org by jn...@apache.org on 2016/12/20 04:27:33 UTC

[4/8] drill git commit: DRILL-5051: Fix incorrect computation of 'fetch' in LimitRecordBatch when 'offset' is specified

DRILL-5051: Fix incorrect computation of 'fetch' in LimitRecordBatch when 'offset' is specified

close apache/drill#662


Project: http://git-wip-us.apache.org/repos/asf/drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/d8cc7105
Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/d8cc7105
Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/d8cc7105

Branch: refs/heads/master
Commit: d8cc7105054953dc94afda0785f4d031a4ebbde1
Parents: 1c7309f
Author: hongze.zhz <ho...@alibaba-inc.com>
Authored: Fri Nov 18 20:11:38 2016 +0800
Committer: Jinfeng Ni <jn...@apache.org>
Committed: Mon Dec 19 15:57:32 2016 -0800

----------------------------------------------------------------------
 .../physical/impl/limit/LimitRecordBatch.java   | 35 ++++----------------
 .../java/org/apache/drill/TestBugFixes.java     | 10 ++++++
 2 files changed, 17 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/d8cc7105/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/limit/LimitRecordBatch.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/limit/LimitRecordBatch.java b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/limit/LimitRecordBatch.java
index 08ffc0b..254a297 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/limit/LimitRecordBatch.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/limit/LimitRecordBatch.java
@@ -139,18 +139,13 @@ public class LimitRecordBatch extends AbstractSingleRecordBatch<Limit> {
       skipBatch = true;
     } else {
       outgoingSv.allocateNew(recordCount);
-      if(incomingSv != null) {
-       limitWithSV(recordCount);
-      } else {
-       limitWithNoSV(recordCount);
-      }
+      limit(recordCount);
     }
 
     return IterOutcome.OK;
   }
 
-  // These two functions are identical except for the computation of the index; merge
-  private void limitWithNoSV(int recordCount) {
+  private void limit(int recordCount) {
     final int offset = Math.max(0, Math.min(recordCount - 1, recordsToSkip));
     recordsToSkip -= offset;
     int fetch;
@@ -164,27 +159,11 @@ public class LimitRecordBatch extends AbstractSingleRecordBatch<Limit> {
 
     int svIndex = 0;
     for(int i = offset; i < fetch; svIndex++, i++) {
-      outgoingSv.setIndex(svIndex, (char) i);
-    }
-    outgoingSv.setRecordCount(svIndex);
-  }
-
-  private void limitWithSV(int recordCount) {
-    final int offset = Math.max(0, Math.min(recordCount - 1, recordsToSkip));
-    recordsToSkip -= offset;
-    int fetch;
-
-    if(noEndLimit) {
-      fetch = recordCount;
-    } else {
-      fetch = Math.min(recordCount, recordsLeft);
-      recordsLeft -= Math.max(0, fetch - offset);
-    }
-
-    int svIndex = 0;
-    for(int i = offset; i < fetch; svIndex++, i++) {
-      final char index = incomingSv.getIndex(i);
-      outgoingSv.setIndex(svIndex, index);
+      if (incomingSv != null) {
+        outgoingSv.setIndex(svIndex, incomingSv.getIndex(i));
+      } else {
+        outgoingSv.setIndex(svIndex, (char) i);
+      }
     }
     outgoingSv.setRecordCount(svIndex);
   }

http://git-wip-us.apache.org/repos/asf/drill/blob/d8cc7105/exec/java-exec/src/test/java/org/apache/drill/TestBugFixes.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/TestBugFixes.java b/exec/java-exec/src/test/java/org/apache/drill/TestBugFixes.java
index 03b1b61..a9fc5d0 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/TestBugFixes.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/TestBugFixes.java
@@ -221,4 +221,14 @@ public class TestBugFixes extends BaseTestQuery {
             .baselineRecords(baseline)
             .go();
   }
+
+  @Test
+  public void testDRILL5051() throws Exception {
+    testBuilder()
+        .sqlQuery("select count(1) as cnt from (select l_orderkey from (select l_orderkey from cp.`tpch/lineitem.parquet` limit 2) limit 1 offset 1)")
+        .unOrdered()
+        .baselineColumns("cnt")
+        .baselineValues(1L)
+        .go();
+  }
 }