This is an automated email from the ASF dual-hosted git repository.
jackietien 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 16980c20ec Handle the scenarios that there is no data for storage
group (#5782)
16980c20ec is described below
commit 16980c20ec88d2da6b0060930b199bad413f643e
Author: Zhang.Jinrui <[email protected]>
AuthorDate: Tue May 3 19:25:17 2022 +0800
Handle the scenarios that there is no data for storage group (#5782)
---
.../org/apache/iotdb/commons/partition/DataPartition.java | 5 +++++
.../java/org/apache/iotdb/commons/partition/Partition.java | 2 ++
.../org/apache/iotdb/commons/partition/SchemaPartition.java | 5 +++++
.../apache/iotdb/db/mpp/common/schematree/SchemaTree.java | 4 ++++
.../java/org/apache/iotdb/db/mpp/plan/analyze/Analysis.java | 5 +++++
.../java/org/apache/iotdb/db/mpp/plan/analyze/Analyzer.java | 8 +++++++-
.../apache/iotdb/db/mpp/plan/execution/QueryExecution.java | 12 ++++++++++--
7 files changed, 38 insertions(+), 3 deletions(-)
diff --git
a/node-commons/src/main/java/org/apache/iotdb/commons/partition/DataPartition.java
b/node-commons/src/main/java/org/apache/iotdb/commons/partition/DataPartition.java
index df98015fb6..a46b8bc246 100644
---
a/node-commons/src/main/java/org/apache/iotdb/commons/partition/DataPartition.java
+++
b/node-commons/src/main/java/org/apache/iotdb/commons/partition/DataPartition.java
@@ -41,6 +41,11 @@ public class DataPartition extends Partition {
super(seriesSlotExecutorName, seriesPartitionSlotNum);
}
+ @Override
+ public boolean isEmpty() {
+ return dataPartitionMap == null || dataPartitionMap.isEmpty();
+ }
+
public DataPartition(
Map<String, Map<TSeriesPartitionSlot, Map<TTimePartitionSlot,
List<TRegionReplicaSet>>>>
dataPartitionMap,
diff --git
a/node-commons/src/main/java/org/apache/iotdb/commons/partition/Partition.java
b/node-commons/src/main/java/org/apache/iotdb/commons/partition/Partition.java
index 839c330f90..426a9e6f50 100644
---
a/node-commons/src/main/java/org/apache/iotdb/commons/partition/Partition.java
+++
b/node-commons/src/main/java/org/apache/iotdb/commons/partition/Partition.java
@@ -38,4 +38,6 @@ public abstract class Partition {
protected TSeriesPartitionSlot calculateDeviceGroupId(String deviceName) {
return executor.getSeriesPartitionSlot(deviceName);
}
+
+ public abstract boolean isEmpty();
}
diff --git
a/node-commons/src/main/java/org/apache/iotdb/commons/partition/SchemaPartition.java
b/node-commons/src/main/java/org/apache/iotdb/commons/partition/SchemaPartition.java
index 586c380e54..9149d8139c 100644
---
a/node-commons/src/main/java/org/apache/iotdb/commons/partition/SchemaPartition.java
+++
b/node-commons/src/main/java/org/apache/iotdb/commons/partition/SchemaPartition.java
@@ -36,6 +36,11 @@ public class SchemaPartition extends Partition {
super(seriesSlotExecutorName, seriesPartitionSlotNum);
}
+ @Override
+ public boolean isEmpty() {
+ return schemaPartitionMap == null || schemaPartitionMap.isEmpty();
+ }
+
public SchemaPartition(
Map<String, Map<TSeriesPartitionSlot, TRegionReplicaSet>>
schemaPartitionMap,
String seriesSlotExecutorName,
diff --git
a/server/src/main/java/org/apache/iotdb/db/mpp/common/schematree/SchemaTree.java
b/server/src/main/java/org/apache/iotdb/db/mpp/common/schematree/SchemaTree.java
index bc5b1c8994..b62b0d1193 100644
---
a/server/src/main/java/org/apache/iotdb/db/mpp/common/schematree/SchemaTree.java
+++
b/server/src/main/java/org/apache/iotdb/db/mpp/common/schematree/SchemaTree.java
@@ -248,4 +248,8 @@ public class SchemaTree {
SchemaNode getRoot() {
return root;
}
+
+ public boolean isEmpty() {
+ return root.getChildren() == null || root.getChildren().size() == 0;
+ }
}
diff --git
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/Analysis.java
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/Analysis.java
index efdc5d11f0..d2837312cb 100644
--- a/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/Analysis.java
+++ b/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/Analysis.java
@@ -120,4 +120,9 @@ public class Analysis {
public void setTypeProvider(TypeProvider typeProvider) {
this.typeProvider = typeProvider;
}
+
+ public boolean hasDataSource() {
+ return (dataPartition != null && !dataPartition.isEmpty())
+ || (schemaPartition != null && !schemaPartition.isEmpty());
+ }
}
diff --git
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/Analyzer.java
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/Analyzer.java
index 8c0972f90e..26a90af04b 100644
--- a/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/Analyzer.java
+++ b/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/Analyzer.java
@@ -29,6 +29,7 @@ import
org.apache.iotdb.db.exception.sql.StatementAnalyzeException;
import org.apache.iotdb.db.metadata.path.PartialPath;
import org.apache.iotdb.db.mpp.common.MPPQueryContext;
import org.apache.iotdb.db.mpp.common.filter.QueryFilter;
+import org.apache.iotdb.db.mpp.common.header.DatasetHeader;
import org.apache.iotdb.db.mpp.common.header.HeaderConstant;
import org.apache.iotdb.db.mpp.common.schematree.PathPatternTree;
import org.apache.iotdb.db.mpp.common.schematree.SchemaTree;
@@ -117,7 +118,12 @@ public class Analyzer {
// request schema fetch API
SchemaTree schemaTree = schemaFetcher.fetchSchema(patternTree);
-
+ // (xingtanzjr) If there is no leaf node in the schema tree, the query
should be completed
+ // immediately
+ if (schemaTree.isEmpty()) {
+ analysis.setRespDatasetHeader(new DatasetHeader(new ArrayList<>(),
false));
+ return analysis;
+ }
// bind metadata, remove wildcards, and apply SLIMIT & SOFFSET
TypeProvider typeProvider = new TypeProvider();
rewrittenStatement =
diff --git
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/execution/QueryExecution.java
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/execution/QueryExecution.java
index 776a75d58e..dce5dccc71 100644
---
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/execution/QueryExecution.java
+++
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/execution/QueryExecution.java
@@ -135,6 +135,10 @@ public class QueryExecution implements IQueryExecution {
}
public void start() {
+ if (skipExecute()) {
+ stateMachine.transitionToFinished();
+ return;
+ }
doLogicalPlan();
doDistributedPlan();
if (context.getQueryType() == QueryType.READ) {
@@ -143,6 +147,10 @@ public class QueryExecution implements IQueryExecution {
schedule();
}
+ private boolean skipExecute() {
+ return context.getQueryType() == QueryType.READ &&
!analysis.hasDataSource();
+ }
+
// Analyze the statement in QueryContext. Generate the analysis this query
need
private static Analysis analyze(
Statement statement,
@@ -223,7 +231,7 @@ public class QueryExecution implements IQueryExecution {
@Override
public TsBlock getBatchResult() {
try {
- if (resultHandle.isAborted() || resultHandle.isFinished()) {
+ if (resultHandle == null || resultHandle.isAborted() ||
resultHandle.isFinished()) {
return null;
}
ListenableFuture<Void> blocked = resultHandle.isBlocked();
@@ -247,7 +255,7 @@ public class QueryExecution implements IQueryExecution {
/** @return true if there is more tsblocks, otherwise false */
@Override
public boolean hasNextResult() {
- return !resultHandle.isFinished();
+ return resultHandle != null && !resultHandle.isFinished();
}
/** return the result column count without the time column */