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-2181: Flatten function in order by, group by, distinct, aggregate functions is disabled
Date Wed, 29 Apr 2015 23:49:39 GMT
Repository: drill
Updated Branches:
  refs/heads/master f5b0f4928 -> e428f0d56


DRILL-2181: Flatten function in order by, group by, distinct, aggregate functions is disabled


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

Branch: refs/heads/master
Commit: e428f0d56955076f0d42f39463983e7a5a0d5c0a
Parents: f5b0f49
Author: Hsuan-Yi Chu <hsuanyi@usc.edu>
Authored: Tue Apr 28 13:38:07 2015 -0700
Committer: Hsuan-Yi Chu <hsuanyi@usc.edu>
Committed: Wed Apr 29 13:38:16 2015 -0700

----------------------------------------------------------------------
 .../sql/parser/UnsupportedOperatorsVisitor.java | 64 ++++++++++++++++++++
 .../apache/drill/TestDisabledFunctionality.java | 59 ++++++++++++++++++
 2 files changed, 123 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/e428f0d5/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 45bf26f..f1ec851 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
@@ -17,6 +17,8 @@
  */
 package org.apache.drill.exec.planner.sql.parser;
 
+import org.apache.calcite.sql.SqlSelect;
+import org.apache.calcite.sql.fun.SqlCountAggFunction;
 import org.apache.drill.exec.ExecConstants;
 import org.apache.drill.exec.exception.UnsupportedOperatorCollector;
 import org.apache.drill.exec.ops.QueryContext;
@@ -135,6 +137,68 @@ public class UnsupportedOperatorsVisitor extends SqlShuttle {
       }
     }
 
+    // Disable complex functions being present in any place other than Select-Clause
+    if(sqlCall instanceof SqlSelect) {
+      SqlSelect sqlSelect = (SqlSelect) sqlCall;
+      if(sqlSelect.hasOrderBy()) {
+        for (SqlNode sqlNode : sqlSelect.getOrderList()) {
+          if(containsFlatten(sqlNode)) {
+            unsupportedOperatorCollector.setException(SqlUnsupportedException.ExceptionType.FUNCTION,
+                "Flatten function is not supported in Order By\n" +
+                "See Apache Drill JIRA: DRILL-2181");
+            throw new UnsupportedOperationException();
+          }
+        }
+      }
+
+      if(sqlSelect.getGroup() != null) {
+        for(SqlNode sqlNode : sqlSelect.getGroup()) {
+          if(containsFlatten(sqlNode)) {
+            unsupportedOperatorCollector.setException(SqlUnsupportedException.ExceptionType.FUNCTION,
+                "Flatten function is not supported in Group By\n" +
+                "See Apache Drill JIRA: DRILL-2181");
+            throw new UnsupportedOperationException();
+          }
+        }
+      }
+
+      if(sqlSelect.isDistinct()) {
+        for(SqlNode column : sqlSelect.getSelectList()) {
+          if(column.getKind() ==  SqlKind.AS) {
+            if(containsFlatten(((SqlCall) column).getOperandList().get(0))) {
+              unsupportedOperatorCollector.setException(SqlUnsupportedException.ExceptionType.FUNCTION,
+                  "Flatten function is not supported in Distinct\n" +
+                  "See Apache Drill JIRA: DRILL-2181");
+              throw new UnsupportedOperationException();
+            }
+          } else {
+            if(containsFlatten(column)) {
+              unsupportedOperatorCollector.setException(SqlUnsupportedException.ExceptionType.FUNCTION,
+                  "Flatten function is not supported in Distinct\n" +
+                  "See Apache Drill JIRA: DRILL-2181");
+              throw new UnsupportedOperationException();
+            }
+          }
+        }
+      }
+    }
+
+    if(sqlCall.getOperator() instanceof SqlCountAggFunction) {
+      for(SqlNode sqlNode : sqlCall.getOperandList()) {
+        if(containsFlatten(sqlNode)) {
+          unsupportedOperatorCollector.setException(SqlUnsupportedException.ExceptionType.FUNCTION,
+              "Flatten function in aggregate functions is not supported\n" +
+              "See Apache Drill JIRA: DRILL-2181");
+          throw new UnsupportedOperationException();
+        }
+      }
+    }
+
     return sqlCall.getOperator().acceptCall(this, sqlCall);
   }
+
+  private boolean containsFlatten(SqlNode sqlNode) throws UnsupportedOperationException {
+    return sqlNode instanceof SqlCall
+        && ((SqlCall) sqlNode).getOperator().getName().toLowerCase().equals("flatten");
+  }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/drill/blob/e428f0d5/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 d304f26..504524d 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
@@ -17,6 +17,7 @@
  */
 package org.apache.drill;
 import org.apache.drill.common.exceptions.UserException;
+import org.apache.drill.common.util.FileUtils;
 import org.apache.drill.exec.work.foreman.SqlUnsupportedException;
 import org.apache.drill.exec.work.foreman.UnsupportedDataTypeException;
 import org.apache.drill.exec.work.foreman.UnsupportedFunctionException;
@@ -307,4 +308,62 @@ public class TestDisabledFunctionality extends BaseTestQuery{
       throwAsUnsupportedException(ex);
     }
   }
+
+  @Test(expected = UnsupportedFunctionException.class) // see DRILL-2181
+  public void testFlattenWithinGroupBy() throws Exception {
+    try {
+      String root = FileUtils.getResourceAsFile("/store/text/sample.json").toURI().toString();
+      String query = String.format("select flatten(j.topping) tt " +
+          "from dfs_test.`%s` j " +
+          "group by flatten(j.topping)", root);
+
+      test(query);
+    } catch(UserException ex) {
+      throwAsUnsupportedException(ex);
+      throw ex;
+    }
+  }
+
+  @Test(expected = UnsupportedFunctionException.class) // see DRILL-2181
+  public void testFlattenWithinOrderBy() throws Exception {
+    try {
+      String root = FileUtils.getResourceAsFile("/store/text/sample.json").toURI().toString();
+      String query = String.format("select flatten(j.topping) tt " +
+          "from dfs_test.`%s` j " +
+          "order by flatten(j.topping)", root);
+
+      test(query);
+    } catch(UserException ex) {
+      throwAsUnsupportedException(ex);
+      throw ex;
+    }
+  }
+
+  @Test(expected = UnsupportedFunctionException.class) // see DRILL-2181
+  public void testFlattenWithinAggFunction() throws Exception {
+    try {
+      String root = FileUtils.getResourceAsFile("/store/text/sample.json").toURI().toString();
+      String query = String.format("select count(flatten(j.topping)) tt " +
+          "from dfs_test.`%s` j", root);
+
+      test(query);
+    } catch(UserException ex) {
+      throwAsUnsupportedException(ex);
+      throw ex;
+    }
+  }
+
+  @Test(expected = UnsupportedFunctionException.class) // see DRILL-2181
+  public void testFlattenWithinDistinct() throws Exception {
+    try {
+      String root = FileUtils.getResourceAsFile("/store/text/sample.json").toURI().toString();
+      String query = String.format("select Distinct (flatten(j.topping)) tt " +
+          "from dfs_test.`%s` j", root);
+
+      test(query);
+    } catch(UserException ex) {
+      throwAsUnsupportedException(ex);
+      throw ex;
+    }
+  }
 }
\ No newline at end of file


Mime
View raw message