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 f292a4e1b1d Delete useless group by time
f292a4e1b1d is described below
commit f292a4e1b1dd7551842b896b245b2383b6a31fdd
Author: Jackie Tien <[email protected]>
AuthorDate: Tue Aug 27 21:07:16 2024 +0800
Delete useless group by time
---
.../plan/relational/sql/ast/AstVisitor.java | 4 -
.../plan/relational/sql/ast/GroupByTime.java | 145 ---------------------
.../plan/relational/sql/parser/AstBuilder.java | 142 +++++---------------
.../db/relational/grammar/sql/RelationalSql.g4 | 12 +-
4 files changed, 32 insertions(+), 271 deletions(-)
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/AstVisitor.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/AstVisitor.java
index 0c4f2518ace..6ee3137851c 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/AstVisitor.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/AstVisitor.java
@@ -427,10 +427,6 @@ public abstract class AstVisitor<R, C> {
return visitNode(node, context);
}
- protected R visitGroupByTime(GroupByTime node, C context) {
- return visitGroupingElement(node, context);
- }
-
protected R visitGroupingSets(GroupingSets node, C context) {
return visitGroupingElement(node, context);
}
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/GroupByTime.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/GroupByTime.java
deleted file mode 100644
index 2d4068e6c27..00000000000
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/GroupByTime.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * 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.queryengine.plan.relational.sql.ast;
-
-import org.apache.tsfile.utils.TimeDuration;
-
-import java.util.Collections;
-import java.util.List;
-import java.util.Objects;
-
-public class GroupByTime extends GroupingElement {
-
- // [startTime, endTime)
- private final long startTime;
- private final long endTime;
- // time interval
- private final TimeDuration interval;
- // sliding step
- private final TimeDuration slidingStep;
- // if it is left close and right open interval
- private final boolean leftCRightO;
-
- public GroupByTime(
- long startTime,
- long endTime,
- TimeDuration interval,
- TimeDuration slidingStep,
- boolean leftCRightO) {
- super(null);
- this.startTime = startTime;
- this.endTime = endTime;
- this.interval = interval;
- this.slidingStep = slidingStep;
- this.leftCRightO = leftCRightO;
- }
-
- public GroupByTime(
- NodeLocation location,
- long startTime,
- long endTime,
- TimeDuration interval,
- TimeDuration slidingStep,
- boolean leftCRightO) {
- super(location);
- this.startTime = startTime;
- this.endTime = endTime;
- this.interval = interval;
- this.slidingStep = slidingStep;
- this.leftCRightO = leftCRightO;
- }
-
- @Override
- public List<Expression> getExpressions() {
- return Collections.emptyList();
- }
-
- @Override
- protected <R, C> R accept(AstVisitor<R, C> visitor, C context) {
- return visitor.visitGroupByTime(this, context);
- }
-
- @Override
- public List<? extends Node> getChildren() {
- return Collections.emptyList();
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
- GroupByTime that = (GroupByTime) o;
- return startTime == that.startTime
- && endTime == that.endTime
- && leftCRightO == that.leftCRightO
- && Objects.equals(interval, that.interval)
- && Objects.equals(slidingStep, that.slidingStep);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(startTime, endTime, interval, slidingStep,
leftCRightO);
- }
-
- @Override
- public String toString() {
- return "GroupByTime{"
- + "startTime="
- + startTime
- + ", endTime="
- + endTime
- + ", interval="
- + interval
- + ", slidingStep="
- + slidingStep
- + ", leftCRightO="
- + leftCRightO
- + '}';
- }
-
- @Override
- public boolean shallowEquals(Node other) {
- return sameClass(this, other);
- }
-
- public long getStartTime() {
- return startTime;
- }
-
- public long getEndTime() {
- return endTime;
- }
-
- public TimeDuration getInterval() {
- return interval;
- }
-
- public TimeDuration getSlidingStep() {
- return slidingStep;
- }
-
- public boolean isLeftCRightO() {
- return leftCRightO;
- }
-}
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/AstBuilder.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/AstBuilder.java
index 928529452da..7b051095e2d 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/AstBuilder.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/AstBuilder.java
@@ -64,7 +64,6 @@ import
org.apache.iotdb.db.queryengine.plan.relational.sql.ast.Flush;
import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.FunctionCall;
import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.GenericDataType;
import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.GroupBy;
-import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.GroupByTime;
import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.GroupingElement;
import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.GroupingSets;
import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.Identifier;
@@ -128,7 +127,6 @@ import
org.apache.iotdb.db.queryengine.plan.relational.sql.ast.SubqueryExpressio
import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.Table;
import
org.apache.iotdb.db.queryengine.plan.relational.sql.ast.TableExpressionType;
import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.TableSubquery;
-import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.TimeRange;
import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.Trim;
import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.TypeParameter;
import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.Union;
@@ -932,115 +930,6 @@ public class AstBuilder extends
RelationalSqlBaseVisitor<Node> {
visit(ctx.groupingElement(), GroupingElement.class));
}
- @Override
- public Node visitTimenGrouping(RelationalSqlParser.TimenGroupingContext ctx)
{
- long startTime = 0;
- long endTime = 0;
- boolean leftCRightO = true;
- if (ctx.timeRange() != null) {
- TimeRange timeRange = (TimeRange) visit(ctx.timeRange());
- startTime = timeRange.getStartTime();
- endTime = timeRange.getEndTime();
- leftCRightO = timeRange.isLeftCRightO();
- }
- // Parse time interval
- TimeDuration interval =
DateTimeUtils.constructTimeDuration(ctx.windowInterval.getText());
- TimeDuration slidingStep = interval;
- if (ctx.windowStep != null) {
- slidingStep =
DateTimeUtils.constructTimeDuration(ctx.windowStep.getText());
- }
-
- if (interval.monthDuration <= 0 && interval.nonMonthDuration <= 0) {
- throw new SemanticException(
- "The second parameter time interval should be a positive integer.");
- }
-
- if (slidingStep.monthDuration <= 0 && slidingStep.nonMonthDuration <= 0) {
- throw new SemanticException(
- "The third parameter time slidingStep should be a positive
integer.");
- }
- return new GroupByTime(
- getLocation(ctx), startTime, endTime, interval, slidingStep,
leftCRightO);
- }
-
- @Override
- public Node
visitLeftClosedRightOpen(RelationalSqlParser.LeftClosedRightOpenContext ctx) {
- return getTimeRange(ctx.timeValue(0), ctx.timeValue(1), true);
- }
-
- @Override
- public Node
visitLeftOpenRightClosed(RelationalSqlParser.LeftOpenRightClosedContext ctx) {
- return getTimeRange(ctx.timeValue(0), ctx.timeValue(1), false);
- }
-
- private TimeRange getTimeRange(
- RelationalSqlParser.TimeValueContext left,
- RelationalSqlParser.TimeValueContext right,
- boolean leftCRightO) {
- long currentTime = CommonDateTimeUtils.currentTime();
- long startTime = parseTimeValue(left, currentTime);
- long endTime = parseTimeValue(right, currentTime);
- if (startTime >= endTime) {
- throw new SemanticException("Start time should be smaller than endTime
in GroupBy");
- }
- return new TimeRange(startTime, endTime, leftCRightO);
- }
-
- private long parseTimeValue(RelationalSqlParser.TimeValueContext ctx, long
currentTime) {
- if (ctx.INTEGER_VALUE() != null) {
- try {
- if (ctx.MINUS() != null) {
- return -Long.parseLong(ctx.INTEGER_VALUE().getText());
- }
- return Long.parseLong(ctx.INTEGER_VALUE().getText());
- } catch (NumberFormatException e) {
- throw new SemanticException(
- String.format("Can not parse %s to long value",
ctx.INTEGER_VALUE().getText()));
- }
- } else {
- return parseDateExpression(ctx.dateExpression(), currentTime);
- }
- }
-
- private Long parseDateExpression(
- RelationalSqlParser.DateExpressionContext ctx, long currentTime) {
- long time;
- time = parseDateTimeFormat(ctx.getChild(0).getText(), currentTime, zoneId);
- for (int i = 1; i < ctx.getChildCount(); i = i + 2) {
- if ("+".equals(ctx.getChild(i).getText())) {
- time += DateTimeUtils.convertDurationStrToLong(time, ctx.getChild(i +
1).getText(), false);
- } else {
- time -= DateTimeUtils.convertDurationStrToLong(time, ctx.getChild(i +
1).getText(), false);
- }
- }
- return time;
- }
-
- @Override
- public Node
visitVariationGrouping(RelationalSqlParser.VariationGroupingContext ctx) {
- return super.visitVariationGrouping(ctx);
- }
-
- @Override
- public Node
visitConditionGrouping(RelationalSqlParser.ConditionGroupingContext ctx) {
- return super.visitConditionGrouping(ctx);
- }
-
- @Override
- public Node visitSessionGrouping(RelationalSqlParser.SessionGroupingContext
ctx) {
- return super.visitSessionGrouping(ctx);
- }
-
- @Override
- public Node visitCountGrouping(RelationalSqlParser.CountGroupingContext ctx)
{
- return super.visitCountGrouping(ctx);
- }
-
- @Override
- public Node visitKeepExpression(RelationalSqlParser.KeepExpressionContext
ctx) {
- return super.visitKeepExpression(ctx);
- }
-
@Override
public Node
visitSingleGroupingSet(RelationalSqlParser.SingleGroupingSetContext ctx) {
return new SimpleGroupBy(
@@ -1484,6 +1373,20 @@ public class AstBuilder extends
RelationalSqlBaseVisitor<Node> {
parseDateExpression(ctx.dateExpression(),
CommonDateTimeUtils.currentTime())));
}
+ private Long parseDateExpression(
+ RelationalSqlParser.DateExpressionContext ctx, long currentTime) {
+ long time;
+ time = parseDateTimeFormat(ctx.getChild(0).getText(), currentTime, zoneId);
+ for (int i = 1; i < ctx.getChildCount(); i = i + 2) {
+ if ("+".equals(ctx.getChild(i).getText())) {
+ time += DateTimeUtils.convertDurationStrToLong(time, ctx.getChild(i +
1).getText(), false);
+ } else {
+ time -= DateTimeUtils.convertDurationStrToLong(time, ctx.getChild(i +
1).getText(), false);
+ }
+ }
+ return time;
+ }
+
@Override
public Node visitTrim(RelationalSqlParser.TrimContext ctx) {
if (ctx.FROM() != null && ctx.trimsSpecification() == null && ctx.trimChar
== null) {
@@ -1645,6 +1548,7 @@ public class AstBuilder extends
RelationalSqlBaseVisitor<Node> {
return new FunctionCall(getLocation(ctx), name, distinct, arguments);
}
+ @Override
public Node visitDateBin(RelationalSqlParser.DateBinContext ctx) {
TimeDuration timeDuration =
DateTimeUtils.constructTimeDuration(ctx.timeDuration().getText());
@@ -1673,6 +1577,22 @@ public class AstBuilder extends
RelationalSqlBaseVisitor<Node> {
getLocation(ctx), QualifiedName.of(DATE_BIN.getFunctionName()),
arguments);
}
+ private long parseTimeValue(RelationalSqlParser.TimeValueContext ctx, long
currentTime) {
+ if (ctx.INTEGER_VALUE() != null) {
+ try {
+ if (ctx.MINUS() != null) {
+ return -Long.parseLong(ctx.INTEGER_VALUE().getText());
+ }
+ return Long.parseLong(ctx.INTEGER_VALUE().getText());
+ } catch (NumberFormatException e) {
+ throw new SemanticException(
+ String.format("Can not parse %s to long value",
ctx.INTEGER_VALUE().getText()));
+ }
+ } else {
+ return parseDateExpression(ctx.dateExpression(), currentTime);
+ }
+ }
+
// ************** literals **************
@Override
diff --git
a/iotdb-core/relational-grammar/src/main/antlr4/org/apache/iotdb/db/relational/grammar/sql/RelationalSql.g4
b/iotdb-core/relational-grammar/src/main/antlr4/org/apache/iotdb/db/relational/grammar/sql/RelationalSql.g4
index 395c902636d..c029d4d3ce3 100644
---
a/iotdb-core/relational-grammar/src/main/antlr4/org/apache/iotdb/db/relational/grammar/sql/RelationalSql.g4
+++
b/iotdb-core/relational-grammar/src/main/antlr4/org/apache/iotdb/db/relational/grammar/sql/RelationalSql.g4
@@ -426,23 +426,13 @@ groupBy
;
groupingElement
- : TIME '(' (timeRange ',')? windowInterval=timeDuration (','
windowStep=timeDuration)?')' #timenGrouping
- | VARIATION '(' expression (',' delta=number)? (',' propertyAssignments)?
')' #variationGrouping
- | CONDITION '(' expression (',' keepExpression)? (','
propertyAssignments)? ')' #conditionGrouping
- | SESSION '(' timeInterval=timeDuration ')'
#sessionGrouping
- | COUNT '(' expression ',' countNumber=INTEGER_VALUE (','
propertyAssignments)? ')' #countGrouping
- | groupingSet
#singleGroupingSet
+ : groupingSet
#singleGroupingSet
// the following three haven't been supported yet
| ROLLUP '(' (groupingSet (',' groupingSet)*)? ')'
#rollup
| CUBE '(' (groupingSet (',' groupingSet)*)? ')'
#cube
| GROUPING SETS '(' groupingSet (',' groupingSet)* ')'
#multipleGroupingSets
;
-timeRange
- : '[' startTime=timeValue ',' endTime=timeValue ')'
#leftClosedRightOpen
- | '(' startTime=timeValue ',' endTime=timeValue ']'
#leftOpenRightClosed
- ;
-
timeValue
: dateExpression
| (PLUS | MINUS)? INTEGER_VALUE