You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by hu...@apache.org on 2023/03/22 08:56:24 UTC

[iotdb] branch lmh/fixLimitBug created (now e07253773f)

This is an automated email from the ASF dual-hosted git repository.

hui pushed a change to branch lmh/fixLimitBug
in repository https://gitbox.apache.org/repos/asf/iotdb.git


      at e07253773f fix order bug

This branch includes the following new commits:

     new e07253773f fix order bug

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.



[iotdb] 01/01: fix order bug

Posted by hu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

hui pushed a commit to branch lmh/fixLimitBug
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit e07253773f06253ed7e2440c968f33db968c88bb
Author: Minghui Liu <li...@foxmail.com>
AuthorDate: Wed Mar 22 16:52:44 2023 +0800

    fix order bug
---
 .../execution/operator/source/SeriesScanUtil.java  | 11 ++++--
 .../read/reader/series/PaginationController.java   | 44 +++++++++++++++++++---
 2 files changed, 46 insertions(+), 9 deletions(-)

diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/source/SeriesScanUtil.java b/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/source/SeriesScanUtil.java
index 755795447f..0dbd911adf 100644
--- a/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/source/SeriesScanUtil.java
+++ b/server/src/main/java/org/apache/iotdb/db/mpp/execution/operator/source/SeriesScanUtil.java
@@ -1112,7 +1112,7 @@ public class SeriesScanUtil {
     return scanOptions.getGlobalTimeFilter();
   }
 
-  protected static class VersionPageReader {
+  protected class VersionPageReader {
 
     private final PriorityMergeReader.MergeReaderPriority version;
     private final IPageReader data;
@@ -1150,11 +1150,16 @@ public class SeriesScanUtil {
     TsBlock getAllSatisfiedPageData(boolean ascending) throws IOException {
       long startTime = System.nanoTime();
       try {
+        paginationController.setEnable(ascending);
         TsBlock tsBlock = data.getAllSatisfiedData();
-        if (!ascending) {
+        paginationController.setEnable(true);
+
+        if (ascending) {
+          return tsBlock;
+        } else {
           tsBlock.reverse();
+          return paginationController.applyTsBlock(tsBlock);
         }
-        return tsBlock;
       } finally {
         QUERY_METRICS.recordSeriesScanCost(
             isAligned
diff --git a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/reader/series/PaginationController.java b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/reader/series/PaginationController.java
index a35867645a..5d0f41b970 100644
--- a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/reader/series/PaginationController.java
+++ b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/reader/series/PaginationController.java
@@ -19,6 +19,8 @@
 
 package org.apache.iotdb.tsfile.read.reader.series;
 
+import org.apache.iotdb.tsfile.read.common.block.TsBlock;
+
 public class PaginationController {
 
   public static final PaginationController UNLIMITED_PAGINATION_CONTROLLER =
@@ -29,6 +31,8 @@ public class PaginationController {
   private long curLimit;
   private long curOffset;
 
+  private boolean enable = true;
+
   public PaginationController(long limit, long offset) {
     // row limit for result set. The default value is 0, which means no limit
     this.curLimit = limit;
@@ -38,29 +42,57 @@ public class PaginationController {
     this.curOffset = offset;
   }
 
+  public void setEnable(boolean enable) {
+    this.enable = enable;
+  }
+
   public boolean hasCurOffset() {
-    return curOffset > 0;
+    return enable && curOffset > 0;
   }
 
   public boolean hasCurOffset(long rowCount) {
-    return curOffset >= rowCount;
+    return enable && curOffset >= rowCount;
   }
 
   public boolean hasCurLimit() {
-    return !hasLimit || curLimit > 0;
+    return !enable || (!hasLimit || curLimit > 0);
   }
 
   public void consumeOffset(long rowCount) {
-    curOffset -= rowCount;
+    if (enable) {
+      curOffset -= rowCount;
+    }
   }
 
   public void consumeOffset() {
-    curOffset--;
+    if (enable) {
+      curOffset--;
+    }
   }
 
   public void consumeLimit() {
-    if (hasLimit) {
+    if (enable && hasLimit) {
       curLimit--;
     }
   }
+
+  public void consumeLimit(long rowCount) {
+    if (enable && hasLimit) {
+      curLimit -= rowCount;
+    }
+  }
+
+  public TsBlock applyTsBlock(TsBlock resultTsBlock) {
+    int fromIndex = 0, length = resultTsBlock.getPositionCount();
+    if (hasCurOffset()) {
+      fromIndex = (int) Math.min(curOffset, length);
+      length -= fromIndex;
+      consumeOffset(fromIndex);
+    }
+    if (hasCurLimit()) {
+      length = (int) Math.min(curLimit, length);
+      consumeLimit(length);
+    }
+    return resultTsBlock.getRegion(fromIndex, length);
+  }
 }