You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ro...@apache.org on 2021/05/13 10:11:08 UTC
[iotdb] branch iotdb-1022-v2 updated: refactor Planner and
LogicalGenerator
This is an automated email from the ASF dual-hosted git repository.
rong pushed a commit to branch iotdb-1022-v2
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/iotdb-1022-v2 by this push:
new f5b732b refactor Planner and LogicalGenerator
f5b732b is described below
commit f5b732b76931395369043a636bc50002c099b07c
Author: SteveYurongSu <st...@outlook.com>
AuthorDate: Thu May 13 18:10:39 2021 +0800
refactor Planner and LogicalGenerator
---
.../apache/iotdb/cluster/query/ClusterPlanner.java | 23 +++++++++++++++++
.../main/java/org/apache/iotdb/db/qp/Planner.java | 5 ++++
.../iotdb/db/qp/strategy/LogicalChecker.java | 30 ++++++++++++++++++++++
.../qp/strategy/optimizer/ConcatPathOptimizer.java | 13 +++++++++-
4 files changed, 70 insertions(+), 1 deletion(-)
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/query/ClusterPlanner.java b/cluster/src/main/java/org/apache/iotdb/cluster/query/ClusterPlanner.java
index f4e9ec4..259b900 100644
--- a/cluster/src/main/java/org/apache/iotdb/cluster/query/ClusterPlanner.java
+++ b/cluster/src/main/java/org/apache/iotdb/cluster/query/ClusterPlanner.java
@@ -19,12 +19,15 @@
package org.apache.iotdb.cluster.query;
+import org.apache.iotdb.db.exception.metadata.IllegalPathException;
import org.apache.iotdb.db.exception.query.QueryProcessException;
import org.apache.iotdb.db.qp.Planner;
import org.apache.iotdb.db.qp.logical.Operator;
import org.apache.iotdb.db.qp.physical.PhysicalPlan;
+import org.apache.iotdb.db.qp.strategy.LogicalChecker;
import org.apache.iotdb.db.qp.strategy.LogicalGenerator;
import org.apache.iotdb.db.qp.strategy.optimizer.ConcatPathOptimizer;
+import org.apache.iotdb.service.rpc.thrift.TSRawDataQueryReq;
import java.time.ZoneId;
@@ -34,12 +37,32 @@ public class ClusterPlanner extends Planner {
@Override
public PhysicalPlan parseSQLToPhysicalPlan(String sqlStr, ZoneId zoneId, int fetchSize)
throws QueryProcessException {
+ // from SQL to logical operator
Operator operator = LogicalGenerator.generate(sqlStr, zoneId);
+ // check if there are logical errors
+ LogicalChecker.check(operator);
+ // optimize the logical operator
operator = logicalOptimize(operator, fetchSize);
+ // from logical operator to physical plan
return new ClusterPhysicalGenerator().transformToPhysicalPlan(operator, fetchSize);
}
@Override
+ public PhysicalPlan rawDataQueryReqToPhysicalPlan(
+ TSRawDataQueryReq rawDataQueryReq, ZoneId zoneId)
+ throws IllegalPathException, QueryProcessException {
+ // from TSRawDataQueryReq to logical operator
+ Operator operator = LogicalGenerator.generate(rawDataQueryReq, zoneId);
+ // check if there are logical errors
+ LogicalChecker.check(operator);
+ // optimize the logical operator
+ operator = logicalOptimize(operator, rawDataQueryReq.fetchSize);
+ // from logical operator to physical plan
+ return new ClusterPhysicalGenerator()
+ .transformToPhysicalPlan(operator, rawDataQueryReq.fetchSize);
+ }
+
+ @Override
protected ConcatPathOptimizer getConcatPathOptimizer() {
return new ClusterConcatPathOptimizer();
}
diff --git a/server/src/main/java/org/apache/iotdb/db/qp/Planner.java b/server/src/main/java/org/apache/iotdb/db/qp/Planner.java
index 027468b..9ba0fb2 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/Planner.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/Planner.java
@@ -27,6 +27,7 @@ import org.apache.iotdb.db.qp.logical.Operator;
import org.apache.iotdb.db.qp.logical.crud.FilterOperator;
import org.apache.iotdb.db.qp.logical.crud.QueryOperator;
import org.apache.iotdb.db.qp.physical.PhysicalPlan;
+import org.apache.iotdb.db.qp.strategy.LogicalChecker;
import org.apache.iotdb.db.qp.strategy.LogicalGenerator;
import org.apache.iotdb.db.qp.strategy.PhysicalGenerator;
import org.apache.iotdb.db.qp.strategy.optimizer.ConcatPathOptimizer;
@@ -53,6 +54,8 @@ public class Planner {
throws QueryProcessException {
// from SQL to logical operator
Operator operator = LogicalGenerator.generate(sqlStr, zoneId);
+ // check if there are logical errors
+ LogicalChecker.check(operator);
// optimize the logical operator
operator = logicalOptimize(operator, fetchSize);
// from logical operator to physical plan
@@ -64,6 +67,8 @@ public class Planner {
throws IllegalPathException, QueryProcessException {
// from TSRawDataQueryReq to logical operator
Operator operator = LogicalGenerator.generate(rawDataQueryReq, zoneId);
+ // check if there are logical errors
+ LogicalChecker.check(operator);
// optimize the logical operator
operator = logicalOptimize(operator, rawDataQueryReq.fetchSize);
// from logical operator to physical plan
diff --git a/server/src/main/java/org/apache/iotdb/db/qp/strategy/LogicalChecker.java b/server/src/main/java/org/apache/iotdb/db/qp/strategy/LogicalChecker.java
new file mode 100644
index 0000000..78ce73c
--- /dev/null
+++ b/server/src/main/java/org/apache/iotdb/db/qp/strategy/LogicalChecker.java
@@ -0,0 +1,30 @@
+/*
+ * 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.qp.strategy;
+
+import org.apache.iotdb.db.exception.query.LogicalOperatorException;
+import org.apache.iotdb.db.qp.logical.Operator;
+
+public class LogicalChecker {
+
+ public static void check(Operator operator) throws LogicalOperatorException {}
+
+ private LogicalChecker() {}
+}
diff --git a/server/src/main/java/org/apache/iotdb/db/qp/strategy/optimizer/ConcatPathOptimizer.java b/server/src/main/java/org/apache/iotdb/db/qp/strategy/optimizer/ConcatPathOptimizer.java
index c77f67b..faee5e4 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/strategy/optimizer/ConcatPathOptimizer.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/strategy/optimizer/ConcatPathOptimizer.java
@@ -31,6 +31,7 @@ import org.apache.iotdb.db.qp.logical.crud.FromOperator;
import org.apache.iotdb.db.qp.logical.crud.FunctionOperator;
import org.apache.iotdb.db.qp.logical.crud.QueryOperator;
import org.apache.iotdb.db.qp.logical.crud.SelectOperator;
+import org.apache.iotdb.db.query.control.QueryResourceManager;
import org.apache.iotdb.db.query.udf.core.context.UDFContext;
import org.apache.iotdb.db.service.IoTDB;
import org.apache.iotdb.tsfile.utils.Pair;
@@ -53,8 +54,18 @@ public class ConcatPathOptimizer implements ILogicalOptimizer {
"failed to concat series paths because the given query operator didn't have prefix paths";
@Override
- public Operator transform(Operator operator, int maxDeduplicatedPathNum)
+ public Operator transform(Operator operator, int fetchSize)
throws LogicalOptimizeException, PathNumOverLimitException {
+ int maxDeduplicatedPathNum =
+ QueryResourceManager.getInstance().getMaxDeduplicatedPathNum(fetchSize);
+ if (operator instanceof QueryOperator && ((QueryOperator) operator).isLastQuery()) {
+ // Dataset of last query actually has only three columns, so we shouldn't limit the path num
+ // while constructing logical plan
+ // To avoid overflowing because logicalOptimize function may do maxDeduplicatedPathNum + 1, we
+ // set it to Integer.MAX_VALUE - 1
+ maxDeduplicatedPathNum = Integer.MAX_VALUE - 1;
+ }
+
QueryOperator queryOperator = (QueryOperator) operator;
FromOperator from = queryOperator.getFromOperator();
List<PartialPath> prefixPaths;