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/07/14 11:47:53 UTC
[iotdb] branch select-into created (now 850f2c0)
This is an automated email from the ASF dual-hosted git repository.
rong pushed a change to branch select-into
in repository https://gitbox.apache.org/repos/asf/iotdb.git.
at 850f2c0 modify TSServiceImpl
This branch includes the following new commits:
new 862afe4 antlr grammer for select into
new f5706f2 fix IoTDBSqlVisitor parsing error
new d5413d3 from sql visitor to logical operator
new a710990 physical plan
new cfa6ec8 auth
new b3a8847 make select-into plan a query plan
new f0c5770 refactor internalExecuteQueryStatement
new 850f2c0 modify TSServiceImpl
The 8 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.
[iotdb] 04/08: physical plan
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rong pushed a commit to branch select-into
in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit a710990edbb04e441d7d884b5b9861ea5e0b12c9
Author: Steve Yurong Su <ro...@apache.org>
AuthorDate: Tue Jul 13 17:14:43 2021 +0800
physical plan
---
.../main/java/org/apache/iotdb/db/qp/Planner.java | 22 ++++++--
.../db/qp/logical/crud/SelectIntoOperator.java | 16 ++++++
.../apache/iotdb/db/qp/physical/PhysicalPlan.java | 6 +-
.../iotdb/db/qp/physical/crud/SelectIntoPlan.java | 66 ++++++++++++++++++++++
.../iotdb/db/qp/strategy/LogicalChecker.java | 5 ++
5 files changed, 108 insertions(+), 7 deletions(-)
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 b12f8ce..28797c4 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
@@ -26,6 +26,7 @@ import org.apache.iotdb.db.exception.query.QueryProcessException;
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.logical.crud.SelectIntoOperator;
import org.apache.iotdb.db.qp.logical.crud.WhereComponent;
import org.apache.iotdb.db.qp.physical.PhysicalPlan;
import org.apache.iotdb.db.qp.physical.crud.GroupByTimePlan;
@@ -42,9 +43,6 @@ import org.apache.iotdb.service.rpc.thrift.TSRawDataQueryReq;
import java.time.ZoneId;
-import static org.apache.iotdb.db.qp.logical.Operator.OperatorType.QUERY;
-import static org.apache.iotdb.db.qp.logical.Operator.OperatorType.QUERY_INDEX;
-
/** provide a integration method for other user. */
public class Planner {
@@ -110,9 +108,15 @@ public class Planner {
*/
protected Operator logicalOptimize(Operator operator, int fetchSize)
throws LogicalOperatorException, PathNumOverLimitException {
- return operator.getType().equals(QUERY) || operator.getType().equals(QUERY_INDEX)
- ? optimizeQueryOperator((QueryOperator) operator, fetchSize)
- : operator;
+ switch (operator.getType()) {
+ case QUERY:
+ case QUERY_INDEX:
+ return optimizeQueryOperator((QueryOperator) operator, fetchSize);
+ case SELECT_INTO:
+ return optimizeSelectIntoOperator((SelectIntoOperator) operator, fetchSize);
+ default:
+ return operator;
+ }
}
/**
@@ -139,6 +143,12 @@ public class Planner {
return root;
}
+ private Operator optimizeSelectIntoOperator(SelectIntoOperator operator, int fetchSize)
+ throws PathNumOverLimitException, LogicalOperatorException {
+ operator.setQueryOperator(optimizeQueryOperator(operator.getQueryOperator(), fetchSize));
+ return operator;
+ }
+
@TestOnly
public PhysicalPlan parseSQLToPhysicalPlan(String sqlStr) throws QueryProcessException {
return parseSQLToPhysicalPlan(sqlStr, ZoneId.systemDefault(), 1024);
diff --git a/server/src/main/java/org/apache/iotdb/db/qp/logical/crud/SelectIntoOperator.java b/server/src/main/java/org/apache/iotdb/db/qp/logical/crud/SelectIntoOperator.java
index 322b9f8..ee9f7fb 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/logical/crud/SelectIntoOperator.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/logical/crud/SelectIntoOperator.java
@@ -19,9 +19,15 @@
package org.apache.iotdb.db.qp.logical.crud;
+import org.apache.iotdb.db.exception.query.LogicalOperatorException;
+import org.apache.iotdb.db.exception.query.QueryProcessException;
import org.apache.iotdb.db.metadata.PartialPath;
import org.apache.iotdb.db.qp.constant.SQLConstant;
import org.apache.iotdb.db.qp.logical.Operator;
+import org.apache.iotdb.db.qp.physical.PhysicalPlan;
+import org.apache.iotdb.db.qp.physical.crud.QueryPlan;
+import org.apache.iotdb.db.qp.physical.crud.SelectIntoPlan;
+import org.apache.iotdb.db.qp.strategy.PhysicalGenerator;
import java.util.List;
@@ -36,6 +42,16 @@ public class SelectIntoOperator extends Operator {
operatorType = OperatorType.SELECT_INTO;
}
+ @Override
+ public PhysicalPlan generatePhysicalPlan(PhysicalGenerator generator)
+ throws QueryProcessException {
+ return new SelectIntoPlan((QueryPlan) queryOperator.generatePhysicalPlan(generator), intoPaths);
+ }
+
+ public void check() throws LogicalOperatorException {
+ queryOperator.check();
+ }
+
public void setQueryOperator(QueryOperator queryOperator) {
this.queryOperator = queryOperator;
}
diff --git a/server/src/main/java/org/apache/iotdb/db/qp/physical/PhysicalPlan.java b/server/src/main/java/org/apache/iotdb/db/qp/physical/PhysicalPlan.java
index 97d5daa..74b4f05 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/physical/PhysicalPlan.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/physical/PhysicalPlan.java
@@ -29,6 +29,7 @@ import org.apache.iotdb.db.qp.physical.crud.InsertMultiTabletPlan;
import org.apache.iotdb.db.qp.physical.crud.InsertRowPlan;
import org.apache.iotdb.db.qp.physical.crud.InsertRowsPlan;
import org.apache.iotdb.db.qp.physical.crud.InsertTabletPlan;
+import org.apache.iotdb.db.qp.physical.crud.SelectIntoPlan;
import org.apache.iotdb.db.qp.physical.crud.SetDeviceTemplatePlan;
import org.apache.iotdb.db.qp.physical.sys.AlterTimeSeriesPlan;
import org.apache.iotdb.db.qp.physical.sys.AuthorPlan;
@@ -380,6 +381,8 @@ public abstract class PhysicalPlan {
case DROP_CONTINUOUS_QUERY:
plan = new DropContinuousQueryPlan();
break;
+ case SELECT_INTO:
+ plan = new SelectIntoPlan();
default:
throw new IOException("unrecognized log type " + type);
}
@@ -438,7 +441,8 @@ public abstract class PhysicalPlan {
STOP_TRIGGER,
CREATE_CONTINUOUS_QUERY,
DROP_CONTINUOUS_QUERY,
- SHOW_CONTINUOUS_QUERIES
+ SHOW_CONTINUOUS_QUERIES,
+ SELECT_INTO
}
public long getIndex() {
diff --git a/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/SelectIntoPlan.java b/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/SelectIntoPlan.java
new file mode 100644
index 0000000..7edb17d
--- /dev/null
+++ b/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/SelectIntoPlan.java
@@ -0,0 +1,66 @@
+/*
+ * 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.physical.crud;
+
+import org.apache.iotdb.db.exception.metadata.IllegalPathException;
+import org.apache.iotdb.db.metadata.PartialPath;
+import org.apache.iotdb.db.qp.logical.Operator.OperatorType;
+import org.apache.iotdb.db.qp.physical.PhysicalPlan;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.List;
+
+public class SelectIntoPlan extends PhysicalPlan {
+
+ private QueryPlan queryPlan;
+ private List<PartialPath> intoPaths;
+
+ public SelectIntoPlan() {
+ super(false, OperatorType.SELECT_INTO);
+ }
+
+ public SelectIntoPlan(QueryPlan queryPlan, List<PartialPath> intoPaths) {
+ super(false, OperatorType.SELECT_INTO);
+ this.queryPlan = queryPlan;
+ this.intoPaths = intoPaths;
+ }
+
+ @Override
+ public void serialize(DataOutputStream stream) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void serialize(ByteBuffer buffer) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void deserialize(ByteBuffer buffer) throws IllegalPathException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public List<PartialPath> getPaths() {
+ throw new UnsupportedOperationException();
+ }
+}
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
index 23f6a6f..14234d5 100644
--- 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
@@ -22,6 +22,7 @@ package org.apache.iotdb.db.qp.strategy;
import org.apache.iotdb.db.exception.query.LogicalOperatorException;
import org.apache.iotdb.db.qp.logical.Operator;
import org.apache.iotdb.db.qp.logical.crud.QueryOperator;
+import org.apache.iotdb.db.qp.logical.crud.SelectIntoOperator;
public class LogicalChecker {
@@ -32,5 +33,9 @@ public class LogicalChecker {
if (operator instanceof QueryOperator) {
((QueryOperator) operator).check();
}
+
+ if (operator instanceof SelectIntoOperator) {
+ ((SelectIntoOperator) operator).check();
+ }
}
}
[iotdb] 06/08: make select-into plan a query plan
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rong pushed a commit to branch select-into
in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit b3a88470e54771cc21b6e1b9e307ea72b40a864b
Author: Steve Yurong Su <ro...@apache.org>
AuthorDate: Wed Jul 14 10:17:12 2021 +0800
make select-into plan a query plan
---
.../engine/transporter/SelectIntoTransporter.java | 27 ++++++++++++++++++++++
.../iotdb/db/qp/physical/crud/SelectIntoPlan.java | 2 +-
2 files changed, 28 insertions(+), 1 deletion(-)
diff --git a/server/src/main/java/org/apache/iotdb/db/engine/transporter/SelectIntoTransporter.java b/server/src/main/java/org/apache/iotdb/db/engine/transporter/SelectIntoTransporter.java
new file mode 100644
index 0000000..385ddbd
--- /dev/null
+++ b/server/src/main/java/org/apache/iotdb/db/engine/transporter/SelectIntoTransporter.java
@@ -0,0 +1,27 @@
+/*
+ * 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.engine.transporter;
+
+import org.apache.iotdb.db.qp.physical.crud.SelectIntoPlan;
+
+public class SelectIntoTransporter {
+
+ public void execute(SelectIntoPlan selectIntoPlan) {}
+}
diff --git a/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/SelectIntoPlan.java b/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/SelectIntoPlan.java
index 7edb17d..71bf595 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/SelectIntoPlan.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/SelectIntoPlan.java
@@ -35,7 +35,7 @@ public class SelectIntoPlan extends PhysicalPlan {
private List<PartialPath> intoPaths;
public SelectIntoPlan() {
- super(false, OperatorType.SELECT_INTO);
+ super(true, OperatorType.SELECT_INTO);
}
public SelectIntoPlan(QueryPlan queryPlan, List<PartialPath> intoPaths) {
[iotdb] 01/08: antlr grammer for select into
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rong pushed a commit to branch select-into
in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 862afe4b6e1d308b4611b1a5a88287ef4a3fd832
Author: Steve Yurong Su <ro...@apache.org>
AuthorDate: Tue Jul 13 09:41:40 2021 +0800
antlr grammer for select into
---
.../antlr4/org/apache/iotdb/db/qp/sql/SqlBase.g4 | 45 ++++++++++++----------
1 file changed, 25 insertions(+), 20 deletions(-)
diff --git a/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/SqlBase.g4 b/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/SqlBase.g4
index 41235f4..cdffba1 100644
--- a/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/SqlBase.g4
+++ b/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/SqlBase.g4
@@ -105,6 +105,7 @@ statement
| STOP TRIGGER triggerName=ID #stopTrigger
| SHOW TRIGGERS #showTriggers
| selectClause fromClause whereClause? specialClause? #selectStatement
+ | selectClause intoClause fromClause whereClause? specialClause? #selectIntoStatement
| CREATE (CONTINUOUS QUERY | CQ) continuousQueryName=ID
resampleClause?
cqSelectIntoClause #createContinuousQueryStatement
@@ -113,26 +114,30 @@ statement
;
selectClause
- : SELECT (LAST | topClause)? resultColumn (COMMA resultColumn)*
- ;
+ : SELECT (LAST | topClause)? resultColumn (COMMA resultColumn)*
+ ;
resultColumn
- : expression (AS ID)?
- ;
+ : expression (AS ID)?
+ ;
expression
- : LR_BRACKET unary=expression RR_BRACKET
- | (PLUS | MINUS) unary=expression
- | leftExpression=expression (STAR | DIV | MOD) rightExpression=expression
- | leftExpression=expression (PLUS | MINUS) rightExpression=expression
- | functionName=suffixPath LR_BRACKET expression (COMMA expression)* functionAttribute* RR_BRACKET
- | suffixPath
- | literal=SINGLE_QUOTE_STRING_LITERAL
- ;
+ : LR_BRACKET unary=expression RR_BRACKET
+ | (PLUS | MINUS) unary=expression
+ | leftExpression=expression (STAR | DIV | MOD) rightExpression=expression
+ | leftExpression=expression (PLUS | MINUS) rightExpression=expression
+ | functionName=suffixPath LR_BRACKET expression (COMMA expression)* functionAttribute* RR_BRACKET
+ | suffixPath
+ | literal=SINGLE_QUOTE_STRING_LITERAL
+ ;
functionAttribute
- : COMMA functionAttributeKey=stringLiteral OPERATOR_EQ functionAttributeValue=stringLiteral
- ;
+ : COMMA functionAttributeKey=stringLiteral OPERATOR_EQ functionAttributeValue=stringLiteral
+ ;
+
+intoClause
+ : INTO intoPath (COMMA intoPath)*
+ ;
alias
: LR_BRACKET ID RR_BRACKET
@@ -338,12 +343,12 @@ resampleClause
: RESAMPLE (EVERY DURATION)? (FOR DURATION)?;
cqSelectIntoClause
- : BEGIN
- selectClause
- INTO (fullPath | nodeNameWithoutStar)
- fromClause
- cqGroupByTimeClause
- END
+ : BEGIN selectClause INTO intoPath fromClause cqGroupByTimeClause END
+ ;
+
+intoPath
+ : fullPath
+ | nodeNameWithoutStar
;
cqGroupByTimeClause
[iotdb] 05/08: auth
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rong pushed a commit to branch select-into
in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit cfa6ec8fc43664432ee4c9632c7a95f988e8df79
Author: Steve Yurong Su <ro...@apache.org>
AuthorDate: Tue Jul 13 17:20:22 2021 +0800
auth
---
server/src/main/java/org/apache/iotdb/db/auth/AuthorityChecker.java | 1 +
1 file changed, 1 insertion(+)
diff --git a/server/src/main/java/org/apache/iotdb/db/auth/AuthorityChecker.java b/server/src/main/java/org/apache/iotdb/db/auth/AuthorityChecker.java
index c0f86b3..a514035 100644
--- a/server/src/main/java/org/apache/iotdb/db/auth/AuthorityChecker.java
+++ b/server/src/main/java/org/apache/iotdb/db/auth/AuthorityChecker.java
@@ -135,6 +135,7 @@ public class AuthorityChecker {
case INSERT:
case LOAD_DATA:
case CREATE_INDEX:
+ case SELECT_INTO:
return PrivilegeType.INSERT_TIMESERIES.ordinal();
case LIST_ROLE:
case LIST_ROLE_USERS:
[iotdb] 02/08: fix IoTDBSqlVisitor parsing error
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rong pushed a commit to branch select-into
in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit f5706f2b8b631765ecb42b248a3612395aec1153
Author: Steve Yurong Su <ro...@apache.org>
AuthorDate: Tue Jul 13 09:46:34 2021 +0800
fix IoTDBSqlVisitor parsing error
---
.../src/main/java/org/apache/iotdb/db/qp/sql/IoTDBSqlVisitor.java | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/server/src/main/java/org/apache/iotdb/db/qp/sql/IoTDBSqlVisitor.java b/server/src/main/java/org/apache/iotdb/db/qp/sql/IoTDBSqlVisitor.java
index 737423b..909bf07 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/sql/IoTDBSqlVisitor.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/sql/IoTDBSqlVisitor.java
@@ -1217,8 +1217,8 @@ public class IoTDBSqlVisitor extends SqlBaseBaseVisitor<Operator> {
trueLevel = fromLen - 1;
}
- if (ctx.fullPath() != null) {
- targetPath = parseFullPath(ctx.fullPath());
+ if (ctx.intoPath().fullPath() != null) {
+ targetPath = parseFullPath(ctx.intoPath().fullPath());
Matcher m = cqLevelNodePattern.matcher(targetPath.getFullPath());
while (m.find()) {
String param = m.group();
@@ -1233,7 +1233,7 @@ public class IoTDBSqlVisitor extends SqlBaseBaseVisitor<Operator> {
"CQ: x of ${x} should be greater than 0 and equal to or less than <level> or the length of queried path prefix.");
}
}
- } else if (ctx.nodeNameWithoutStar() != null) {
+ } else if (ctx.intoPath().nodeNameWithoutStar() != null) {
List<String> targetNodes = new ArrayList<>();
@@ -1242,7 +1242,7 @@ public class IoTDBSqlVisitor extends SqlBaseBaseVisitor<Operator> {
for (int i = 1; i <= trueLevel; i++) {
targetNodes.add("${" + i + "}");
}
- targetNodes.add(ctx.nodeNameWithoutStar().getText());
+ targetNodes.add(ctx.intoPath().nodeNameWithoutStar().getText());
targetPath = new PartialPath(targetNodes.toArray(new String[0]));
}
[iotdb] 08/08: modify TSServiceImpl
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rong pushed a commit to branch select-into
in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 850f2c0bd744b5ab43c4812cae796997205fa1c0
Author: Steve Yurong Su <ro...@apache.org>
AuthorDate: Wed Jul 14 19:45:32 2021 +0800
modify TSServiceImpl
---
.../engine/transporter/SelectIntoTransporter.java | 10 +++-
.../apache/iotdb/db/qp/physical/PhysicalPlan.java | 4 ++
.../iotdb/db/qp/physical/crud/SelectIntoPlan.java | 13 ++++
.../org/apache/iotdb/db/service/TSServiceImpl.java | 69 ++++++++++++++++++----
4 files changed, 83 insertions(+), 13 deletions(-)
diff --git a/server/src/main/java/org/apache/iotdb/db/engine/transporter/SelectIntoTransporter.java b/server/src/main/java/org/apache/iotdb/db/engine/transporter/SelectIntoTransporter.java
index 385ddbd..b88179b 100644
--- a/server/src/main/java/org/apache/iotdb/db/engine/transporter/SelectIntoTransporter.java
+++ b/server/src/main/java/org/apache/iotdb/db/engine/transporter/SelectIntoTransporter.java
@@ -19,9 +19,15 @@
package org.apache.iotdb.db.engine.transporter;
-import org.apache.iotdb.db.qp.physical.crud.SelectIntoPlan;
+import org.apache.iotdb.db.exception.IoTDBException;
+import org.apache.iotdb.db.metadata.PartialPath;
+import org.apache.iotdb.tsfile.read.query.dataset.QueryDataSet;
+
+import java.util.List;
public class SelectIntoTransporter {
- public void execute(SelectIntoPlan selectIntoPlan) {}
+ public SelectIntoTransporter(QueryDataSet queryDataSet, List<PartialPath> intoPaths) {}
+
+ public void execute() throws IoTDBException {}
}
diff --git a/server/src/main/java/org/apache/iotdb/db/qp/physical/PhysicalPlan.java b/server/src/main/java/org/apache/iotdb/db/qp/physical/PhysicalPlan.java
index af58de9..dbdd956 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/physical/PhysicalPlan.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/physical/PhysicalPlan.java
@@ -116,6 +116,10 @@ public abstract class PhysicalPlan {
return isQuery;
}
+ public boolean isSelectInto() {
+ return false;
+ }
+
public Operator.OperatorType getOperatorType() {
return operatorType;
}
diff --git a/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/SelectIntoPlan.java b/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/SelectIntoPlan.java
index 71bf595..7606998 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/SelectIntoPlan.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/physical/crud/SelectIntoPlan.java
@@ -45,6 +45,11 @@ public class SelectIntoPlan extends PhysicalPlan {
}
@Override
+ public boolean isSelectInto() {
+ return true;
+ }
+
+ @Override
public void serialize(DataOutputStream stream) throws IOException {
throw new UnsupportedOperationException();
}
@@ -63,4 +68,12 @@ public class SelectIntoPlan extends PhysicalPlan {
public List<PartialPath> getPaths() {
throw new UnsupportedOperationException();
}
+
+ public QueryPlan getQueryPlan() {
+ return queryPlan;
+ }
+
+ public List<PartialPath> getIntoPaths() {
+ return intoPaths;
+ }
}
diff --git a/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java b/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
index f1af737..6c2190d 100644
--- a/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
+++ b/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
@@ -27,6 +27,7 @@ import org.apache.iotdb.db.conf.IoTDBConstant;
import org.apache.iotdb.db.conf.IoTDBDescriptor;
import org.apache.iotdb.db.cost.statistic.Measurement;
import org.apache.iotdb.db.cost.statistic.Operation;
+import org.apache.iotdb.db.engine.transporter.SelectIntoTransporter;
import org.apache.iotdb.db.exception.BatchProcessException;
import org.apache.iotdb.db.exception.IoTDBException;
import org.apache.iotdb.db.exception.QueryInBatchStatementException;
@@ -59,6 +60,7 @@ import org.apache.iotdb.db.qp.physical.crud.InsertTabletPlan;
import org.apache.iotdb.db.qp.physical.crud.LastQueryPlan;
import org.apache.iotdb.db.qp.physical.crud.QueryPlan;
import org.apache.iotdb.db.qp.physical.crud.RawDataQueryPlan;
+import org.apache.iotdb.db.qp.physical.crud.SelectIntoPlan;
import org.apache.iotdb.db.qp.physical.crud.SetDeviceTemplatePlan;
import org.apache.iotdb.db.qp.physical.crud.UDFPlan;
import org.apache.iotdb.db.qp.physical.crud.UDTFPlan;
@@ -498,7 +500,7 @@ public class TSServiceImpl implements TSIService.Iface {
PhysicalPlan physicalPlan =
processor.parseSQLToPhysicalPlan(
statement, sessionManager.getZoneId(req.sessionId), DEFAULT_FETCH_SIZE);
- if (physicalPlan.isQuery()) {
+ if (physicalPlan.isQuery() || physicalPlan.isSelectInto()) {
throw new QueryInBatchStatementException(statement);
}
@@ -597,16 +599,21 @@ public class TSServiceImpl implements TSIService.Iface {
processor.parseSQLToPhysicalPlan(
statement, sessionManager.getZoneId(req.getSessionId()), req.fetchSize);
- return physicalPlan.isQuery()
- ? internalExecuteQueryStatement(
- statement,
- req.statementId,
- physicalPlan,
- req.fetchSize,
- req.timeout,
- sessionManager.getUsername(req.getSessionId()),
- req.isEnableRedirectQuery())
- : executeUpdateStatement(physicalPlan, req.getSessionId());
+ if (physicalPlan.isQuery()) {
+ return internalExecuteQueryStatement(
+ statement,
+ req.statementId,
+ physicalPlan,
+ req.fetchSize,
+ req.timeout,
+ sessionManager.getUsername(req.getSessionId()),
+ req.isEnableRedirectQuery());
+ } else if (physicalPlan.isSelectInto()) {
+ return executeSelectIntoStatement(
+ statement, req.statementId, physicalPlan, req.fetchSize, req.timeout);
+ } else {
+ return executeUpdateStatement(physicalPlan, req.getSessionId());
+ }
} catch (InterruptedException e) {
LOGGER.error(INFO_INTERRUPT_ERROR, req, e);
Thread.currentThread().interrupt();
@@ -1024,6 +1031,46 @@ public class TSServiceImpl implements TSIService.Iface {
plan.setPaths(null);
}
+ private TSExecuteStatementResp executeSelectIntoStatement(
+ String statement, long statementId, PhysicalPlan physicalPlan, int fetchSize, long timeout)
+ throws IoTDBException, TException, SQLException, IOException, InterruptedException,
+ QueryFilterOptimizationException {
+ final long startTime = System.currentTimeMillis();
+
+ final SelectIntoPlan selectIntoPlan = (SelectIntoPlan) physicalPlan;
+ final QueryPlan queryPlan = selectIntoPlan.getQueryPlan();
+
+ queryCount.incrementAndGet();
+ AUDIT_LOGGER.debug("Session {} execute select into: {}", currSessionId.get(), statement);
+
+ Pair<Integer, Integer> fetchSizeDeduplicatedPathNumPair =
+ getMemoryParametersFromPhysicalPlan(queryPlan, fetchSize);
+ fetchSize = fetchSizeDeduplicatedPathNumPair.left;
+ long queryId =
+ sessionManager.requestQueryId(
+ statementId, true, fetchSize, fetchSizeDeduplicatedPathNumPair.right);
+
+ tracingManager.writeQueryInfo(queryId, statement, startTime, queryPlan);
+ try {
+ queryTimeManager.registerQuery(queryId, startTime, statement, timeout, queryPlan);
+ new SelectIntoTransporter(
+ createQueryDataSet(queryId, queryPlan, fetchSize), selectIntoPlan.getIntoPaths())
+ .execute();
+ return RpcUtils.getTSExecuteStatementResp(RpcUtils.getStatus(TSStatusCode.SUCCESS_STATUS))
+ .setQueryId(queryId);
+ } catch (Exception e) {
+ sessionManager.releaseQueryResourceNoExceptions(queryId);
+ throw e;
+ } finally {
+ queryTimeManager.unRegisterQuery(queryId, queryPlan);
+ Measurement.INSTANCE.addOperationLatency(Operation.EXECUTE_QUERY, startTime);
+ long costTime = System.currentTimeMillis() - startTime;
+ if (costTime >= config.getSlowQueryThreshold()) {
+ SLOW_SQL_LOGGER.info("Cost: {} ms, sql is {}", costTime, statement);
+ }
+ }
+ }
+
@SuppressWarnings("squid:S3776") // Suppress high Cognitive Complexity warning
@Override
public TSFetchResultsResp fetchResults(TSFetchResultsReq req) {
[iotdb] 07/08: refactor internalExecuteQueryStatement
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rong pushed a commit to branch select-into
in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit f0c5770a7856f4b0065163aa3a62f4f20fdc237d
Author: Steve Yurong Su <ro...@apache.org>
AuthorDate: Wed Jul 14 11:42:54 2021 +0800
refactor internalExecuteQueryStatement
---
.../apache/iotdb/db/qp/physical/PhysicalPlan.java | 4 +-
.../iotdb/db/query/control/QueryTimeManager.java | 14 +++++
.../iotdb/db/query/control/TracingManager.java | 49 ++++++++++++---
.../org/apache/iotdb/db/service/TSServiceImpl.java | 71 ++++++++--------------
.../iotdb/db/query/control/TracingManagerTest.java | 19 ++++--
5 files changed, 98 insertions(+), 59 deletions(-)
diff --git a/server/src/main/java/org/apache/iotdb/db/qp/physical/PhysicalPlan.java b/server/src/main/java/org/apache/iotdb/db/qp/physical/PhysicalPlan.java
index 74b4f05..af58de9 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/physical/PhysicalPlan.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/physical/PhysicalPlan.java
@@ -219,7 +219,9 @@ public abstract class PhysicalPlan {
}
public void setLoginUserName(String loginUserName) {
- this.loginUserName = loginUserName;
+ if (this instanceof AuthorPlan) {
+ this.loginUserName = loginUserName;
+ }
}
public static class Factory {
diff --git a/server/src/main/java/org/apache/iotdb/db/query/control/QueryTimeManager.java b/server/src/main/java/org/apache/iotdb/db/query/control/QueryTimeManager.java
index 3d78a92..48bb732 100644
--- a/server/src/main/java/org/apache/iotdb/db/query/control/QueryTimeManager.java
+++ b/server/src/main/java/org/apache/iotdb/db/query/control/QueryTimeManager.java
@@ -22,6 +22,8 @@ import org.apache.iotdb.db.concurrent.IoTDBThreadPoolFactory;
import org.apache.iotdb.db.conf.IoTDBConfig;
import org.apache.iotdb.db.conf.IoTDBDescriptor;
import org.apache.iotdb.db.exception.query.QueryTimeoutRuntimeException;
+import org.apache.iotdb.db.qp.physical.PhysicalPlan;
+import org.apache.iotdb.db.qp.physical.sys.ShowQueryProcesslistPlan;
import org.apache.iotdb.db.service.IService;
import org.apache.iotdb.db.service.ServiceType;
@@ -76,6 +78,14 @@ public class QueryTimeManager implements IService {
queryScheduledTaskMap.put(queryId, scheduledFuture);
}
+ public void registerQuery(
+ long queryId, long startTime, String sql, long timeout, PhysicalPlan plan) {
+ if (plan instanceof ShowQueryProcesslistPlan) {
+ return;
+ }
+ registerQuery(queryId, startTime, sql, timeout);
+ }
+
public void killQuery(long queryId) {
if (queryInfoMap.get(queryId) == null) {
return;
@@ -101,6 +111,10 @@ public class QueryTimeManager implements IService {
return successRemoved;
}
+ public AtomicBoolean unRegisterQuery(long queryId, PhysicalPlan plan) {
+ return plan instanceof ShowQueryProcesslistPlan ? null : unRegisterQuery(queryId);
+ }
+
public static void checkQueryAlive(long queryId) {
QueryInfo queryInfo = getInstance().queryInfoMap.get(queryId);
if (queryInfo != null && queryInfo.isInterrupted()) {
diff --git a/server/src/main/java/org/apache/iotdb/db/query/control/TracingManager.java b/server/src/main/java/org/apache/iotdb/db/query/control/TracingManager.java
index 450c4f4..31a071f 100644
--- a/server/src/main/java/org/apache/iotdb/db/query/control/TracingManager.java
+++ b/server/src/main/java/org/apache/iotdb/db/query/control/TracingManager.java
@@ -18,10 +18,16 @@
*/
package org.apache.iotdb.db.query.control;
+import org.apache.iotdb.db.conf.IoTDBConfig;
import org.apache.iotdb.db.conf.IoTDBConstant;
import org.apache.iotdb.db.conf.IoTDBDescriptor;
import org.apache.iotdb.db.engine.fileSystem.SystemFileFactory;
import org.apache.iotdb.db.engine.storagegroup.TsFileResource;
+import org.apache.iotdb.db.qp.physical.PhysicalPlan;
+import org.apache.iotdb.db.qp.physical.crud.AlignByDevicePlan;
+import org.apache.iotdb.db.qp.physical.crud.QueryPlan;
+import org.apache.iotdb.db.query.dataset.AlignByDeviceDataSet;
+import org.apache.iotdb.tsfile.read.query.dataset.QueryDataSet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -39,12 +45,15 @@ import java.util.concurrent.ConcurrentHashMap;
public class TracingManager {
private static final Logger logger = LoggerFactory.getLogger(TracingManager.class);
+ private static final IoTDBConfig config = IoTDBDescriptor.getInstance().getConfig();
+
private static final String QUERY_ID = "Query Id: ";
private static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss.SSS";
+
private BufferedWriter writer;
private Map<Long, Long> queryStartTime = new ConcurrentHashMap<>();
- public TracingManager(String dirName, String logFileName) {
+ private TracingManager(String dirName, String logFileName) {
initTracingManager(dirName, logFileName);
}
@@ -71,8 +80,12 @@ public class TracingManager {
return TracingManagerHelper.INSTANCE;
}
- public void writeQueryInfo(long queryId, String statement, long startTime, int pathsNum)
+ public void writeQueryInfo(long queryId, String statement, long startTime, PhysicalPlan plan)
throws IOException {
+ if (!config.isEnablePerformanceTracing() || !(plan instanceof QueryPlan)) {
+ return;
+ }
+
queryStartTime.put(queryId, startTime);
StringBuilder builder = new StringBuilder();
builder
@@ -85,15 +98,19 @@ public class TracingManager {
.append(" - Start time: ")
.append(new SimpleDateFormat(DATE_FORMAT).format(startTime))
.append("\n" + QUERY_ID)
- .append(queryId)
- .append(" - Number of series paths: ")
- .append(pathsNum)
- .append("\n");
+ .append(queryId);
+ if (plan instanceof AlignByDevicePlan) {
+ builder.append(" - Number of series paths: ").append(plan.getPaths().size()).append("\n");
+ }
writer.write(builder.toString());
}
// for align by device query
public void writeQueryInfo(long queryId, String statement, long startTime) throws IOException {
+ if (!config.isEnablePerformanceTracing()) {
+ return;
+ }
+
queryStartTime.put(queryId, startTime);
StringBuilder builder = new StringBuilder();
builder
@@ -109,12 +126,16 @@ public class TracingManager {
writer.write(builder.toString());
}
- public void writePathsNum(long queryId, int pathsNum) throws IOException {
+ public void writePathsNum(long queryId, QueryDataSet dataSet) throws IOException {
+ if (!config.isEnablePerformanceTracing() || !(dataSet instanceof AlignByDeviceDataSet)) {
+ return;
+ }
+
StringBuilder builder =
new StringBuilder(QUERY_ID)
.append(queryId)
.append(" - Number of series paths: ")
- .append(pathsNum)
+ .append(((AlignByDeviceDataSet) dataSet).getPathsNum())
.append("\n");
writer.write(builder.toString());
}
@@ -122,6 +143,10 @@ public class TracingManager {
public void writeTsFileInfo(
long queryId, Set<TsFileResource> seqFileResources, Set<TsFileResource> unSeqFileResources)
throws IOException {
+ if (!config.isEnablePerformanceTracing()) {
+ return;
+ }
+
// to avoid the disorder info of multi query
// add query id as prefix of each info
StringBuilder builder =
@@ -176,6 +201,10 @@ public class TracingManager {
public void writeChunksInfo(long queryId, long totalChunkNum, long totalChunkSize)
throws IOException {
+ if (!config.isEnablePerformanceTracing()) {
+ return;
+ }
+
StringBuilder builder =
new StringBuilder(QUERY_ID)
.append(queryId)
@@ -190,6 +219,10 @@ public class TracingManager {
}
public void writeEndTime(long queryId) throws IOException {
+ if (!config.isEnablePerformanceTracing()) {
+ return;
+ }
+
long endTime = System.currentTimeMillis();
StringBuilder builder =
new StringBuilder(QUERY_ID)
diff --git a/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java b/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
index 0616f61..f1af737 100644
--- a/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
+++ b/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
@@ -77,7 +77,6 @@ import org.apache.iotdb.db.query.control.QueryTimeManager;
import org.apache.iotdb.db.query.control.SessionManager;
import org.apache.iotdb.db.query.control.SessionTimeoutManager;
import org.apache.iotdb.db.query.control.TracingManager;
-import org.apache.iotdb.db.query.dataset.AlignByDeviceDataSet;
import org.apache.iotdb.db.query.dataset.DirectAlignByTimeDataSet;
import org.apache.iotdb.db.query.dataset.DirectNonAlignDataSet;
import org.apache.iotdb.db.query.expression.ResultColumn;
@@ -174,10 +173,12 @@ public class TSServiceImpl implements TSIService.Iface {
private static final String INFO_QUERY_PROCESS_ERROR = "Error occurred in query process: ";
private static final String INFO_NOT_ALLOWED_IN_BATCH_ERROR =
"The query statement is not allowed in batch: ";
-
private static final String INFO_INTERRUPT_ERROR =
"Current Thread interrupted when dealing with request {}";
+ public static final TSProtocolVersion CURRENT_RPC_VERSION =
+ TSProtocolVersion.IOTDB_SERVICE_PROTOCOL_V3;
+
private static final int MAX_SIZE =
IoTDBDescriptor.getInstance().getConfig().getQueryCacheSizeInMetric();
private static final int DELETE_SIZE = 20;
@@ -185,23 +186,18 @@ public class TSServiceImpl implements TSIService.Iface {
private static final long MS_TO_MONTH = 30 * 86400_000L;
private final IoTDBConfig config = IoTDBDescriptor.getInstance().getConfig();
- private final boolean enableMetric = config.isEnableMetricService();
-
- private static final List<SqlArgument> sqlArgumentList = new ArrayList<>(MAX_SIZE);
- protected Planner processor;
- protected IPlanExecutor executor;
-
- private SessionManager sessionManager = SessionManager.getInstance();
// When the client abnormally exits, we can still know who to disconnect
private final ThreadLocal<Long> currSessionId = new ThreadLocal<>();
+ private final SessionManager sessionManager = SessionManager.getInstance();
- public static final TSProtocolVersion CURRENT_RPC_VERSION =
- TSProtocolVersion.IOTDB_SERVICE_PROTOCOL_V3;
-
+ private static final List<SqlArgument> sqlArgumentList = new ArrayList<>(MAX_SIZE);
private static final AtomicInteger queryCount = new AtomicInteger(0);
+ private final QueryTimeManager queryTimeManager = QueryTimeManager.getInstance();
+ private final TracingManager tracingManager = TracingManager.getInstance();
- private QueryTimeManager queryTimeManager = QueryTimeManager.getInstance();
+ protected Planner processor;
+ protected IPlanExecutor executor;
public TSServiceImpl() throws QueryProcessException {
processor = new Planner();
@@ -733,33 +729,24 @@ public class TSServiceImpl implements TSIService.Iface {
QueryFilterOptimizationException, MetadataException, IOException, InterruptedException,
TException, AuthException {
queryCount.incrementAndGet();
- AUDIT_LOGGER.debug("Session {} execute Query: {}", currSessionId.get(), statement);
+ AUDIT_LOGGER.debug("Session {} execute query: {}", currSessionId.get(), statement);
+
long startTime = System.currentTimeMillis();
long queryId = -1;
- try {
-
- // pair.left = fetchSize, pair.right = deduplicatedNum
- Pair<Integer, Integer> p = getMemoryParametersFromPhysicalPlan(plan, fetchSize);
- fetchSize = p.left;
+ try {
+ Pair<Integer, Integer> fetchSizeDeduplicatedPathNumPair =
+ getMemoryParametersFromPhysicalPlan(plan, fetchSize);
+ fetchSize = fetchSizeDeduplicatedPathNumPair.left;
// generate the queryId for the operation
- queryId = sessionManager.requestQueryId(statementId, true, fetchSize, p.right);
- // register query info to queryTimeManager
- if (!(plan instanceof ShowQueryProcesslistPlan)) {
- queryTimeManager.registerQuery(queryId, startTime, statement, timeout);
- }
- if (plan instanceof QueryPlan && config.isEnablePerformanceTracing()) {
- TracingManager tracingManager = TracingManager.getInstance();
- if (!(plan instanceof AlignByDevicePlan)) {
- tracingManager.writeQueryInfo(queryId, statement, startTime, plan.getPaths().size());
- } else {
- tracingManager.writeQueryInfo(queryId, statement, startTime);
- }
- }
+ queryId =
+ sessionManager.requestQueryId(
+ statementId, true, fetchSize, fetchSizeDeduplicatedPathNumPair.right);
- if (plan instanceof AuthorPlan) {
- plan.setLoginUserName(username);
- }
+ queryTimeManager.registerQuery(queryId, startTime, statement, timeout, plan);
+ tracingManager.writeQueryInfo(queryId, statement, startTime, plan);
+
+ plan.setLoginUserName(username);
TSExecuteStatementResp resp = null;
// execute it before createDataSet since it may change the content of query plan
@@ -823,14 +810,12 @@ public class TSServiceImpl implements TSIService.Iface {
}
}
}
- resp.setQueryId(queryId);
- if (plan instanceof AlignByDevicePlan && config.isEnablePerformanceTracing()) {
- TracingManager.getInstance()
- .writePathsNum(queryId, ((AlignByDeviceDataSet) newDataSet).getPathsNum());
- }
+ resp.setQueryId(queryId);
- if (enableMetric) {
+ tracingManager.writePathsNum(queryId, newDataSet);
+ queryTimeManager.unRegisterQuery(queryId, plan);
+ if (config.isEnableMetricService()) {
long endTime = System.currentTimeMillis();
SqlArgument sqlArgument = new SqlArgument(resp, plan, statement, startTime, endTime);
synchronized (sqlArgumentList) {
@@ -841,10 +826,6 @@ public class TSServiceImpl implements TSIService.Iface {
}
}
- // remove query info in QueryTimeManager
- if (!(plan instanceof ShowQueryProcesslistPlan)) {
- queryTimeManager.unRegisterQuery(queryId);
- }
return resp;
} catch (Exception e) {
sessionManager.releaseQueryResourceNoExceptions(queryId);
diff --git a/server/src/test/java/org/apache/iotdb/db/query/control/TracingManagerTest.java b/server/src/test/java/org/apache/iotdb/db/query/control/TracingManagerTest.java
index 3f1f0a9..acb40e6 100644
--- a/server/src/test/java/org/apache/iotdb/db/query/control/TracingManagerTest.java
+++ b/server/src/test/java/org/apache/iotdb/db/query/control/TracingManagerTest.java
@@ -23,6 +23,9 @@ import org.apache.iotdb.db.conf.IoTDBDescriptor;
import org.apache.iotdb.db.constant.TestConstant;
import org.apache.iotdb.db.engine.fileSystem.SystemFileFactory;
import org.apache.iotdb.db.engine.storagegroup.TsFileResource;
+import org.apache.iotdb.db.exception.metadata.IllegalPathException;
+import org.apache.iotdb.db.qp.physical.crud.AlignByDevicePlan;
+import org.apache.iotdb.db.query.dataset.AlignByDeviceDataSet;
import org.apache.iotdb.db.utils.EnvironmentUtils;
import org.apache.commons.io.FileUtils;
@@ -63,17 +66,17 @@ public class TracingManagerTest {
}
@Test
- public void tracingQueryTest() throws IOException {
+ public void tracingQueryTest() throws IOException, IllegalPathException {
if (!tracingManager.getWriterStatus()) {
tracingManager.openTracingWriteStream();
}
String[] ans = {
"Query Id: 10 - Query Statement: " + sql,
"Query Id: 10 - Start time: 2020-12-",
- "Query Id: 10 - Number of series paths: 3",
+ "Query Id: 10 - Number of series paths: 0",
"Query Id: 10 - Query Statement: " + sql,
"Query Id: 10 - Start time: 2020-12-",
- "Query Id: 10 - Number of series paths: 3",
+ "Query Id: 10 - Number of series paths: 0",
"Query Id: 10 - Number of sequence files: 1",
"Query Id: 10 - SeqFile_1-1-0.tsfile root.sg.d1[1, 999], root.sg.d2[2, 998]",
"Query Id: 10 - Number of unSequence files: 0",
@@ -81,9 +84,15 @@ public class TracingManagerTest {
"Query Id: 10 - Average size of chunks: 1371",
"Query Id: 10 - Total cost time: "
};
+
+ AlignByDevicePlan plan = new AlignByDevicePlan();
+ plan.setPaths(Collections.emptyList());
+ plan.setDevices(Collections.emptyList());
+ AlignByDeviceDataSet dataSet = new AlignByDeviceDataSet(plan, null, null);
+
tracingManager.writeQueryInfo(queryId, sql, 1607529600000L);
- tracingManager.writePathsNum(queryId, 3);
- tracingManager.writeQueryInfo(queryId, sql, 1607529600000L, 3);
+ tracingManager.writePathsNum(queryId, dataSet);
+ tracingManager.writeQueryInfo(queryId, sql, 1607529600000L, plan);
tracingManager.writeTsFileInfo(queryId, seqResources, Collections.EMPTY_SET);
tracingManager.writeChunksInfo(queryId, 3, 4113L);
tracingManager.writeEndTime(queryId);
[iotdb] 03/08: from sql visitor to logical operator
Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rong pushed a commit to branch select-into
in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit d5413d3570151d812e5a86b39d94a52bae1ecc1c
Author: Steve Yurong Su <ro...@apache.org>
AuthorDate: Tue Jul 13 16:17:56 2021 +0800
from sql visitor to logical operator
---
.../antlr4/org/apache/iotdb/db/qp/sql/SqlBase.g4 | 13 ++-
.../apache/iotdb/db/qp/constant/SQLConstant.java | 4 +
.../org/apache/iotdb/db/qp/logical/Operator.java | 2 +
.../db/qp/logical/crud/SelectIntoOperator.java | 54 ++++++++++
.../apache/iotdb/db/qp/sql/IoTDBSqlVisitor.java | 118 +++++++++++++--------
.../iotdb/db/qp/physical/PhysicalPlanTest.java | 16 +--
6 files changed, 149 insertions(+), 58 deletions(-)
diff --git a/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/SqlBase.g4 b/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/SqlBase.g4
index cdffba1..54acf2b 100644
--- a/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/SqlBase.g4
+++ b/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/SqlBase.g4
@@ -104,8 +104,7 @@ statement
| START TRIGGER triggerName=ID #startTrigger
| STOP TRIGGER triggerName=ID #stopTrigger
| SHOW TRIGGERS #showTriggers
- | selectClause fromClause whereClause? specialClause? #selectStatement
- | selectClause intoClause fromClause whereClause? specialClause? #selectIntoStatement
+ | selectClause intoClause? fromClause whereClause? specialClause? #selectStatement
| CREATE (CONTINUOUS QUERY | CQ) continuousQueryName=ID
resampleClause?
cqSelectIntoClause #createContinuousQueryStatement
@@ -139,6 +138,11 @@ intoClause
: INTO intoPath (COMMA intoPath)*
;
+intoPath
+ : fullPath
+ | nodeNameWithoutStar
+ ;
+
alias
: LR_BRACKET ID RR_BRACKET
;
@@ -346,11 +350,6 @@ cqSelectIntoClause
: BEGIN selectClause INTO intoPath fromClause cqGroupByTimeClause END
;
-intoPath
- : fullPath
- | nodeNameWithoutStar
- ;
-
cqGroupByTimeClause
: GROUP BY TIME LR_BRACKET
DURATION
diff --git a/server/src/main/java/org/apache/iotdb/db/qp/constant/SQLConstant.java b/server/src/main/java/org/apache/iotdb/db/qp/constant/SQLConstant.java
index 7509bf0..bf2e9c2 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/constant/SQLConstant.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/constant/SQLConstant.java
@@ -179,6 +179,8 @@ public class SQLConstant {
public static final int TOK_CONTINUOUS_QUERY_DROP = 107;
public static final int TOK_SHOW_CONTINUOUS_QUERIES = 108;
+ public static final int TOK_SELECT_INTO = 109;
+
public static final Map<Integer, String> tokenNames = new HashMap<>();
public static String[] getSingleRootArray() {
@@ -247,6 +249,8 @@ public class SQLConstant {
tokenNames.put(TOK_CONTINUOUS_QUERY_CREATE, "TOK_CONTINUOUS_QUERY_CREATE");
tokenNames.put(TOK_CONTINUOUS_QUERY_DROP, "TOK_CONTINUOUS_QUERY_DROP");
tokenNames.put(TOK_SHOW_CONTINUOUS_QUERIES, "TOK_SHOW_CONTINUOUS_QUERIES");
+
+ tokenNames.put(TOK_SELECT_INTO, "TOK_SELECT_INTO");
}
public static boolean isReservedPath(PartialPath pathStr) {
diff --git a/server/src/main/java/org/apache/iotdb/db/qp/logical/Operator.java b/server/src/main/java/org/apache/iotdb/db/qp/logical/Operator.java
index 56eba91..53234cb 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/logical/Operator.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/logical/Operator.java
@@ -126,6 +126,8 @@ public abstract class Operator {
UDAF,
UDTF,
+ SELECT_INTO,
+
CREATE_FUNCTION,
DROP_FUNCTION,
diff --git a/server/src/main/java/org/apache/iotdb/db/qp/logical/crud/SelectIntoOperator.java b/server/src/main/java/org/apache/iotdb/db/qp/logical/crud/SelectIntoOperator.java
new file mode 100644
index 0000000..322b9f8
--- /dev/null
+++ b/server/src/main/java/org/apache/iotdb/db/qp/logical/crud/SelectIntoOperator.java
@@ -0,0 +1,54 @@
+/*
+ * 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.logical.crud;
+
+import org.apache.iotdb.db.metadata.PartialPath;
+import org.apache.iotdb.db.qp.constant.SQLConstant;
+import org.apache.iotdb.db.qp.logical.Operator;
+
+import java.util.List;
+
+public class SelectIntoOperator extends Operator {
+
+ private QueryOperator queryOperator;
+
+ private List<PartialPath> intoPaths;
+
+ public SelectIntoOperator() {
+ super(SQLConstant.TOK_SELECT_INTO);
+ operatorType = OperatorType.SELECT_INTO;
+ }
+
+ public void setQueryOperator(QueryOperator queryOperator) {
+ this.queryOperator = queryOperator;
+ }
+
+ public QueryOperator getQueryOperator() {
+ return queryOperator;
+ }
+
+ public void setIntoPaths(List<PartialPath> intoPaths) {
+ this.intoPaths = intoPaths;
+ }
+
+ public List<PartialPath> getIntoPaths() {
+ return intoPaths;
+ }
+}
diff --git a/server/src/main/java/org/apache/iotdb/db/qp/sql/IoTDBSqlVisitor.java b/server/src/main/java/org/apache/iotdb/db/qp/sql/IoTDBSqlVisitor.java
index 909bf07..8a40fa4 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/sql/IoTDBSqlVisitor.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/sql/IoTDBSqlVisitor.java
@@ -45,6 +45,7 @@ import org.apache.iotdb.db.qp.logical.crud.InsertOperator;
import org.apache.iotdb.db.qp.logical.crud.LastQueryOperator;
import org.apache.iotdb.db.qp.logical.crud.QueryOperator;
import org.apache.iotdb.db.qp.logical.crud.SelectComponent;
+import org.apache.iotdb.db.qp.logical.crud.SelectIntoOperator;
import org.apache.iotdb.db.qp.logical.crud.SpecialClauseComponent;
import org.apache.iotdb.db.qp.logical.crud.UDFQueryOperator;
import org.apache.iotdb.db.qp.logical.crud.WhereComponent;
@@ -156,6 +157,7 @@ import org.apache.iotdb.db.qp.sql.SqlBaseParser.InsertColumnsSpecContext;
import org.apache.iotdb.db.qp.sql.SqlBaseParser.InsertMultiValueContext;
import org.apache.iotdb.db.qp.sql.SqlBaseParser.InsertStatementContext;
import org.apache.iotdb.db.qp.sql.SqlBaseParser.InsertValuesSpecContext;
+import org.apache.iotdb.db.qp.sql.SqlBaseParser.IntoPathContext;
import org.apache.iotdb.db.qp.sql.SqlBaseParser.KillQueryContext;
import org.apache.iotdb.db.qp.sql.SqlBaseParser.LimitClauseContext;
import org.apache.iotdb.db.qp.sql.SqlBaseParser.LimitStatementContext;
@@ -284,7 +286,9 @@ public class IoTDBSqlVisitor extends SqlBaseBaseVisitor<Operator> {
"For delete statement, where clause can only contain atomic expressions like : "
+ "time > XXX, time <= XXX, or two atomic expressions connected by 'AND'";
- private static final Pattern cqLevelNodePattern = Pattern.compile("\\$\\{\\w+}");
+ // used to match "{x}", where x is a integer.
+ // for create-cq clause and select-into clause.
+ private static final Pattern leveledPathNodePattern = Pattern.compile("\\$\\{\\w+}");
private ZoneId zoneId;
private QueryOperator queryOp;
@@ -1045,8 +1049,8 @@ public class IoTDBSqlVisitor extends SqlBaseBaseVisitor<Operator> {
queryOp.setWhereComponent(whereComponent);
}
}
-
- return queryOp;
+ // 4. Check whether it's a select-into clause
+ return ctx.intoClause() == null ? queryOp : parseAndConstructSelectIntoOperator(ctx);
}
public void parseSelectClause(SelectClauseContext ctx) {
@@ -1100,6 +1104,68 @@ public class IoTDBSqlVisitor extends SqlBaseBaseVisitor<Operator> {
resultColumnContext.AS() == null ? null : resultColumnContext.ID().getText());
}
+ private SelectIntoOperator parseAndConstructSelectIntoOperator(SelectStatementContext ctx) {
+ if (queryOp.getFromComponent().getPrefixPaths().size() != 1) {
+ throw new SQLParserException(
+ "select into: the number of prefix paths in the from clause should be 1.");
+ }
+
+ int sourcePathsCount = queryOp.getSelectComponent().getResultColumns().size();
+ if (sourcePathsCount != ctx.intoClause().intoPath().size()) {
+ throw new SQLParserException(
+ "select into: the number of source paths and the number of target paths should be the same.");
+ }
+
+ SelectIntoOperator selectIntoOperator = new SelectIntoOperator();
+ selectIntoOperator.setQueryOperator(queryOp);
+ List<PartialPath> intoPaths = new ArrayList<>();
+ for (int i = 0; i < sourcePathsCount; ++i) {
+ intoPaths.add(parseIntoPath(ctx.intoClause().intoPath(i)));
+ }
+ selectIntoOperator.setIntoPaths(intoPaths);
+ return selectIntoOperator;
+ }
+
+ private PartialPath parseIntoPath(IntoPathContext intoPathContext) {
+ int levelLimitOfSourcePrefixPath = queryOp.getSpecialClauseComponent().getLevel();
+ if (levelLimitOfSourcePrefixPath == -1) {
+ levelLimitOfSourcePrefixPath =
+ queryOp.getFromComponent().getPrefixPaths().get(0).getNodeLength() - 1;
+ }
+
+ PartialPath intoPath = null;
+ if (intoPathContext.fullPath() != null) {
+ intoPath = parseFullPath(intoPathContext.fullPath());
+
+ Matcher m = leveledPathNodePattern.matcher(intoPath.getFullPath());
+ while (m.find()) {
+ String param = m.group();
+ int nodeIndex = 0;
+ try {
+ nodeIndex = Integer.parseInt(param.substring(2, param.length() - 1).trim());
+ } catch (NumberFormatException e) {
+ throw new SQLParserException("the x of ${x} should be an integer.");
+ }
+ if (nodeIndex < 1 || levelLimitOfSourcePrefixPath < nodeIndex) {
+ throw new SQLParserException(
+ "the x of ${x} should be greater than 0 and equal to or less than <level> or the length of queried path prefix.");
+ }
+ }
+ } else if (intoPathContext.nodeNameWithoutStar() != null) {
+ String[] intoPathNodes = new String[levelLimitOfSourcePrefixPath + 2];
+ intoPathNodes[0] = "root";
+ for (int i = 1; i <= levelLimitOfSourcePrefixPath; ++i) {
+ intoPathNodes[i] = "${" + i + "}";
+ }
+ intoPathNodes[levelLimitOfSourcePrefixPath + 1] =
+ intoPathContext.nodeNameWithoutStar().getText();
+
+ intoPath = new PartialPath(intoPathNodes);
+ }
+
+ return intoPath;
+ }
+
@Override
public Operator visitDropContinuousQueryStatement(DropContinuousQueryStatementContext ctx) {
DropContinuousQueryOperator dropContinuousQueryOperator =
@@ -1199,54 +1265,18 @@ public class IoTDBSqlVisitor extends SqlBaseBaseVisitor<Operator> {
}
if (queryOp.getFromComponent().getPrefixPaths().size() > 1) {
- throw new SQLParserException("CQ: CQ currently does not support multiple series .");
+ throw new SQLParserException("CQ: CQ currently does not support multiple series.");
}
parseCqGroupByTimeClause(ctx.cqGroupByTimeClause());
- int fromLen = queryOp.getFromComponent().getPrefixPaths().get(0).getNodeLength();
- int queryLevel = queryOp.getSpecialClauseComponent().getLevel();
- if (queryLevel >= fromLen) {
+ int groupByQueryLevel = queryOp.getSpecialClauseComponent().getLevel();
+ int fromPrefixLevelLimit = queryOp.getFromComponent().getPrefixPaths().get(0).getNodeLength();
+ if (groupByQueryLevel >= fromPrefixLevelLimit) {
throw new SQLParserException("CQ: Level should not exceed the <from_prefix> length.");
}
- PartialPath targetPath = null;
-
- int trueLevel = queryLevel;
- if (trueLevel == -1) {
- trueLevel = fromLen - 1;
- }
-
- if (ctx.intoPath().fullPath() != null) {
- targetPath = parseFullPath(ctx.intoPath().fullPath());
- Matcher m = cqLevelNodePattern.matcher(targetPath.getFullPath());
- while (m.find()) {
- String param = m.group();
- int nodeIndex = 0;
- try {
- nodeIndex = Integer.parseInt(param.substring(2, param.length() - 1).trim());
- } catch (NumberFormatException e) {
- throw new SQLParserException("CQ: x of ${x} should be an integer.");
- }
- if (nodeIndex < 1 || nodeIndex > trueLevel) {
- throw new SQLParserException(
- "CQ: x of ${x} should be greater than 0 and equal to or less than <level> or the length of queried path prefix.");
- }
- }
- } else if (ctx.intoPath().nodeNameWithoutStar() != null) {
-
- List<String> targetNodes = new ArrayList<>();
-
- targetNodes.add("root");
-
- for (int i = 1; i <= trueLevel; i++) {
- targetNodes.add("${" + i + "}");
- }
- targetNodes.add(ctx.intoPath().nodeNameWithoutStar().getText());
- targetPath = new PartialPath(targetNodes.toArray(new String[0]));
- }
-
- createContinuousQueryOperator.setTargetPath(targetPath);
+ createContinuousQueryOperator.setTargetPath(parseIntoPath(ctx.intoPath()));
createContinuousQueryOperator.setQueryOperator(queryOp);
}
diff --git a/server/src/test/java/org/apache/iotdb/db/qp/physical/PhysicalPlanTest.java b/server/src/test/java/org/apache/iotdb/db/qp/physical/PhysicalPlanTest.java
index 56d5708..9fa6591 100644
--- a/server/src/test/java/org/apache/iotdb/db/qp/physical/PhysicalPlanTest.java
+++ b/server/src/test/java/org/apache/iotdb/db/qp/physical/PhysicalPlanTest.java
@@ -1331,7 +1331,7 @@ public class PhysicalPlanTest {
(CreateContinuousQueryPlan) processor.parseSQLToPhysicalPlan(sql);
fail();
} catch (SQLParserException e) {
- assertEquals("CQ: x of ${x} should be an integer.", e.getMessage());
+ assertTrue(e.getMessage().contains("the x of ${x} should be an integer."));
}
}
@@ -1345,9 +1345,10 @@ public class PhysicalPlanTest {
(CreateContinuousQueryPlan) processor.parseSQLToPhysicalPlan(sql);
fail();
} catch (SQLParserException e) {
- assertEquals(
- "CQ: x of ${x} should be greater than 0 and equal to or less than <level> or the length of queried path prefix.",
- e.getMessage());
+ assertTrue(
+ e.getMessage()
+ .contains(
+ "the x of ${x} should be greater than 0 and equal to or less than <level> or the length of queried path prefix."));
}
}
@@ -1392,9 +1393,10 @@ public class PhysicalPlanTest {
(CreateContinuousQueryPlan) processor.parseSQLToPhysicalPlan(sql);
fail();
} catch (SQLParserException e) {
- assertEquals(
- "CQ: x of ${x} should be greater than 0 and equal to or less than <level> or the length of queried path prefix.",
- e.getMessage());
+ assertTrue(
+ e.getMessage()
+ .contains(
+ "the x of ${x} should be greater than 0 and equal to or less than <level> or the length of queried path prefix."));
}
}