drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject drill git commit: DRILL-3802: Throw unsupported error for ROLLUP, CUBE, GROUPING SETS, GROUPING, GROUPING_ID, GROUP_ID
Date Thu, 22 Oct 2015 04:27:00 GMT
Repository: drill
Updated Branches:
  refs/heads/master e293952bc -> 19b4b798b


DRILL-3802: Throw unsupported error for ROLLUP, CUBE, GROUPING SETS, GROUPING, GROUPING_ID,
GROUP_ID

close apache/drill#209


Project: http://git-wip-us.apache.org/repos/asf/drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/19b4b798
Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/19b4b798
Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/19b4b798

Branch: refs/heads/master
Commit: 19b4b798b6756c6a140a05c2ca8e6e79778b1df1
Parents: e293952
Author: Jinfeng Ni <jni@apache.org>
Authored: Mon Oct 19 10:19:03 2015 -0700
Committer: Jinfeng Ni <jni@apache.org>
Committed: Wed Oct 21 15:36:16 2015 -0700

----------------------------------------------------------------------
 .../sql/parser/UnsupportedOperatorsVisitor.java | 106 +++++++++++++++++++
 .../apache/drill/TestDisabledFunctionality.java |  78 ++++++++++++++
 2 files changed, 184 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/19b4b798/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/parser/UnsupportedOperatorsVisitor.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/parser/UnsupportedOperatorsVisitor.java
b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/parser/UnsupportedOperatorsVisitor.java
index 188095c..effe022 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/parser/UnsupportedOperatorsVisitor.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/parser/UnsupportedOperatorsVisitor.java
@@ -18,6 +18,9 @@
 package org.apache.drill.exec.planner.sql.parser;
 
 import org.apache.calcite.sql.SqlNumericLiteral;
+import org.apache.calcite.sql.SqlOperator;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.sql.util.SqlBasicVisitor;
 import org.apache.drill.exec.ExecConstants;
 import org.apache.drill.exec.exception.UnsupportedOperatorCollector;
 import org.apache.drill.exec.ops.QueryContext;
@@ -88,6 +91,10 @@ public class UnsupportedOperatorsVisitor extends SqlShuttle {
     if(sqlCall instanceof SqlSelect) {
       SqlSelect sqlSelect = (SqlSelect) sqlCall;
 
+      checkGrouping((sqlSelect));
+
+      checkRollupCubeGrpSets(sqlSelect);
+
       for(SqlNode nodeInSelectList : sqlSelect.getSelectList()) {
         // If the window function is used with an alias,
         // enter the first operand of AS operator
@@ -305,6 +312,105 @@ public class UnsupportedOperatorsVisitor extends SqlShuttle {
     return sqlCall.getOperator().acceptCall(this, sqlCall);
   }
 
+  private void checkRollupCubeGrpSets(SqlSelect sqlSelect) {
+    final ExprFinder rollupCubeGrpSetsFinder = new ExprFinder(RollupCubeGrpSets);
+    sqlSelect.accept(rollupCubeGrpSetsFinder);
+    if (rollupCubeGrpSetsFinder.find()) {
+      unsupportedOperatorCollector.setException(SqlUnsupportedException.ExceptionType.FUNCTION,
+          "Rollup, Cube, Grouping Sets are not supported in GROUP BY clause.\n" +
+              "See Apache Drill JIRA: DRILL-3962");
+      throw new UnsupportedOperationException();
+    }
+  }
+
+  private void checkGrouping(SqlSelect sqlSelect) {
+    final ExprFinder groupingFinder = new ExprFinder(GroupingID);
+    sqlSelect.accept(groupingFinder);
+    if (groupingFinder.find()) {
+      unsupportedOperatorCollector.setException(SqlUnsupportedException.ExceptionType.FUNCTION,
+          "Grouping, Grouping_ID, Group_ID are not supported.\n" +
+              "See Apache Drill JIRA: DRILL-3962");
+      throw new UnsupportedOperationException();
+    }
+  }
+
+  /**
+   * A function that replies true or false for a given expression.
+   *
+   * @see org.apache.calcite.rel.rules.PushProjector.OperatorExprCondition
+   */
+  private interface SqlNodeCondition {
+    /**
+     * Evaluates a condition for a given expression.
+     *
+     * @param sqlNode Expression
+     * @return result of evaluating the condition
+     */
+    boolean test(SqlNode sqlNode);
+  }
+
+  /**
+   * A condition that returns true if SqlNode has rollup, cube, grouping_sets.
+   * */
+  private final SqlNodeCondition RollupCubeGrpSets = new SqlNodeCondition() {
+    @Override
+    public boolean test(SqlNode sqlNode) {
+      if (sqlNode instanceof SqlCall) {
+        final SqlOperator operator = ((SqlCall) sqlNode).getOperator();
+        if (operator == SqlStdOperatorTable.ROLLUP
+            || operator == SqlStdOperatorTable.CUBE
+            || operator == SqlStdOperatorTable.GROUPING_SETS) {
+          return true;
+        }
+      }
+      return false;
+    }
+  };
+
+  /**
+   * A condition that returns true if SqlNode has Grouping, Grouping_ID, GROUP_ID.
+   */
+  private final SqlNodeCondition GroupingID = new SqlNodeCondition() {
+    @Override
+    public boolean test(SqlNode sqlNode) {
+      if (sqlNode instanceof SqlCall) {
+        final SqlOperator operator = ((SqlCall) sqlNode).getOperator();
+        if (operator == SqlStdOperatorTable.GROUPING
+            || operator == SqlStdOperatorTable.GROUPING_ID
+            || operator == SqlStdOperatorTable.GROUP_ID) {
+          return true;
+        }
+      }
+      return false;
+    }
+  };
+
+  /**
+   * A visitor to check if the given SqlNodeCondition is tested as true or not.
+   * If the condition is true, mark flag 'find' as true.
+   */
+  private static class ExprFinder extends SqlBasicVisitor<Void> {
+    private boolean find = false;
+    private final SqlNodeCondition condition;
+
+    public ExprFinder(SqlNodeCondition condition) {
+      this.find = false;
+      this.condition = condition;
+    }
+
+    public boolean find() {
+      return this.find;
+    }
+
+    @Override
+    public Void visit(SqlCall call) {
+      if (this.condition.test(call)) {
+        this.find = true;
+      }
+      return super.visit(call);
+    }
+  }
+
   private boolean containsFlatten(SqlNode sqlNode) throws UnsupportedOperationException {
     return sqlNode instanceof SqlCall
         && ((SqlCall) sqlNode).getOperator().getName().toLowerCase().equals("flatten");

http://git-wip-us.apache.org/repos/asf/drill/blob/19b4b798/exec/java-exec/src/test/java/org/apache/drill/TestDisabledFunctionality.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/TestDisabledFunctionality.java
b/exec/java-exec/src/test/java/org/apache/drill/TestDisabledFunctionality.java
index f53cc0f..fdf39c1 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/TestDisabledFunctionality.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/TestDisabledFunctionality.java
@@ -336,4 +336,82 @@ public class TestDisabledFunctionality extends BaseTestQuery{
     final String query = "select * from cp.`parquet/decimal_dictionary.parquet`";
     errorMsgTestHelper(query, ExecErrorConstants.DECIMAL_DISABLE_ERR_MSG);
   }
+
+  @Test (expected = UnsupportedFunctionException.class) //DRILL-3802
+  public void testDisableRollup() throws Exception{
+    try {
+      final String query = "select n_regionkey, count(*) as cnt from cp.`tpch/nation.parquet`
group by rollup(n_regionkey, n_name)";
+      test(query);
+    } catch(UserException ex) {
+      throwAsUnsupportedException(ex);
+      throw ex;
+    }
+  }
+
+  @Test (expected = UnsupportedFunctionException.class) //DRILL-3802
+  public void testDisableCube() throws Exception{
+    try {
+      final String query = "select n_regionkey, count(*) as cnt from cp.`tpch/nation.parquet`
group by cube(n_regionkey, n_name)";
+      test(query);
+    } catch(UserException ex) {
+      throwAsUnsupportedException(ex);
+      throw ex;
+    }
+  }
+
+  @Test (expected = UnsupportedFunctionException.class) //DRILL-3802
+  public void testDisableGroupingSets() throws Exception{
+    try {
+      final String query = "select n_regionkey, count(*) as cnt from cp.`tpch/nation.parquet`
group by grouping sets(n_regionkey, n_name)";
+      test(query);
+    } catch(UserException ex) {
+      throwAsUnsupportedException(ex);
+      throw ex;
+    }
+  }
+
+  @Test (expected = UnsupportedFunctionException.class) //DRILL-3802
+  public void testDisableGrouping() throws Exception{
+    try {
+      final String query = "select n_regionkey, count(*), GROUPING(n_regionkey) from cp.`tpch/nation.parquet`
group by n_regionkey;";
+      test(query);
+    } catch(UserException ex) {
+      throwAsUnsupportedException(ex);
+      throw ex;
+    }
+  }
+
+  @Test (expected = UnsupportedFunctionException.class) //DRILL-3802
+  public void testDisableGrouping_ID() throws Exception{
+    try {
+      final String query = "select n_regionkey, count(*), GROUPING_ID(n_regionkey) from cp.`tpch/nation.parquet`
group by n_regionkey;";
+      test(query);
+    } catch(UserException ex) {
+      throwAsUnsupportedException(ex);
+      throw ex;
+    }
+  }
+
+  @Test (expected = UnsupportedFunctionException.class) //DRILL-3802
+  public void testDisableGroup_ID() throws Exception{
+    try {
+      final String query = "select n_regionkey, count(*), GROUP_ID() from cp.`tpch/nation.parquet`
group by n_regionkey;";
+      test(query);
+    } catch(UserException ex) {
+      throwAsUnsupportedException(ex);
+      throw ex;
+    }
+  }
+
+  @Test (expected = UnsupportedFunctionException.class) //DRILL-3802
+  public void testDisableGroupingInFilter() throws Exception{
+    try {
+      final String query = "select n_regionkey, count(*) from cp.`tpch/nation.parquet` group
by n_regionkey HAVING GROUPING(n_regionkey) = 1";
+      test(query);
+    } catch(UserException ex) {
+      throwAsUnsupportedException(ex);
+      throw ex;
+    }
+  }
+
 }
\ No newline at end of file


Mime
View raw message