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/14 11:27:35 UTC

[iotdb] branch iotdb-1022-v2 updated: fix antlr

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 e78c496  fix antlr
e78c496 is described below

commit e78c49668f28ae527b16cfa67c05ea99a08a1957
Author: SteveYurongSu <st...@outlook.com>
AuthorDate: Fri May 14 19:26:52 2021 +0800

    fix antlr
---
 .../antlr4/org/apache/iotdb/db/qp/sql/SqlBase.g4   | 18 ++-----
 .../iotdb/db/qp/logical/crud/SelectOperator.java   | 11 ++++-
 .../apache/iotdb/db/qp/sql/IoTDBSqlVisitor.java    | 11 ++---
 .../expression/unary/NumberLiteralOperand.java     | 57 ----------------------
 4 files changed, 17 insertions(+), 80 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 d00b933..f846956 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
@@ -115,22 +115,12 @@ resultColumn
    ;
 
 expression
-   : numberLiteral
-   | suffixPath
-   | functionClause
-   | LR_BRACKET unary=expression RR_BRACKET
-   | (PLUS | MINUS) unary=expression
+   : (PLUS | MINUS) unary=expression
    | leftExpression=expression (STAR | DIV | MOD) rightExpression=expression
    | leftExpression=expression (PLUS | MINUS) rightExpression=expression
-   ;
-
-numberLiteral
-   : MINUS? realLiteral
-   | MINUS? INT
-   ;
-
-functionClause
-   : functionName=ID LR_BRACKET expression (COMMA expression)* functionAttribute* RR_BRACKET
+   | functionName=suffixPath LR_BRACKET expression (COMMA expression)* functionAttribute* RR_BRACKET
+   | suffixPath
+   | LR_BRACKET unary=expression RR_BRACKET
    ;
 
 functionAttribute
diff --git a/server/src/main/java/org/apache/iotdb/db/qp/logical/crud/SelectOperator.java b/server/src/main/java/org/apache/iotdb/db/qp/logical/crud/SelectOperator.java
index 434e44d..12d51ab 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/logical/crud/SelectOperator.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/logical/crud/SelectOperator.java
@@ -20,6 +20,7 @@ package org.apache.iotdb.db.qp.logical.crud;
 
 import org.apache.iotdb.db.metadata.PartialPath;
 import org.apache.iotdb.db.qp.logical.Operator;
+import org.apache.iotdb.db.query.expression.Expression;
 import org.apache.iotdb.db.query.expression.ResultColumn;
 import org.apache.iotdb.db.query.expression.unary.FunctionExpression;
 import org.apache.iotdb.db.query.expression.unary.TimeSeriesOperand;
@@ -94,7 +95,15 @@ public final class SelectOperator extends Operator {
     if (pathsCache == null) {
       pathsCache = new ArrayList<>();
       for (ResultColumn resultColumn : resultColumns) {
-        pathsCache.add(((TimeSeriesOperand) resultColumn.getExpression()).getPath());
+        Expression expression = resultColumn.getExpression();
+        if (expression instanceof TimeSeriesOperand) {
+          pathsCache.add(((TimeSeriesOperand) resultColumn.getExpression()).getPath());
+        } else {
+          TimeSeriesOperand timeSeriesOperand =
+              (TimeSeriesOperand)
+                  ((FunctionExpression) resultColumn.getExpression()).getExpressions().get(0);
+          pathsCache.add(timeSeriesOperand.getPath());
+        }
       }
     }
     return pathsCache;
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 a5bff6b..e327bc1 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
@@ -118,7 +118,6 @@ import org.apache.iotdb.db.qp.sql.SqlBaseParser.FromClauseContext;
 import org.apache.iotdb.db.qp.sql.SqlBaseParser.FullMergeContext;
 import org.apache.iotdb.db.qp.sql.SqlBaseParser.FullPathContext;
 import org.apache.iotdb.db.qp.sql.SqlBaseParser.FunctionAttributeContext;
-import org.apache.iotdb.db.qp.sql.SqlBaseParser.FunctionClauseContext;
 import org.apache.iotdb.db.qp.sql.SqlBaseParser.GrantRoleContext;
 import org.apache.iotdb.db.qp.sql.SqlBaseParser.GrantRoleToUserContext;
 import org.apache.iotdb.db.qp.sql.SqlBaseParser.GrantUserContext;
@@ -222,7 +221,6 @@ import org.apache.iotdb.db.query.expression.binary.MultiplicationExpression;
 import org.apache.iotdb.db.query.expression.binary.SubtractionExpression;
 import org.apache.iotdb.db.query.expression.unary.FunctionExpression;
 import org.apache.iotdb.db.query.expression.unary.MinusExpression;
-import org.apache.iotdb.db.query.expression.unary.NumberLiteralOperand;
 import org.apache.iotdb.db.query.expression.unary.TimeSeriesOperand;
 import org.apache.iotdb.tsfile.common.conf.TSFileDescriptor;
 import org.apache.iotdb.tsfile.common.constant.TsFileConstant;
@@ -1044,15 +1042,12 @@ public class IoTDBSqlVisitor extends SqlBaseBaseVisitor<Operator> {
   @SuppressWarnings("squid:S3776")
   private Expression parseExpression(ExpressionContext context) {
     // unary
-    if (context.numberLiteral() != null) {
-      return new NumberLiteralOperand(Double.parseDouble(context.numberLiteral().getText()));
+    if (context.functionName != null) {
+      return parseFunctionExpression(context);
     }
     if (context.suffixPath() != null) {
       return new TimeSeriesOperand(parseSuffixPath(context.suffixPath()));
     }
-    if (context.functionClause() != null) {
-      return parseFunctionExpression(context.functionClause());
-    }
     if (context.unary != null) {
       return context.MINUS() != null
           ? new MinusExpression(parseExpression(context.expression(0)))
@@ -1081,7 +1076,7 @@ public class IoTDBSqlVisitor extends SqlBaseBaseVisitor<Operator> {
     throw new UnsupportedOperationException();
   }
 
-  private Expression parseFunctionExpression(FunctionClauseContext functionClause) {
+  private Expression parseFunctionExpression(ExpressionContext functionClause) {
     FunctionExpression functionExpression =
         new FunctionExpression(functionClause.functionName.getText());
 
diff --git a/server/src/main/java/org/apache/iotdb/db/query/expression/unary/NumberLiteralOperand.java b/server/src/main/java/org/apache/iotdb/db/query/expression/unary/NumberLiteralOperand.java
deleted file mode 100644
index 7c5f3fc..0000000
--- a/server/src/main/java/org/apache/iotdb/db/query/expression/unary/NumberLiteralOperand.java
+++ /dev/null
@@ -1,57 +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.query.expression.unary;
-
-import org.apache.iotdb.db.metadata.PartialPath;
-import org.apache.iotdb.db.qp.utils.WildcardsRemover;
-import org.apache.iotdb.db.query.expression.Expression;
-import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
-
-import java.util.List;
-
-public class NumberLiteralOperand extends Expression {
-
-  protected double literal;
-
-  public NumberLiteralOperand(double literal) {
-    this.literal = literal;
-  }
-
-  @Override
-  public TSDataType dataType() {
-    return TSDataType.DOUBLE;
-  }
-
-  @Override
-  public void concat(List<PartialPath> prefixPaths, List<Expression> resultExpressions) {
-    throw new UnsupportedOperationException();
-  }
-
-  @Override
-  public void removeWildcards(
-      WildcardsRemover wildcardsRemover, List<Expression> resultExpressions) {
-    throw new UnsupportedOperationException();
-  }
-
-  @Override
-  public String toString() {
-    return String.valueOf(literal);
-  }
-}