You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by mm...@apache.org on 2018/07/20 17:41:36 UTC

[23/53] [abbrv] calcite git commit: [CALCITE-2304] In Babel parser, allow Hive-style syntax "LEFT SEMI JOIN"

[CALCITE-2304] In Babel parser, allow Hive-style syntax "LEFT SEMI JOIN"


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

Branch: refs/heads/site
Commit: 870e54facba01b7c3cbeb7c5386ebc0787ed50aa
Parents: 3e50a53
Author: Julian Hyde <jh...@apache.org>
Authored: Tue May 8 10:23:10 2018 -0700
Committer: Julian Hyde <jh...@apache.org>
Committed: Sun Jul 8 22:41:08 2018 -0700

----------------------------------------------------------------------
 babel/src/main/codegen/config.fmpp                          | 6 ++++++
 babel/src/main/codegen/includes/parserImpls.ftl             | 7 +++++++
 babel/src/test/resources/sql/select.iq                      | 9 +++++++++
 core/src/main/codegen/config.fmpp                           | 5 +++++
 core/src/main/codegen/templates/Parser.jj                   | 4 ++++
 core/src/main/java/org/apache/calcite/sql/JoinType.java     | 7 +++++++
 core/src/main/java/org/apache/calcite/sql/SqlJoin.java      | 3 +++
 .../org/apache/calcite/sql/validate/SqlValidatorImpl.java   | 6 ++++++
 core/src/test/codegen/config.fmpp                           | 5 +++++
 server/src/main/codegen/config.fmpp                         | 5 +++++
 10 files changed, 57 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite/blob/870e54fa/babel/src/main/codegen/config.fmpp
----------------------------------------------------------------------
diff --git a/babel/src/main/codegen/config.fmpp b/babel/src/main/codegen/config.fmpp
index 57bbe86..57b6419 100644
--- a/babel/src/main/codegen/config.fmpp
+++ b/babel/src/main/codegen/config.fmpp
@@ -33,6 +33,12 @@ data: {
         "SEMI"
       ]
 
+      # List of additional join types. Each is a method with no arguments.
+      # Example: LeftSemiJoin()
+      joinTypes: [
+        "LeftSemiJoin"
+      ]
+
       # List of methods for parsing custom SQL statements.
       statementParserMethods: [
       ]

http://git-wip-us.apache.org/repos/asf/calcite/blob/870e54fa/babel/src/main/codegen/includes/parserImpls.ftl
----------------------------------------------------------------------
diff --git a/babel/src/main/codegen/includes/parserImpls.ftl b/babel/src/main/codegen/includes/parserImpls.ftl
index 627a634..09b5d3d 100644
--- a/babel/src/main/codegen/includes/parserImpls.ftl
+++ b/babel/src/main/codegen/includes/parserImpls.ftl
@@ -15,4 +15,11 @@
 // limitations under the License.
 -->
 
+JoinType LeftSemiJoin() :
+{
+}
+{
+    <LEFT> <SEMI> <JOIN> { return JoinType.LEFT_SEMI_JOIN; }
+}
+
 // End parserImpls.ftl

http://git-wip-us.apache.org/repos/asf/calcite/blob/870e54fa/babel/src/test/resources/sql/select.iq
----------------------------------------------------------------------
diff --git a/babel/src/test/resources/sql/select.iq b/babel/src/test/resources/sql/select.iq
index ef692dc..d429c6c 100755
--- a/babel/src/test/resources/sql/select.iq
+++ b/babel/src/test/resources/sql/select.iq
@@ -29,6 +29,15 @@ FROM "scott"."EMP" AS "EMP",
 ORDER BY "EMP"."DEPTNO"
 !explain-validated-on all
 
+# LEFT SEMI JOIN (Hive only)
+SELECT *
+FROM emp LEFT SEMI JOIN dept ON emp.deptno = dept.deptno;
+
+SELECT "EMP"."EMPNO", "EMP"."ENAME", "EMP"."JOB", "EMP"."MGR", "EMP"."HIREDATE", "EMP"."SAL", "EMP"."COMM", "EMP"."DEPTNO", "DEPT"."DEPTNO" AS "DEPTNO0", "DEPT"."DNAME", "DEPT"."LOC"
+FROM "scott"."EMP" AS "EMP"
+    LEFT SEMI JOIN "scott"."DEPT" AS "DEPT" ON "EMP"."DEPTNO" = "DEPT"."DEPTNO"
+!explain-validated-on hive
+
 # Test CONNECT BY (Oracle only)
 !if (false) {
 SELECT *

http://git-wip-us.apache.org/repos/asf/calcite/blob/870e54fa/core/src/main/codegen/config.fmpp
----------------------------------------------------------------------
diff --git a/core/src/main/codegen/config.fmpp b/core/src/main/codegen/config.fmpp
index 41cfeee..2cec0c8 100644
--- a/core/src/main/codegen/config.fmpp
+++ b/core/src/main/codegen/config.fmpp
@@ -52,6 +52,11 @@ data: {
     nonReservedKeywords: [
     ]
 
+    # List of additional join types. Each is a method with no arguments.
+    # Example: LeftSemiJoin()
+    joinTypes: [
+    ]
+
     # List of methods for parsing custom SQL statements.
     # Return type of method implementation should be 'SqlNode'.
     # Example: SqlShowDatabases(), SqlShowTables().

http://git-wip-us.apache.org/repos/asf/calcite/blob/870e54fa/core/src/main/codegen/templates/Parser.jj
----------------------------------------------------------------------
diff --git a/core/src/main/codegen/templates/Parser.jj b/core/src/main/codegen/templates/Parser.jj
index 4096cfe..7fda2bc 100644
--- a/core/src/main/codegen/templates/Parser.jj
+++ b/core/src/main/codegen/templates/Parser.jj
@@ -1614,6 +1614,10 @@ SqlLiteral JoinType() :
         <FULL> [ <OUTER> ] <JOIN> { joinType = JoinType.FULL; }
     |
         <CROSS> <JOIN> { joinType = JoinType.CROSS; }
+<#list parser.joinTypes as method>
+    |
+        joinType = ${method}()
+</#list>
     )
     {
         return joinType.symbol(getPos());

http://git-wip-us.apache.org/repos/asf/calcite/blob/870e54fa/core/src/main/java/org/apache/calcite/sql/JoinType.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/JoinType.java b/core/src/main/java/org/apache/calcite/sql/JoinType.java
index acbff50..3ee64d4 100644
--- a/core/src/main/java/org/apache/calcite/sql/JoinType.java
+++ b/core/src/main/java/org/apache/calcite/sql/JoinType.java
@@ -50,6 +50,13 @@ public enum JoinType {
   RIGHT,
 
   /**
+   * Left semi join.
+   *
+   * <p>Not used by Calcite; only in Babel's Hive dialect.
+   */
+  LEFT_SEMI_JOIN,
+
+  /**
    * Comma join: the good old-fashioned SQL <code>FROM</code> clause,
    * where table expressions are specified with commas between them, and
    * join conditions are specified in the <code>WHERE</code> clause.

http://git-wip-us.apache.org/repos/asf/calcite/blob/870e54fa/core/src/main/java/org/apache/calcite/sql/SqlJoin.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/SqlJoin.java b/core/src/main/java/org/apache/calcite/sql/SqlJoin.java
index e533ee9..bf97c25 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlJoin.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlJoin.java
@@ -222,6 +222,9 @@ public class SqlJoin extends SqlCall {
       case LEFT:
         writer.sep(natural + "LEFT JOIN");
         break;
+      case LEFT_SEMI_JOIN:
+        writer.sep(natural + "LEFT SEMI JOIN");
+        break;
       case RIGHT:
         writer.sep(natural + "RIGHT JOIN");
         break;

http://git-wip-us.apache.org/repos/asf/calcite/blob/870e54fa/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java b/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
index 71b4b76..2d14bd5 100644
--- a/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
+++ b/core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
@@ -3133,6 +3133,12 @@ public class SqlValidatorImpl implements SqlValidatorWithHints {
     // Which join types require/allow a ON/USING condition, or allow
     // a NATURAL keyword?
     switch (joinType) {
+    case LEFT_SEMI_JOIN:
+      if (!conformance.isLiberal()) {
+        throw newValidationError(join.getJoinTypeNode(),
+            RESOURCE.dialectDoesNotSupportFeature("LEFT SEMI JOIN"));
+      }
+      // fall through
     case INNER:
     case LEFT:
     case RIGHT:

http://git-wip-us.apache.org/repos/asf/calcite/blob/870e54fa/core/src/test/codegen/config.fmpp
----------------------------------------------------------------------
diff --git a/core/src/test/codegen/config.fmpp b/core/src/test/codegen/config.fmpp
index 2f747e2..7833ee2 100644
--- a/core/src/test/codegen/config.fmpp
+++ b/core/src/test/codegen/config.fmpp
@@ -36,6 +36,11 @@ data: {
       nonReservedKeywords: [
       ]
 
+      # List of additional join types. Each is a method with no arguments.
+      # Example: LeftSemiJoin()
+      joinTypes: [
+      ]
+
       # List of methods for parsing custom SQL statements.
       statementParserMethods: [
         "SqlDescribeSpacePower()"

http://git-wip-us.apache.org/repos/asf/calcite/blob/870e54fa/server/src/main/codegen/config.fmpp
----------------------------------------------------------------------
diff --git a/server/src/main/codegen/config.fmpp b/server/src/main/codegen/config.fmpp
index 34fe90c..00a32ca 100644
--- a/server/src/main/codegen/config.fmpp
+++ b/server/src/main/codegen/config.fmpp
@@ -43,6 +43,11 @@ data: {
         "VIRTUAL"
       ]
 
+      # List of additional join types. Each is a method with no arguments.
+      # Example: LeftSemiJoin()
+      joinTypes: [
+      ]
+
       # List of methods for parsing custom SQL statements.
       statementParserMethods: [
       ]