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 95884ad6b9 [IOTDB-3277] [IOTDB-3310] [IOTDB-3311] Fix some SQL parser
bugs in new cluster (#6060)
95884ad6b9 is described below
commit 95884ad6b95561bdde42eea55edc50fa23fb46a0
Author: liuminghui233 <[email protected]>
AuthorDate: Mon May 30 09:43:40 2022 +0800
[IOTDB-3277] [IOTDB-3310] [IOTDB-3311] Fix some SQL parser bugs in new
cluster (#6060)
---
.../org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4 | 14 ++-
.../iotdb/db/mpp/plan/parser/ASTVisitor.java | 107 +++++++++++++++++----
.../iotdb/db/mpp/plan/planner/LogicalPlanner.java | 21 ++--
3 files changed, 112 insertions(+), 30 deletions(-)
diff --git a/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4
b/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4
index 326eac60b0..bc8167772e 100644
--- a/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4
+++ b/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4
@@ -76,15 +76,19 @@ syncStatement
// Create Storage Group
setStorageGroup
- : SET STORAGE GROUP TO prefixPath (WITH storageGroupAttributeClause (COMMA
storageGroupAttributeClause)*)?
+ : SET STORAGE GROUP TO prefixPath storageGroupAttributesClause?
;
-storageGroupAttributeClause
- : (TTL | SCHEMA_REPLICATION_FACTOR | DATA_REPLICATION_FACTOR |
TIME_PARTITION_INTERVAL) '=' INTEGER_LITERAL
+createStorageGroup
+ : CREATE STORAGE GROUP prefixPath storageGroupAttributesClause?
;
-createStorageGroup
- : CREATE STORAGE GROUP prefixPath
+storageGroupAttributesClause
+ : WITH storageGroupAttributeClause (COMMA storageGroupAttributeClause)*
+ ;
+
+storageGroupAttributeClause
+ : (TTL | SCHEMA_REPLICATION_FACTOR | DATA_REPLICATION_FACTOR |
TIME_PARTITION_INTERVAL) '=' INTEGER_LITERAL
;
// Create Timeseries
diff --git
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/parser/ASTVisitor.java
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/parser/ASTVisitor.java
index 25f2c5bce1..463ff16649 100644
--- a/server/src/main/java/org/apache/iotdb/db/mpp/plan/parser/ASTVisitor.java
+++ b/server/src/main/java/org/apache/iotdb/db/mpp/plan/parser/ASTVisitor.java
@@ -754,6 +754,23 @@ public class ASTVisitor extends
IoTDBSqlParserBaseVisitor<Statement> {
return queryStatement;
}
+ @Override
+ public Statement
visitGroupByFillStatement(IoTDBSqlParser.GroupByFillStatementContext ctx) {
+ // parse group by time clause & fill clause
+ parseGroupByTimeClause(ctx.groupByFillClause());
+
+ // parse order by time
+ if (ctx.orderByTimeClause() != null) {
+ parseOrderByTimeClause(ctx.orderByTimeClause());
+ }
+
+ // parse limit & offset
+ if (ctx.specialLimit() != null) {
+ return visit(ctx.specialLimit());
+ }
+ return queryStatement;
+ }
+
private void parseGroupByTimeClause(IoTDBSqlParser.GroupByTimeClauseContext
ctx) {
GroupByTimeComponent groupByTimeComponent = new GroupByTimeComponent();
@@ -800,6 +817,41 @@ public class ASTVisitor extends
IoTDBSqlParserBaseVisitor<Statement> {
queryStatement.setGroupByTimeComponent(groupByTimeComponent);
}
+ private void parseGroupByTimeClause(IoTDBSqlParser.GroupByFillClauseContext
ctx) {
+ GroupByTimeComponent groupByTimeComponent = new GroupByTimeComponent();
+
+ // parse time range
+ parseTimeRange(ctx.timeRange(), groupByTimeComponent);
+ groupByTimeComponent.setLeftCRightO(ctx.timeRange().LS_BRACKET() != null);
+
+ // parse time interval
+ groupByTimeComponent.setInterval(
+ parseTimeIntervalOrSlidingStep(
+ ctx.DURATION_LITERAL(0).getText(), true, groupByTimeComponent));
+ if (groupByTimeComponent.getInterval() <= 0) {
+ throw new SemanticException(
+ "The second parameter time interval should be a positive integer.");
+ }
+
+ // parse sliding step
+ if (ctx.DURATION_LITERAL().size() == 2) {
+ groupByTimeComponent.setSlidingStep(
+ parseTimeIntervalOrSlidingStep(
+ ctx.DURATION_LITERAL(1).getText(), false, groupByTimeComponent));
+ } else {
+ groupByTimeComponent.setSlidingStep(groupByTimeComponent.getInterval());
+
groupByTimeComponent.setSlidingStepByMonth(groupByTimeComponent.isIntervalByMonth());
+ }
+
+ // parse fill clause
+ if (ctx.fillClause() != null) {
+ parseFillClause(ctx.fillClause());
+ }
+
+ // set groupByTimeComponent
+ queryStatement.setGroupByTimeComponent(groupByTimeComponent);
+ }
+
/** parse time range (startTime and endTime) in group by query. */
private void parseTimeRange(
IoTDBSqlParser.TimeRangeContext timeRange, GroupByTimeComponent
groupByClauseComponent) {
@@ -1616,32 +1668,53 @@ public class ASTVisitor extends
IoTDBSqlParserBaseVisitor<Statement> {
return privileges.toArray(new String[0]);
}
+ // Create Storage Group
+
@Override
public Statement visitSetStorageGroup(IoTDBSqlParser.SetStorageGroupContext
ctx) {
SetStorageGroupStatement setStorageGroupStatement = new
SetStorageGroupStatement();
PartialPath path = parsePrefixPath(ctx.prefixPath());
setStorageGroupStatement.setStorageGroupPath(path);
- if (ctx.storageGroupAttributeClause() != null) {
- for (IoTDBSqlParser.StorageGroupAttributeClauseContext attribute :
- ctx.storageGroupAttributeClause()) {
- if (attribute.TTL() != null) {
- long ttl = Long.parseLong(attribute.INTEGER_LITERAL().getText());
- setStorageGroupStatement.setTtl(ttl);
- } else if (attribute.SCHEMA_REPLICATION_FACTOR() != null) {
- int schemaReplicationFactor =
Integer.parseInt(attribute.INTEGER_LITERAL().getText());
-
setStorageGroupStatement.setSchemaReplicationFactor(schemaReplicationFactor);
- } else if (attribute.DATA_REPLICATION_FACTOR() != null) {
- int dataReplicationFactor =
Integer.parseInt(attribute.INTEGER_LITERAL().getText());
-
setStorageGroupStatement.setDataReplicationFactor(dataReplicationFactor);
- } else if (attribute.TIME_PARTITION_INTERVAL() != null) {
- long timePartitionInterval =
Long.parseLong(attribute.INTEGER_LITERAL().getText());
-
setStorageGroupStatement.setTimePartitionInterval(timePartitionInterval);
- }
- }
+ if (ctx.storageGroupAttributesClause() != null) {
+ parseStorageGroupAttributesClause(
+ setStorageGroupStatement, ctx.storageGroupAttributesClause());
}
return setStorageGroupStatement;
}
+ @Override
+ public Statement
visitCreateStorageGroup(IoTDBSqlParser.CreateStorageGroupContext ctx) {
+ SetStorageGroupStatement setStorageGroupStatement = new
SetStorageGroupStatement();
+ PartialPath path = parsePrefixPath(ctx.prefixPath());
+ setStorageGroupStatement.setStorageGroupPath(path);
+ if (ctx.storageGroupAttributesClause() != null) {
+ parseStorageGroupAttributesClause(
+ setStorageGroupStatement, ctx.storageGroupAttributesClause());
+ }
+ return setStorageGroupStatement;
+ }
+
+ private void parseStorageGroupAttributesClause(
+ SetStorageGroupStatement setStorageGroupStatement,
+ IoTDBSqlParser.StorageGroupAttributesClauseContext ctx) {
+ for (IoTDBSqlParser.StorageGroupAttributeClauseContext attribute :
+ ctx.storageGroupAttributeClause()) {
+ if (attribute.TTL() != null) {
+ long ttl = Long.parseLong(attribute.INTEGER_LITERAL().getText());
+ setStorageGroupStatement.setTtl(ttl);
+ } else if (attribute.SCHEMA_REPLICATION_FACTOR() != null) {
+ int schemaReplicationFactor =
Integer.parseInt(attribute.INTEGER_LITERAL().getText());
+
setStorageGroupStatement.setSchemaReplicationFactor(schemaReplicationFactor);
+ } else if (attribute.DATA_REPLICATION_FACTOR() != null) {
+ int dataReplicationFactor =
Integer.parseInt(attribute.INTEGER_LITERAL().getText());
+
setStorageGroupStatement.setDataReplicationFactor(dataReplicationFactor);
+ } else if (attribute.TIME_PARTITION_INTERVAL() != null) {
+ long timePartitionInterval =
Long.parseLong(attribute.INTEGER_LITERAL().getText());
+
setStorageGroupStatement.setTimePartitionInterval(timePartitionInterval);
+ }
+ }
+ }
+
@Override
public Statement visitSetTTL(IoTDBSqlParser.SetTTLContext ctx) {
SetTTLStatement setTTLStatement = new SetTTLStatement();
diff --git
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/LogicalPlanner.java
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/LogicalPlanner.java
index 1f008ab26d..1cfce05a56 100644
---
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/LogicalPlanner.java
+++
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/LogicalPlanner.java
@@ -273,14 +273,19 @@ public class LogicalPlanner {
}
} else {
planBuilder =
- planBuilder.planAggregationSource(
- sourceExpressions,
- queryStatement.getResultOrder(),
- analysis.getGlobalTimeFilter(),
- analysis.getGroupByTimeParameter(),
- aggregationExpressions,
- analysis.getGroupByLevelExpressions(),
- analysis.getTypeProvider());
+ planBuilder
+ .planAggregationSource(
+ sourceExpressions,
+ queryStatement.getResultOrder(),
+ analysis.getGlobalTimeFilter(),
+ analysis.getGroupByTimeParameter(),
+ aggregationExpressions,
+ analysis.getGroupByLevelExpressions(),
+ analysis.getTypeProvider())
+ .planTransform(
+ transformExpressions,
+ queryStatement.isGroupByTime(),
+ queryStatement.getSelectComponent().getZoneId());
}
return planBuilder.getRoot();