You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by qi...@apache.org on 2020/02/26 02:07:33 UTC

[incubator-iotdb] branch fix_return_null created (now 140827d)

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

qiaojialin pushed a change to branch fix_return_null
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git.


      at 140827d  return empty dataset instead of throw exception

This branch includes the following new commits:

     new 140827d  return empty dataset instead of throw exception

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.



[incubator-iotdb] 01/01: return empty dataset instead of throw exception

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

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

commit 140827d661b7ca153f920567688ac0936b003c27
Author: qiaojialin <64...@qq.com>
AuthorDate: Wed Feb 26 10:07:50 2020 +0800

    return empty dataset instead of throw exception
---
 .../src/main/java/org/apache/iotdb/JDBCExample.java |  2 +-
 .../org/apache/iotdb/jdbc/IoTDBResultMetadata.java  |  5 +----
 .../apache/iotdb/db/qp/executor/PlanExecutor.java   |  6 +++++-
 .../tsfile/read/query/dataset/EmptyDataSet.java     | 21 +++++++++++++++++++++
 4 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/example/jdbc/src/main/java/org/apache/iotdb/JDBCExample.java b/example/jdbc/src/main/java/org/apache/iotdb/JDBCExample.java
index 99a6193..011fba1 100644
--- a/example/jdbc/src/main/java/org/apache/iotdb/JDBCExample.java
+++ b/example/jdbc/src/main/java/org/apache/iotdb/JDBCExample.java
@@ -46,7 +46,7 @@ public class JDBCExample {
       outputResult(resultSet);
       resultSet = statement.executeQuery("select count(*) from root");
       outputResult(resultSet);
-      resultSet = statement.executeQuery("select count(*) from root where time >= 1 and time <= 100 group by ([0, 100], 20ms, 20ms)");
+      resultSet = statement.executeQuery("select count(*) from root where time >= 1 and time <= 100 group by ([0, 100), 20ms, 20ms)");
       outputResult(resultSet);
     }
   }
diff --git a/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBResultMetadata.java b/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBResultMetadata.java
index 25e88bd..e0af511 100644
--- a/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBResultMetadata.java
+++ b/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBResultMetadata.java
@@ -59,10 +59,7 @@ public class IoTDBResultMetadata implements ResultSetMetaData {
   }
 
   @Override
-  public int getColumnCount() throws SQLException {
-    if (columnInfoList == null || columnInfoList.isEmpty()) {
-      throw new SQLException("No column exists");
-    }
+  public int getColumnCount() {
     return columnInfoList.size();
   }
 
diff --git a/server/src/main/java/org/apache/iotdb/db/qp/executor/PlanExecutor.java b/server/src/main/java/org/apache/iotdb/db/qp/executor/PlanExecutor.java
index 2cf135d..a489c34 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/executor/PlanExecutor.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/executor/PlanExecutor.java
@@ -117,6 +117,7 @@ import org.apache.iotdb.tsfile.read.TsFileSequenceReader;
 import org.apache.iotdb.tsfile.read.common.Field;
 import org.apache.iotdb.tsfile.read.common.Path;
 import org.apache.iotdb.tsfile.read.common.RowRecord;
+import org.apache.iotdb.tsfile.read.query.dataset.EmptyDataSet;
 import org.apache.iotdb.tsfile.read.query.dataset.QueryDataSet;
 import org.apache.iotdb.tsfile.utils.Binary;
 import org.apache.iotdb.tsfile.utils.Pair;
@@ -225,7 +226,10 @@ public class PlanExecutor implements IPlanExecutor {
       throws StorageEngineException, QueryFilterOptimizationException, QueryProcessException,
       IOException {
     QueryDataSet queryDataSet;
-    if (queryPlan instanceof AlignByDevicePlan) {
+    if (queryPlan.getPaths().isEmpty()) {
+      // no time series are selected, return EmptyDataSet
+      queryDataSet = new EmptyDataSet();
+    } else if (queryPlan instanceof AlignByDevicePlan) {
       queryDataSet = new AlignByDeviceDataSet((AlignByDevicePlan) queryPlan, context, queryRouter);
     } else {
       if (queryPlan instanceof GroupByPlan) {
diff --git a/tsfile/src/main/java/org/apache/iotdb/tsfile/read/query/dataset/EmptyDataSet.java b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/query/dataset/EmptyDataSet.java
new file mode 100644
index 0000000..213a7c2
--- /dev/null
+++ b/tsfile/src/main/java/org/apache/iotdb/tsfile/read/query/dataset/EmptyDataSet.java
@@ -0,0 +1,21 @@
+package org.apache.iotdb.tsfile.read.query.dataset;
+
+import java.util.Collections;
+import org.apache.iotdb.tsfile.read.common.RowRecord;
+
+public class EmptyDataSet extends QueryDataSet {
+
+  public EmptyDataSet() {
+    super(Collections.emptyList(), Collections.emptyList());
+  }
+
+  @Override
+  protected boolean hasNextWithoutConstraint() {
+    return false;
+  }
+
+  @Override
+  protected RowRecord nextWithoutConstraint() {
+    return null;
+  }
+}