You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by xi...@apache.org on 2021/03/14 03:56:26 UTC

[iotdb] branch clusterQueryOpt updated (2cfb127 -> aa7cbcf)

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

xiangweiwei pushed a change to branch clusterQueryOpt
in repository https://gitbox.apache.org/repos/asf/iotdb.git.


    from 2cfb127  rename some parameters
     new 8a818c8  modify the sequence of setTimeFilter
     new aa7cbcf  optimize aggr result

The 2 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.


Summary of changes:
 .../iotdb/cluster/common/TestManagedSeriesReader.java  |  4 +---
 .../reader/RemoteSeriesReaderByTimestampTest.java      |  7 ++-----
 .../aggregation/impl/FirstValueDescAggrResult.java     |  3 ++-
 .../db/query/aggregation/impl/LastValueAggrResult.java | 13 ++++---------
 .../aggregation/impl/LastValueDescAggrResult.java      | 12 +++---------
 .../db/query/aggregation/impl/MaxTimeAggrResult.java   | 10 +++-------
 .../query/aggregation/impl/MaxTimeDescAggrResult.java  |  9 ++-------
 .../query/aggregation/impl/MinTimeDescAggrResult.java  |  3 ++-
 .../query/reader/series/SeriesReaderByTimestamp.java   | 18 ++++++++++--------
 9 files changed, 29 insertions(+), 50 deletions(-)


[iotdb] 01/02: modify the sequence of setTimeFilter

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

xiangweiwei pushed a commit to branch clusterQueryOpt
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit 8a818c88c606f84494ceab17928aec7b93ff264f
Author: Alima777 <wx...@gmail.com>
AuthorDate: Fri Mar 12 20:52:55 2021 +0800

    modify the sequence of setTimeFilter
---
 .../apache/iotdb/db/query/reader/series/SeriesReaderByTimestamp.java    | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/server/src/main/java/org/apache/iotdb/db/query/reader/series/SeriesReaderByTimestamp.java b/server/src/main/java/org/apache/iotdb/db/query/reader/series/SeriesReaderByTimestamp.java
index 8f0b04d..7653219 100644
--- a/server/src/main/java/org/apache/iotdb/db/query/reader/series/SeriesReaderByTimestamp.java
+++ b/server/src/main/java/org/apache/iotdb/db/query/reader/series/SeriesReaderByTimestamp.java
@@ -70,8 +70,8 @@ public class SeriesReaderByTimestamp implements IReaderByTimestamp {
   public Object[] getValuesInTimestamps(long[] timestamp, int length) throws IOException {
     Object[] results = new Object[length];
     int timeIndex;
+    seriesReader.setTimeFilter(timestamp[0]);
     for (timeIndex = 0; timeIndex < length; timeIndex++) {
-      seriesReader.setTimeFilter(timestamp[0]);
       if ((batchData == null || !hasAvailableData(batchData, timestamp[timeIndex]))
           && !hasNext(timestamp[timeIndex])) {
         // there is no more data


[iotdb] 02/02: optimize aggr result

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

xiangweiwei pushed a commit to branch clusterQueryOpt
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit aa7cbcf9d538a989dccdc0e197f4bcab8c17a623
Author: Alima777 <wx...@gmail.com>
AuthorDate: Sun Mar 14 11:55:56 2021 +0800

    optimize aggr result
---
 .../iotdb/cluster/common/TestManagedSeriesReader.java  |  4 +---
 .../reader/RemoteSeriesReaderByTimestampTest.java      |  7 ++-----
 .../aggregation/impl/FirstValueDescAggrResult.java     |  3 ++-
 .../db/query/aggregation/impl/LastValueAggrResult.java | 13 ++++---------
 .../aggregation/impl/LastValueDescAggrResult.java      | 12 +++---------
 .../db/query/aggregation/impl/MaxTimeAggrResult.java   | 10 +++-------
 .../query/aggregation/impl/MaxTimeDescAggrResult.java  |  9 ++-------
 .../query/aggregation/impl/MinTimeDescAggrResult.java  |  3 ++-
 .../query/reader/series/SeriesReaderByTimestamp.java   | 18 ++++++++++--------
 9 files changed, 29 insertions(+), 50 deletions(-)

diff --git a/cluster/src/test/java/org/apache/iotdb/cluster/common/TestManagedSeriesReader.java b/cluster/src/test/java/org/apache/iotdb/cluster/common/TestManagedSeriesReader.java
index 6f220e4..cbd9bb6 100644
--- a/cluster/src/test/java/org/apache/iotdb/cluster/common/TestManagedSeriesReader.java
+++ b/cluster/src/test/java/org/apache/iotdb/cluster/common/TestManagedSeriesReader.java
@@ -59,12 +59,10 @@ public class TestManagedSeriesReader implements ManagedSeriesReader, IReaderByTi
   @Override
   public Object[] getValuesInTimestamps(long[] timestamps, int length) {
     Object[] results = new Object[length];
-    boolean hasValue = false;
     for (int i = 0; i < length; i++) {
       while (batchData.hasCurrent()) {
         long currTime = batchData.currentTime();
         if (currTime == timestamps[i]) {
-          hasValue = true;
           results[i] = batchData.currentValue();
           break;
         } else if (currTime > timestamps[i]) {
@@ -74,7 +72,7 @@ public class TestManagedSeriesReader implements ManagedSeriesReader, IReaderByTi
         batchData.next();
       }
     }
-    return hasValue ? results : null;
+    return results;
   }
 
   @Override
diff --git a/cluster/src/test/java/org/apache/iotdb/cluster/query/reader/RemoteSeriesReaderByTimestampTest.java b/cluster/src/test/java/org/apache/iotdb/cluster/query/reader/RemoteSeriesReaderByTimestampTest.java
index b8a4706..ef2772e 100644
--- a/cluster/src/test/java/org/apache/iotdb/cluster/query/reader/RemoteSeriesReaderByTimestampTest.java
+++ b/cluster/src/test/java/org/apache/iotdb/cluster/query/reader/RemoteSeriesReaderByTimestampTest.java
@@ -83,7 +83,6 @@ public class RemoteSeriesReaderByTimestampTest {
                           ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                           DataOutputStream dataOutputStream =
                               new DataOutputStream(byteArrayOutputStream);
-                          boolean isNull = true;
                           Object[] results = new Object[timestamps.size()];
                           for (int i = 0; i < timestamps.size(); i++) {
                             while (batchData.hasCurrent()) {
@@ -91,7 +90,6 @@ public class RemoteSeriesReaderByTimestampTest {
                               if (currentTime == timestamps.get(i)) {
                                 results[i] = batchData.currentValue();
                                 batchData.next();
-                                isNull = false;
                                 break;
                               } else if (currentTime > timestamps.get(i)) {
                                 results[i] = null;
@@ -101,8 +99,7 @@ public class RemoteSeriesReaderByTimestampTest {
                               batchData.next();
                             }
                           }
-                          SerializeUtils.serializeObjects(
-                              isNull ? new Object[0] : results, dataOutputStream);
+                          SerializeUtils.serializeObjects(results, dataOutputStream);
 
                           resultHandler.onComplete(
                               ByteBuffer.wrap(byteArrayOutputStream.toByteArray()));
@@ -158,7 +155,7 @@ public class RemoteSeriesReaderByTimestampTest {
         assertEquals(i * 1.0, results[i]);
       }
       times[0] = 101;
-      assertEquals(0, reader.getValuesInTimestamps(times, 1).length);
+      assertEquals(null, reader.getValuesInTimestamps(times, 1)[0]);
     } finally {
       QueryResourceManager.getInstance().endQuery(context.getQueryId());
     }
diff --git a/server/src/main/java/org/apache/iotdb/db/query/aggregation/impl/FirstValueDescAggrResult.java b/server/src/main/java/org/apache/iotdb/db/query/aggregation/impl/FirstValueDescAggrResult.java
index ad682d4..91d71a6 100644
--- a/server/src/main/java/org/apache/iotdb/db/query/aggregation/impl/FirstValueDescAggrResult.java
+++ b/server/src/main/java/org/apache/iotdb/db/query/aggregation/impl/FirstValueDescAggrResult.java
@@ -54,10 +54,11 @@ public class FirstValueDescAggrResult extends FirstValueAggrResult {
   public void updateResultUsingTimestamps(
       long[] timestamps, int length, IReaderByTimestamp dataReader) throws IOException {
     Object[] values = dataReader.getValuesInTimestamps(timestamps, length);
-    for (int i = 0; i < length; i++) {
+    for (int i = length - 1; i >= 0; i--) {
       if (values[i] != null) {
         setValue(values[i]);
         timestamp = timestamps[i];
+        return;
       }
     }
   }
diff --git a/server/src/main/java/org/apache/iotdb/db/query/aggregation/impl/LastValueAggrResult.java b/server/src/main/java/org/apache/iotdb/db/query/aggregation/impl/LastValueAggrResult.java
index bf21f7b..04cb67e 100644
--- a/server/src/main/java/org/apache/iotdb/db/query/aggregation/impl/LastValueAggrResult.java
+++ b/server/src/main/java/org/apache/iotdb/db/query/aggregation/impl/LastValueAggrResult.java
@@ -85,19 +85,14 @@ public class LastValueAggrResult extends AggregateResult {
   @Override
   public void updateResultUsingTimestamps(
       long[] timestamps, int length, IReaderByTimestamp dataReader) throws IOException {
-    long time = Long.MIN_VALUE;
-    Object lastVal = null;
     Object[] values = dataReader.getValuesInTimestamps(timestamps, length);
-    for (int i = 0; i < length; i++) {
+    for (int i = length - 1; i >= 0; i--) {
       if (values[i] != null) {
-        time = timestamps[i];
-        lastVal = values[i];
+        timestamp = timestamps[i];
+        setValue(values[i]);
+        return;
       }
     }
-    if (time != Long.MIN_VALUE) {
-      setValue(lastVal);
-      timestamp = time;
-    }
   }
 
   @Override
diff --git a/server/src/main/java/org/apache/iotdb/db/query/aggregation/impl/LastValueDescAggrResult.java b/server/src/main/java/org/apache/iotdb/db/query/aggregation/impl/LastValueDescAggrResult.java
index 354a360..8cdeaed 100644
--- a/server/src/main/java/org/apache/iotdb/db/query/aggregation/impl/LastValueDescAggrResult.java
+++ b/server/src/main/java/org/apache/iotdb/db/query/aggregation/impl/LastValueDescAggrResult.java
@@ -68,20 +68,14 @@ public class LastValueDescAggrResult extends LastValueAggrResult {
     if (hasFinalResult()) {
       return;
     }
-    long time = Long.MIN_VALUE;
-    Object lastVal = null;
     Object[] values = dataReader.getValuesInTimestamps(timestamps, length);
     for (int i = 0; i < length; i++) {
       if (values[i] != null) {
-        time = timestamps[i];
-        lastVal = values[i];
-        break;
+        timestamp = timestamps[i];
+        setValue(values[i]);
+        return;
       }
     }
-    if (time != Long.MIN_VALUE) {
-      setValue(lastVal);
-      timestamp = time;
-    }
   }
 
   @Override
diff --git a/server/src/main/java/org/apache/iotdb/db/query/aggregation/impl/MaxTimeAggrResult.java b/server/src/main/java/org/apache/iotdb/db/query/aggregation/impl/MaxTimeAggrResult.java
index df19df6..321bc78 100644
--- a/server/src/main/java/org/apache/iotdb/db/query/aggregation/impl/MaxTimeAggrResult.java
+++ b/server/src/main/java/org/apache/iotdb/db/query/aggregation/impl/MaxTimeAggrResult.java
@@ -66,17 +66,13 @@ public class MaxTimeAggrResult extends AggregateResult {
   @Override
   public void updateResultUsingTimestamps(
       long[] timestamps, int length, IReaderByTimestamp dataReader) throws IOException {
-    long time = -1;
     Object[] values = dataReader.getValuesInTimestamps(timestamps, length);
-    for (int i = 0; i < length; i++) {
+    for (int i = length - 1; i >= 0; i--) {
       if (values[i] != null) {
-        time = timestamps[i];
+        updateMaxTimeResult(timestamps[i]);
+        return;
       }
     }
-
-    if (time != -1) {
-      updateMaxTimeResult(time);
-    }
   }
 
   @Override
diff --git a/server/src/main/java/org/apache/iotdb/db/query/aggregation/impl/MaxTimeDescAggrResult.java b/server/src/main/java/org/apache/iotdb/db/query/aggregation/impl/MaxTimeDescAggrResult.java
index 3e1bc91..82d6c4e 100644
--- a/server/src/main/java/org/apache/iotdb/db/query/aggregation/impl/MaxTimeDescAggrResult.java
+++ b/server/src/main/java/org/apache/iotdb/db/query/aggregation/impl/MaxTimeDescAggrResult.java
@@ -52,18 +52,13 @@ public class MaxTimeDescAggrResult extends MaxTimeAggrResult {
     if (hasFinalResult()) {
       return;
     }
-    long time = -1;
     Object[] values = dataReader.getValuesInTimestamps(timestamps, length);
     for (int i = 0; i < length; i++) {
       if (values[i] != null) {
-        time = timestamps[i];
-        break;
+        updateMaxTimeResult(timestamps[i]);
+        return;
       }
     }
-
-    if (time != -1) {
-      updateMaxTimeResult(time);
-    }
   }
 
   @Override
diff --git a/server/src/main/java/org/apache/iotdb/db/query/aggregation/impl/MinTimeDescAggrResult.java b/server/src/main/java/org/apache/iotdb/db/query/aggregation/impl/MinTimeDescAggrResult.java
index 3cb1fbb..2e65be3 100644
--- a/server/src/main/java/org/apache/iotdb/db/query/aggregation/impl/MinTimeDescAggrResult.java
+++ b/server/src/main/java/org/apache/iotdb/db/query/aggregation/impl/MinTimeDescAggrResult.java
@@ -44,9 +44,10 @@ public class MinTimeDescAggrResult extends MinTimeAggrResult {
   public void updateResultUsingTimestamps(
       long[] timestamps, int length, IReaderByTimestamp dataReader) throws IOException {
     Object[] values = dataReader.getValuesInTimestamps(timestamps, length);
-    for (int i = 0; i < length; i++) {
+    for (int i = length - 1; i >= 0; i--) {
       if (values[i] != null) {
         setLongValue(timestamps[i]);
+        return;
       }
     }
   }
diff --git a/server/src/main/java/org/apache/iotdb/db/query/reader/series/SeriesReaderByTimestamp.java b/server/src/main/java/org/apache/iotdb/db/query/reader/series/SeriesReaderByTimestamp.java
index 7653219..69d3248 100644
--- a/server/src/main/java/org/apache/iotdb/db/query/reader/series/SeriesReaderByTimestamp.java
+++ b/server/src/main/java/org/apache/iotdb/db/query/reader/series/SeriesReaderByTimestamp.java
@@ -67,20 +67,22 @@ public class SeriesReaderByTimestamp implements IReaderByTimestamp {
   }
 
   @Override
-  public Object[] getValuesInTimestamps(long[] timestamp, int length) throws IOException {
+  public Object[] getValuesInTimestamps(long[] timestamps, int length) throws IOException {
+    if (length <= 0) {
+      return null;
+    }
     Object[] results = new Object[length];
-    int timeIndex;
-    seriesReader.setTimeFilter(timestamp[0]);
-    for (timeIndex = 0; timeIndex < length; timeIndex++) {
-      if ((batchData == null || !hasAvailableData(batchData, timestamp[timeIndex]))
-          && !hasNext(timestamp[timeIndex])) {
+    seriesReader.setTimeFilter(timestamps[0]);
+    for (int i = 0; i < length; i++) {
+      if ((batchData == null || !hasAvailableData(batchData, timestamps[i]))
+          && !hasNext(timestamps[i])) {
         // there is no more data
         break;
       }
-      results[timeIndex] = batchData.getValueInTimestamp(timestamp[timeIndex]);
+      results[i] = batchData.getValueInTimestamp(timestamps[i]);
     }
 
-    return timeIndex != 0 ? results : null;
+    return results;
   }
 
   @Override