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

amansinha pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/drill.git

commit 76728e5ecd30418862f4bc1d32bc315042851eb1
Author: chunhui-shi <c...@maprtech.com>
AuthorDate: Fri Feb 2 10:03:38 2018 -0800

    DRILL-6321: Customize Drill's conformance. Allow support to APPLY keywords
    
    close apache/drill#1224
    
    Conflicts:
        
exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/SqlConverter.java
    
    Fix checkstyle
---
 .../drill/exec/planner/sql/DrillConformance.java   | 43 ++++++++++++++++++++
 .../drill/exec/planner/sql/DrillParserConfig.java  |  4 +-
 .../drill/exec/planner/sql/SqlConverter.java       | 34 ++++++++--------
 .../org/apache/drill/exec/sql/TestConformance.java | 46 ++++++++++++++++++++++
 4 files changed, 109 insertions(+), 18 deletions(-)

diff --git 
a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillConformance.java
 
b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillConformance.java
new file mode 100644
index 0000000..e6efeb9
--- /dev/null
+++ 
b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillConformance.java
@@ -0,0 +1,43 @@
+/*
+ * 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.drill.exec.planner.sql;
+
+import org.apache.calcite.sql.validate.SqlConformanceEnum;
+import org.apache.calcite.sql.validate.SqlDelegatingConformance;
+
+/**
+ * Drill's SQL conformance is SqlConformanceEnum.DEFAULT except for method 
isApplyAllowed().
+ * Since Drill is going to allow OUTER APPLY and CROSS APPLY to allow each row 
from left child of Join
+ * to join with output of right side (sub-query or table function that will be 
invoked for each row).
+ * Refer to DRILL-5999 for more information.
+ */
+public class DrillConformance extends SqlDelegatingConformance {
+
+  public DrillConformance() {
+    super(SqlConformanceEnum.DEFAULT);
+  }
+
+  public DrillConformance(SqlConformanceEnum flavor) {
+    super(flavor);
+  }
+
+  @Override
+  public boolean isApplyAllowed() {
+    return true;
+  }
+}
diff --git 
a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillParserConfig.java
 
b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillParserConfig.java
index 1f67c5e..575ad86 100644
--- 
a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillParserConfig.java
+++ 
b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillParserConfig.java
@@ -22,7 +22,6 @@ import org.apache.calcite.avatica.util.Quoting;
 import org.apache.calcite.sql.parser.SqlParser;
 import org.apache.calcite.sql.parser.SqlParserImplFactory;
 import org.apache.calcite.sql.validate.SqlConformance;
-import org.apache.calcite.sql.validate.SqlConformanceEnum;
 import org.apache.drill.exec.planner.physical.PlannerSettings;
 import 
org.apache.drill.exec.planner.sql.parser.impl.DrillParserWithCompoundIdConverter;
 
@@ -30,6 +29,7 @@ public class DrillParserConfig implements SqlParser.Config {
 
   private final long identifierMaxLength;
   private final Quoting quotingIdentifiers;
+  public final static SqlConformance DRILL_CONFORMANCE = new 
DrillConformance();
 
   public DrillParserConfig(PlannerSettings settings) {
     identifierMaxLength = settings.getIdentifierMaxLength();
@@ -63,7 +63,7 @@ public class DrillParserConfig implements SqlParser.Config {
 
   @Override
   public SqlConformance conformance() {
-    return SqlConformanceEnum.DEFAULT;
+    return DRILL_CONFORMANCE;
   }
 
   @Override
diff --git 
a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/SqlConverter.java
 
b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/SqlConverter.java
index 7342256..c7e1b25 100644
--- 
a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/SqlConverter.java
+++ 
b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/SqlConverter.java
@@ -58,7 +58,7 @@ import org.apache.calcite.sql.parser.SqlParser;
 import org.apache.calcite.sql.parser.SqlParserPos;
 import org.apache.calcite.sql.type.SqlTypeName;
 import org.apache.calcite.sql.util.ChainedSqlOperatorTable;
-import org.apache.calcite.sql.validate.SqlConformanceEnum;
+import org.apache.calcite.sql.validate.SqlConformance;
 import org.apache.calcite.sql.validate.SqlValidatorCatalogReader;
 import org.apache.calcite.sql.validate.SqlValidatorImpl;
 import org.apache.calcite.sql.validate.SqlValidatorScope;
@@ -139,7 +139,7 @@ public class SqlConverter {
         session);
     this.opTab = new 
ChainedSqlOperatorTable(Arrays.asList(context.getDrillOperatorTable(), 
catalog));
     this.costFactory = (settings.useDefaultCosting()) ? null : new 
DrillCostBase.DrillCostFactory();
-    this.validator = new DrillValidator(opTab, catalog, typeFactory, 
SqlConformanceEnum.DEFAULT);
+    this.validator = new DrillValidator(opTab, catalog, typeFactory, 
parserConfig.conformance());
     validator.setIdentifierExpansion(true);
     cluster = null;
   }
@@ -159,7 +159,7 @@ public class SqlConverter {
     this.catalog = catalog;
     this.opTab = parent.opTab;
     this.planner = parent.planner;
-    this.validator = new DrillValidator(opTab, catalog, typeFactory, 
SqlConformanceEnum.DEFAULT);
+    this.validator = new DrillValidator(opTab, catalog, typeFactory, 
parserConfig.conformance());
     this.temporarySchema = parent.temporarySchema;
     this.session = parent.session;
     this.drillConfig = parent.drillConfig;
@@ -240,7 +240,7 @@ public class SqlConverter {
   private class DrillValidator extends SqlValidatorImpl {
 
     protected DrillValidator(SqlOperatorTable opTab, SqlValidatorCatalogReader 
catalogReader,
-        RelDataTypeFactory typeFactory, SqlConformanceEnum conformance) {
+        RelDataTypeFactory typeFactory, SqlConformance conformance) {
       super(opTab, catalogReader, typeFactory, conformance);
     }
 
@@ -250,20 +250,22 @@ public class SqlConverter {
         RelDataType targetRowType,
         SqlValidatorScope scope) {
       switch (node.getKind()) {
-      case AS:
-        if (((SqlCall) node).operand(0) instanceof SqlIdentifier) {
-          SqlIdentifier tempNode = ((SqlCall) node).operand(0);
-          DrillCalciteCatalogReader catalogReader = 
(SqlConverter.DrillCalciteCatalogReader) getCatalogReader();
-
-          // Check the schema and throw a valid SchemaNotFound exception 
instead of TableNotFound exception.
-          if (catalogReader.getTable(Lists.newArrayList(tempNode.names)) == 
null) {
-            catalogReader.isValidSchema(tempNode.names);
+        case AS:
+          if (((SqlCall) node).operand(0) instanceof SqlIdentifier) {
+            SqlIdentifier tempNode = ((SqlCall) node).operand(0);
+            DrillCalciteCatalogReader catalogReader = 
(SqlConverter.DrillCalciteCatalogReader) getCatalogReader();
+
+            // Check the schema and throw a valid SchemaNotFound exception 
instead of TableNotFound exception.
+            if (catalogReader.getTable(Lists.newArrayList(tempNode.names)) == 
null) {
+              catalogReader.isValidSchema(tempNode.names);
+            }
+            changeNamesIfTableIsTemporary(tempNode);
           }
-          changeNamesIfTableIsTemporary(tempNode);
-        }
-      default:
-        super.validateFrom(node, targetRowType, scope);
+          break;
+        default:
+          break;
       }
+      super.validateFrom(node, targetRowType, scope);
     }
 
     @Override
diff --git 
a/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestConformance.java 
b/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestConformance.java
new file mode 100644
index 0000000..4af1a84
--- /dev/null
+++ 
b/exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestConformance.java
@@ -0,0 +1,46 @@
+/*
+ * 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.drill.exec.sql;
+
+import org.apache.drill.PlanTestBase;
+import org.apache.drill.categories.SqlTest;
+import org.apache.drill.test.BaseTestQuery;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+@Category(SqlTest.class)
+public class TestConformance extends BaseTestQuery {
+
+  @Test
+  public void testApply() throws Exception{
+
+    //cross join is not support yet in Drill: DRILL-1921, so we are testing 
OUTER APPLY only
+    String query = "SELECT c.c_nationkey, o.orderdate from " +
+      "cp.`tpch/customer.parquet` c outer apply " +
+      "cp.`tpch/orders.parquet` o " +
+      "where c.c_custkey = o.o_custkey";
+
+    PlanTestBase.testPlanMatchingPatterns(query,
+        new String[] {"Join"}, new String[] {}
+    );
+
+    return;
+  }
+
+
+}

-- 
To stop receiving notification emails like this one, please contact
amansi...@apache.org.

Reply via email to