You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ja...@apache.org on 2021/03/15 11:50:18 UTC
[iotdb] branch MasterQueryDebug updated: support 'explain' clause
(#2847)
This is an automated email from the ASF dual-hosted git repository.
jackietien pushed a commit to branch MasterQueryDebug
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/MasterQueryDebug by this push:
new d0f4f35 support 'explain' clause (#2847)
d0f4f35 is described below
commit d0f4f356bd0a9e916914e8d218bbc12b9420e838
Author: Steve Yurong Su <st...@outlook.com>
AuthorDate: Mon Mar 15 19:50:02 2021 +0800
support 'explain' clause (#2847)
support 'explain' clause
---
antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/SqlBase.g4 | 7 ++++++-
.../main/java/org/apache/iotdb/db/qp/logical/Operator.java | 11 +++++++++++
.../main/java/org/apache/iotdb/db/qp/sql/IoTDBSqlVisitor.java | 6 +++++-
.../org/apache/iotdb/db/qp/strategy/PhysicalGenerator.java | 9 ++++++++-
4 files changed, 30 insertions(+), 3 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 fac9d26..e47754e 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
@@ -20,7 +20,7 @@
grammar SqlBase;
singleStatement
- : statement (';')? EOF
+ : EXPLAIN statement (';')? EOF
;
/*
@@ -1285,6 +1285,11 @@ LIKE
TOLERANCE
: T O L E R A N C E
;
+
+EXPLAIN
+ : E X P L A I N
+ ;
+
//============================
// End of the keywords list
//============================
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 c7ec520..f2a8633 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
@@ -27,12 +27,15 @@ public abstract class Operator {
protected int tokenIntType;
// operator type in String format
protected String tokenName;
+ // flag of "explain"
+ protected boolean isDebug;
protected OperatorType operatorType = OperatorType.NULL;
protected Operator(int tokenIntType) {
this.tokenIntType = tokenIntType;
this.tokenName = SQLConstant.tokenNames.get(tokenIntType);
+ this.isDebug = false;
}
public OperatorType getType() {
@@ -55,6 +58,14 @@ public abstract class Operator {
this.operatorType = operatorType;
}
+ public boolean isDebug() {
+ return isDebug;
+ }
+
+ public void setDebug(boolean debug) {
+ isDebug = debug;
+ }
+
@Override
public String toString() {
return tokenName;
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 1fd4522..cfd923b 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
@@ -260,7 +260,11 @@ public class IoTDBSqlVisitor extends SqlBaseBaseVisitor<Operator> {
@Override
public Operator visitSingleStatement(SingleStatementContext ctx) {
- return visit(ctx.statement());
+ Operator operator = visit(ctx.statement());
+ if (ctx.EXPLAIN() != null) {
+ operator.setDebug(true);
+ }
+ return operator;
}
@Override
diff --git a/server/src/main/java/org/apache/iotdb/db/qp/strategy/PhysicalGenerator.java b/server/src/main/java/org/apache/iotdb/db/qp/strategy/PhysicalGenerator.java
index 8332a88..230573f 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/strategy/PhysicalGenerator.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/strategy/PhysicalGenerator.java
@@ -144,9 +144,16 @@ import java.util.Set;
/** Used to convert logical operator to physical plan */
public class PhysicalGenerator {
- @SuppressWarnings("squid:S3776") // Suppress high Cognitive Complexity warning
public PhysicalPlan transformToPhysicalPlan(Operator operator, int fetchSize)
throws QueryProcessException {
+ PhysicalPlan physicalPlan = doTransformation(operator, fetchSize);
+ physicalPlan.setDebug(operator.isDebug());
+ return physicalPlan;
+ }
+
+ @SuppressWarnings("squid:S3776") // Suppress high Cognitive Complexity warning
+ private PhysicalPlan doTransformation(Operator operator, int fetchSize)
+ throws QueryProcessException {
List<PartialPath> paths;
switch (operator.getType()) {
case AUTHOR: