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

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


The following commit(s) were added to refs/heads/master by this push:
     new aad6796deb [IOTDB-3364] Fix Query stucked with null valued aligned 
timeseries bug (#6120)
aad6796deb is described below

commit aad6796debacf0fc3272c154ab260b0bd3279977
Author: Jackie Tien <[email protected]>
AuthorDate: Wed Jun 1 17:16:39 2022 +0800

    [IOTDB-3364] Fix Query stucked with null valued aligned timeseries bug 
(#6120)
---
 .../db/integration/aligned/IoTDBEmptyDataIT.java   | 78 ++++++++++++++++++++++
 .../querycontext/AlignedReadOnlyMemChunk.java      | 13 ++--
 .../file/metadata/statistics/Statistics.java       | 20 +++---
 .../file/metadata/statistics/TimeStatistics.java   | 14 ++++
 4 files changed, 112 insertions(+), 13 deletions(-)

diff --git 
a/integration/src/test/java/org/apache/iotdb/db/integration/aligned/IoTDBEmptyDataIT.java
 
b/integration/src/test/java/org/apache/iotdb/db/integration/aligned/IoTDBEmptyDataIT.java
new file mode 100644
index 0000000000..269f0af6fd
--- /dev/null
+++ 
b/integration/src/test/java/org/apache/iotdb/db/integration/aligned/IoTDBEmptyDataIT.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iotdb.db.integration.aligned;
+
+import org.apache.iotdb.integration.env.EnvFactory;
+import org.apache.iotdb.itbase.category.ClusterTest;
+import org.apache.iotdb.itbase.category.LocalStandaloneTest;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+@Category({LocalStandaloneTest.class, ClusterTest.class})
+public class IoTDBEmptyDataIT {
+
+  @BeforeClass
+  public static void setUp() throws Exception {
+    EnvFactory.getEnv().initBeforeTest();
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+
+      statement.execute("create aligned timeseries root.sg.d1(s1 int32);");
+      statement.execute("insert into root.sg.d1(time, s1) aligned values(1400, 
null); ");
+    } catch (Exception e) {
+      e.printStackTrace();
+    }
+  }
+
+  @AfterClass
+  public static void tearDown() throws Exception {
+    EnvFactory.getEnv().cleanAfterTest();
+  }
+
+  @Test
+  public void selectAllAlignedWithoutValueFilterTest() {
+
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+
+      try (ResultSet resultSet = statement.executeQuery("select * from 
root.sg.d1")) {
+        int cnt = 0;
+        while (resultSet.next()) {
+          cnt++;
+        }
+        assertEquals(0, cnt);
+      }
+
+    } catch (SQLException e) {
+      e.printStackTrace();
+      fail(e.getMessage());
+    }
+  }
+}
diff --git 
a/server/src/main/java/org/apache/iotdb/db/engine/querycontext/AlignedReadOnlyMemChunk.java
 
b/server/src/main/java/org/apache/iotdb/db/engine/querycontext/AlignedReadOnlyMemChunk.java
index 14dd30b7e2..7641235e51 100644
--- 
a/server/src/main/java/org/apache/iotdb/db/engine/querycontext/AlignedReadOnlyMemChunk.java
+++ 
b/server/src/main/java/org/apache/iotdb/db/engine/querycontext/AlignedReadOnlyMemChunk.java
@@ -82,9 +82,6 @@ public class AlignedReadOnlyMemChunk extends ReadOnlyMemChunk 
{
     for (int column = 0; column < tsBlock.getValueColumnCount(); column++) {
       Statistics valueStatistics = 
Statistics.getStatsByType(dataTypes.get(column));
       valueStatistics.setEmpty(true);
-      IChunkMetadata valueChunkMetadata =
-          new ChunkMetadata(valueChunkNames.get(column), 
dataTypes.get(column), 0, valueStatistics);
-      valueChunkMetadataList.add(valueChunkMetadata);
       switch (dataTypes.get(column)) {
         case BOOLEAN:
           for (int row = 0; row < tsBlock.getPositionCount(); row++) {
@@ -137,7 +134,15 @@ public class AlignedReadOnlyMemChunk extends 
ReadOnlyMemChunk {
         default:
           throw new QueryProcessException("Unsupported data type:" + 
dataTypes.get(column));
       }
-      valueStatistics.setEmpty(false);
+      if (valueStatistics.getCount() > 0) {
+        IChunkMetadata valueChunkMetadata =
+            new ChunkMetadata(
+                valueChunkNames.get(column), dataTypes.get(column), 0, 
valueStatistics);
+        valueChunkMetadataList.add(valueChunkMetadata);
+        valueStatistics.setEmpty(false);
+      } else {
+        valueChunkMetadataList.add(null);
+      }
     }
     IChunkMetadata alignedChunkMetadata =
         new AlignedChunkMetadata(timeChunkMetadata, valueChunkMetadataList);
diff --git 
a/tsfile/src/main/java/org/apache/iotdb/tsfile/file/metadata/statistics/Statistics.java
 
b/tsfile/src/main/java/org/apache/iotdb/tsfile/file/metadata/statistics/Statistics.java
index a9fcec1b2a..012fbe729d 100644
--- 
a/tsfile/src/main/java/org/apache/iotdb/tsfile/file/metadata/statistics/Statistics.java
+++ 
b/tsfile/src/main/java/org/apache/iotdb/tsfile/file/metadata/statistics/Statistics.java
@@ -155,16 +155,18 @@ public abstract class Statistics<T extends Serializable> {
   @SuppressWarnings("unchecked")
   public void mergeStatistics(Statistics<? extends Serializable> stats) {
     if (this.getClass() == stats.getClass()) {
-      if (stats.startTime < this.startTime) {
-        this.startTime = stats.startTime;
+      if (!stats.isEmpty) {
+        if (stats.startTime < this.startTime) {
+          this.startTime = stats.startTime;
+        }
+        if (stats.endTime > this.endTime) {
+          this.endTime = stats.endTime;
+        }
+        // must be sure no overlap between two statistics
+        this.count += stats.count;
+        mergeStatisticsValue((Statistics<T>) stats);
+        isEmpty = false;
       }
-      if (stats.endTime > this.endTime) {
-        this.endTime = stats.endTime;
-      }
-      // must be sure no overlap between two statistics
-      this.count += stats.count;
-      mergeStatisticsValue((Statistics<T>) stats);
-      isEmpty = false;
     } else {
       Class<?> thisClass = this.getClass();
       Class<?> statsClass = stats.getClass();
diff --git 
a/tsfile/src/main/java/org/apache/iotdb/tsfile/file/metadata/statistics/TimeStatistics.java
 
b/tsfile/src/main/java/org/apache/iotdb/tsfile/file/metadata/statistics/TimeStatistics.java
index adc967ecc7..33fcad15cb 100644
--- 
a/tsfile/src/main/java/org/apache/iotdb/tsfile/file/metadata/statistics/TimeStatistics.java
+++ 
b/tsfile/src/main/java/org/apache/iotdb/tsfile/file/metadata/statistics/TimeStatistics.java
@@ -45,6 +45,20 @@ public class TimeStatistics extends Statistics<Long> {
     return 0;
   }
 
+  @Override
+  public void update(long time) {
+    super.update(time);
+    setEmpty(false);
+  }
+
+  @Override
+  public void update(long[] time, int batchSize) {
+    super.update(time, batchSize);
+    if (batchSize > 0) {
+      setEmpty(false);
+    }
+  }
+
   @Override
   public Long getMinValue() {
     throw new StatisticsClassException(String.format(STATS_UNSUPPORTED_MSG, 
TIME, "min value"));

Reply via email to