You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by ki...@apache.org on 2020/05/12 15:28:46 UTC

[incubator-pinot] branch no-arg-function created (now 7869b8d)

This is an automated email from the ASF dual-hosted git repository.

kishoreg pushed a change to branch no-arg-function
in repository https://gitbox.apache.org/repos/asf/incubator-pinot.git.


      at 7869b8d  Handling a no-arg function in query parsing and expression tree

This branch includes the following new commits:

     new 7869b8d  Handling a no-arg function in query parsing and expression tree

The 1 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.



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[incubator-pinot] 01/01: Handling a no-arg function in query parsing and expression tree

Posted by ki...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

kishoreg pushed a commit to branch no-arg-function
in repository https://gitbox.apache.org/repos/asf/incubator-pinot.git

commit 7869b8dd3f98041ba04d55e47a9abfcea10d6f58
Author: kishoreg <g....@gmail.com>
AuthorDate: Tue May 12 08:27:36 2020 -0700

    Handling a no-arg function in query parsing and expression tree
---
 .../request/transform/TransformExpressionTree.java       |  6 ++++--
 .../org/apache/pinot/sql/parsers/CalciteSqlParser.java   | 16 ++++++++++------
 2 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/pinot-common/src/main/java/org/apache/pinot/common/request/transform/TransformExpressionTree.java b/pinot-common/src/main/java/org/apache/pinot/common/request/transform/TransformExpressionTree.java
index 5c0a515..46d9efa 100644
--- a/pinot-common/src/main/java/org/apache/pinot/common/request/transform/TransformExpressionTree.java
+++ b/pinot-common/src/main/java/org/apache/pinot/common/request/transform/TransformExpressionTree.java
@@ -89,8 +89,10 @@ public class TransformExpressionTree {
       _expressionType = ExpressionType.FUNCTION;
       _value = ((FunctionCallAstNode) root).getName().toLowerCase();
       _children = new ArrayList<>();
-      for (AstNode child : root.getChildren()) {
-        _children.add(new TransformExpressionTree(child));
+      if(root.hasChildren()) {
+        for (AstNode child : root.getChildren()) {
+          _children.add(new TransformExpressionTree(child));
+        }
       }
     } else if (root instanceof IdentifierAstNode) {
       _expressionType = ExpressionType.IDENTIFIER;
diff --git a/pinot-common/src/main/java/org/apache/pinot/sql/parsers/CalciteSqlParser.java b/pinot-common/src/main/java/org/apache/pinot/sql/parsers/CalciteSqlParser.java
index aa6ddf8..d428549 100644
--- a/pinot-common/src/main/java/org/apache/pinot/sql/parsers/CalciteSqlParser.java
+++ b/pinot-common/src/main/java/org/apache/pinot/sql/parsers/CalciteSqlParser.java
@@ -55,6 +55,7 @@ import org.apache.pinot.common.utils.request.RequestUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+
 public class CalciteSqlParser {
 
   private static final Logger LOGGER = LoggerFactory.getLogger(CalciteSqlParser.class);
@@ -291,7 +292,7 @@ public class CalciteSqlParser {
         throw new RuntimeException(
             "Unable to convert SqlNode: " + sqlNode + " to PinotQuery. Unknown node type: " + sqlNode.getKind());
     }
-    queryReWrite(pinotQuery);
+    queryRewrite(pinotQuery);
     return pinotQuery;
   }
 
@@ -307,7 +308,7 @@ public class CalciteSqlParser {
     return SqlParser.create(sql, parserBuilder.build());
   }
 
-  private static void queryReWrite(PinotQuery pinotQuery) {
+  private static void queryRewrite(PinotQuery pinotQuery) {
     // Update Predicate Comparison
     if (pinotQuery.isSetFilterExpression()) {
       Expression filterExpression = pinotQuery.getFilterExpression();
@@ -361,8 +362,10 @@ public class CalciteSqlParser {
         default:
           List<Expression> operands = functionCall.getOperands();
           List<Expression> newOperands = new ArrayList<>();
-          for (int i = 0; i < operands.size(); i++) {
-            newOperands.add(updateComparisonPredicate(operands.get(i)));
+          if (operands != null) {
+            for (int i = 0; i < operands.size(); i++) {
+              newOperands.add(updateComparisonPredicate(operands.get(i)));
+            }
           }
           functionCall.setOperands(newOperands);
       }
@@ -590,8 +593,9 @@ public class CalciteSqlParser {
         if (funcSqlNode.getOperator().getKind() == SqlKind.OTHER_FUNCTION) {
           funcName = funcSqlNode.getOperator().getName();
         }
-        if (funcName.equalsIgnoreCase(SqlKind.COUNT.toString()) && (funcSqlNode.getFunctionQuantifier() != null) && funcSqlNode
-            .getFunctionQuantifier().toValue().equalsIgnoreCase(AggregationFunctionType.DISTINCT.getName())) {
+        if (funcName.equalsIgnoreCase(SqlKind.COUNT.toString()) && (funcSqlNode.getFunctionQuantifier() != null)
+            && funcSqlNode.getFunctionQuantifier().toValue()
+            .equalsIgnoreCase(AggregationFunctionType.DISTINCT.getName())) {
           funcName = AggregationFunctionType.DISTINCTCOUNT.getName();
         }
         final Expression funcExpr = RequestUtils.getFunctionExpression(funcName);


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org