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

hui 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 a1f1c3c2df [IOTDB-3475] Fix ResultSet format for empty query (#6648)
a1f1c3c2df is described below

commit a1f1c3c2dfb9f52bad084cabc3c73aa99f7108bc
Author: liuminghui233 <[email protected]>
AuthorDate: Wed Jul 20 10:56:30 2022 +0800

    [IOTDB-3475] Fix ResultSet format for empty query (#6648)
---
 .../org/apache/iotdb/db/it/IoTDBSimpleQueryIT.java |  1 +
 .../apache/iotdb/db/it/query/IoTDBResultSetIT.java | 33 ++++++++++++++++++++++
 .../iotdb/db/mpp/common/header/DatasetHeader.java  |  2 ++
 .../memory/StatementMemorySourceVisitor.java       |  6 +++-
 .../apache/iotdb/db/utils/QueryDataSetUtils.java   |  4 +++
 5 files changed, 45 insertions(+), 1 deletion(-)

diff --git 
a/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBSimpleQueryIT.java 
b/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBSimpleQueryIT.java
index 6f4eae0920..be16f925a5 100644
--- 
a/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBSimpleQueryIT.java
+++ 
b/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBSimpleQueryIT.java
@@ -1066,6 +1066,7 @@ public class IoTDBSimpleQueryIT {
   }
 
   @Test
+  @Ignore // disable align is not supported yet
   public void testDisableAlign() throws Exception {
     try (Connection connection = EnvFactory.getEnv().getConnection();
         Statement statement = connection.createStatement()) {
diff --git 
a/integration-test/src/test/java/org/apache/iotdb/db/it/query/IoTDBResultSetIT.java
 
b/integration-test/src/test/java/org/apache/iotdb/db/it/query/IoTDBResultSetIT.java
index 3997852de9..ab0e72d405 100644
--- 
a/integration-test/src/test/java/org/apache/iotdb/db/it/query/IoTDBResultSetIT.java
+++ 
b/integration-test/src/test/java/org/apache/iotdb/db/it/query/IoTDBResultSetIT.java
@@ -39,6 +39,7 @@ import java.sql.Statement;
 import java.sql.Types;
 
 import static org.apache.iotdb.db.it.utils.TestUtils.prepareData;
+import static org.apache.iotdb.db.it.utils.TestUtils.resultSetEqualTest;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.fail;
 
@@ -53,10 +54,16 @@ public class IoTDBResultSetIT {
         "CREATE TIMESERIES root.t1.wf01.wt01.temperature WITH DATATYPE=FLOAT, 
ENCODING=RLE",
         "CREATE TIMESERIES root.t1.wf01.wt01.type WITH DATATYPE=INT32, 
ENCODING=RLE",
         "CREATE TIMESERIES root.t1.wf01.wt01.grade WITH DATATYPE=INT64, 
ENCODING=RLE",
+        "CREATE TIMESERIES root.t1.wf01.wt02.status WITH DATATYPE=BOOLEAN, 
ENCODING=PLAIN",
+        "CREATE TIMESERIES root.t1.wf01.wt02.temperature WITH DATATYPE=FLOAT, 
ENCODING=RLE",
+        "CREATE TIMESERIES root.t1.wf01.wt02.type WITH DATATYPE=INT32, 
ENCODING=RLE",
+        "CREATE TIMESERIES root.t1.wf01.wt02.grade WITH DATATYPE=INT64, 
ENCODING=RLE",
         "CREATE TIMESERIES root.sg.dev.status WITH 
DATATYPE=text,ENCODING=PLAIN",
         "insert into root.sg.dev(time,status) values(1,3.14)"
       };
 
+  private static final String[] emptyResultSet = new String[] {};
+
   @BeforeClass
   public static void setUp() throws Exception {
     EnvFactory.getEnv().initBeforeClass();
@@ -128,4 +135,30 @@ public class IoTDBResultSetIT {
       fail(e.getMessage());
     }
   }
+
+  @Test
+  public void emptyQueryTest1() {
+    String expectedHeader = "Time,";
+    resultSetEqualTest("select * from root.sg1.d1", expectedHeader, 
emptyResultSet);
+  }
+
+  @Test
+  public void emptyQueryTest2() {
+    String expectedHeader =
+        
"Time,root.t1.wf01.wt02.grade,root.t1.wf01.wt02.temperature,root.t1.wf01.wt02.type,root.t1.wf01.wt02.status,";
+    resultSetEqualTest("select * from root.t1.wf01.wt02", expectedHeader, 
emptyResultSet);
+  }
+
+  @Test
+  public void emptyShowTimeseriesTest() {
+    String expectedHeader =
+        "timeseries,alias,storage 
group,dataType,encoding,compression,tags,attributes,";
+    resultSetEqualTest("show timeseries root.sg1.**", expectedHeader, 
emptyResultSet);
+  }
+
+  @Test
+  public void emptyShowDeviceTest() {
+    String expectedHeader = "devices,isAligned,";
+    resultSetEqualTest("show devices root.sg1.**", expectedHeader, 
emptyResultSet);
+  }
 }
diff --git 
a/server/src/main/java/org/apache/iotdb/db/mpp/common/header/DatasetHeader.java 
b/server/src/main/java/org/apache/iotdb/db/mpp/common/header/DatasetHeader.java
index 4e270d2365..34680b5a2c 100644
--- 
a/server/src/main/java/org/apache/iotdb/db/mpp/common/header/DatasetHeader.java
+++ 
b/server/src/main/java/org/apache/iotdb/db/mpp/common/header/DatasetHeader.java
@@ -34,6 +34,8 @@ import java.util.stream.Collectors;
 /** The header of query result dataset. */
 public class DatasetHeader {
 
+  public static DatasetHeader EMPTY_HEADER = new DatasetHeader(new 
ArrayList<>(), false);
+
   // column names, data types and aliases of result dataset
   private final List<ColumnHeader> columnHeaders;
 
diff --git 
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/execution/memory/StatementMemorySourceVisitor.java
 
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/execution/memory/StatementMemorySourceVisitor.java
index 1fcca2f319..1f685f2425 100644
--- 
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/execution/memory/StatementMemorySourceVisitor.java
+++ 
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/execution/memory/StatementMemorySourceVisitor.java
@@ -53,12 +53,16 @@ import java.util.Set;
 import java.util.TreeSet;
 import java.util.stream.Collectors;
 
+import static org.apache.iotdb.db.mpp.common.header.DatasetHeader.EMPTY_HEADER;
+
 public class StatementMemorySourceVisitor
     extends StatementVisitor<StatementMemorySource, 
StatementMemorySourceContext> {
 
   @Override
   public StatementMemorySource visitNode(StatementNode node, 
StatementMemorySourceContext context) {
-    return new StatementMemorySource(new TsBlock(0), new DatasetHeader(new 
ArrayList<>(), false));
+    DatasetHeader datasetHeader = context.getAnalysis().getRespDatasetHeader();
+    return new StatementMemorySource(
+        new TsBlock(0), datasetHeader == null ? EMPTY_HEADER : datasetHeader);
   }
 
   @Override
diff --git 
a/server/src/main/java/org/apache/iotdb/db/utils/QueryDataSetUtils.java 
b/server/src/main/java/org/apache/iotdb/db/utils/QueryDataSetUtils.java
index f7e9640455..8b4ff934c3 100644
--- a/server/src/main/java/org/apache/iotdb/db/utils/QueryDataSetUtils.java
+++ b/server/src/main/java/org/apache/iotdb/db/utils/QueryDataSetUtils.java
@@ -203,6 +203,10 @@ public class QueryDataSetUtils {
         break;
       }
       TsBlock tsBlock = optionalTsBlock.get();
+      if (tsBlock.isEmpty()) {
+        continue;
+      }
+
       int currentCount = tsBlock.getPositionCount();
       // serialize time column
       for (int i = 0; i < currentCount; i++) {

Reply via email to