calcite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jh...@apache.org
Subject [2/3] calcite git commit: [CALCITE-2037] Modify parser template to allow sub-projects to override SqlStmt syntax (Roman Kulyk)
Date Wed, 08 Nov 2017 17:52:56 GMT
[CALCITE-2037] Modify parser template to allow sub-projects to override SqlStmt syntax (Roman
Kulyk)

Move additional (custom) statements on the top of the SqlStmt() method in Parser.jj.

Add test to "parserextensiontesting" parser (Julian Hyde).

Close apache/calcite#561


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

Branch: refs/heads/master
Commit: 5a0403cf7a31aa80d4de179f75b8154a7b0c7a58
Parents: fe3529d
Author: Roman Kulyk <rom.kulyk@gmail.com>
Authored: Tue Nov 7 14:48:08 2017 +0000
Committer: Julian Hyde <jhyde@apache.org>
Committed: Wed Nov 8 08:41:33 2017 -0800

----------------------------------------------------------------------
 core/src/main/codegen/templates/Parser.jj                | 11 +++++------
 core/src/test/codegen/config.fmpp                        |  1 +
 core/src/test/codegen/includes/parserImpls.ftl           |  9 +++++++++
 .../parserextensiontesting/ExtensionSqlParserTest.java   |  9 +++++++++
 4 files changed, 24 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite/blob/5a0403cf/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 0aef85b..a4f7119 100644
--- a/core/src/main/codegen/templates/Parser.jj
+++ b/core/src/main/codegen/templates/Parser.jj
@@ -890,6 +890,11 @@ SqlNode SqlStmt() :
 }
 {
     (
+<#-- Add methods to parse additional statements here -->
+<#list parser.statementParserMethods as method>
+        stmt = ${method}
+    |
+</#list>
         stmt = SqlSetOption(Span.of(), null)
     |
         stmt = SqlAlter()
@@ -913,12 +918,6 @@ SqlNode SqlStmt() :
         stmt = SqlMerge()
     |
         stmt = SqlProcedureCall()
-
-<#-- Add methods to parse additional statements here -->
-<#list parser.statementParserMethods as method>
-    |
-        stmt = ${method}
-</#list>
     )
     {
         return stmt;

http://git-wip-us.apache.org/repos/asf/calcite/blob/5a0403cf/core/src/test/codegen/config.fmpp
----------------------------------------------------------------------
diff --git a/core/src/test/codegen/config.fmpp b/core/src/test/codegen/config.fmpp
index bd168b1..2f747e2 100644
--- a/core/src/test/codegen/config.fmpp
+++ b/core/src/test/codegen/config.fmpp
@@ -38,6 +38,7 @@ data: {
 
       # List of methods for parsing custom SQL statements.
       statementParserMethods: [
+        "SqlDescribeSpacePower()"
       ]
 
       # List of methods for parsing custom literals.

http://git-wip-us.apache.org/repos/asf/calcite/blob/5a0403cf/core/src/test/codegen/includes/parserImpls.ftl
----------------------------------------------------------------------
diff --git a/core/src/test/codegen/includes/parserImpls.ftl b/core/src/test/codegen/includes/parserImpls.ftl
index cea63a4..754f876 100644
--- a/core/src/test/codegen/includes/parserImpls.ftl
+++ b/core/src/test/codegen/includes/parserImpls.ftl
@@ -47,4 +47,13 @@ SqlCreate SqlCreateTable(Span s, boolean replace) :
     }
 }
 
+SqlNode SqlDescribeSpacePower() :
+{
+}
+{
+    <DESCRIBE> <SPACE> <POWER> {
+        return null;
+    }
+}
+
 // End parserImpls.ftl

http://git-wip-us.apache.org/repos/asf/calcite/blob/5a0403cf/core/src/test/java/org/apache/calcite/sql/parser/parserextensiontesting/ExtensionSqlParserTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/sql/parser/parserextensiontesting/ExtensionSqlParserTest.java
b/core/src/test/java/org/apache/calcite/sql/parser/parserextensiontesting/ExtensionSqlParserTest.java
index 1b58a4c..825d072 100644
--- a/core/src/test/java/org/apache/calcite/sql/parser/parserextensiontesting/ExtensionSqlParserTest.java
+++ b/core/src/test/java/org/apache/calcite/sql/parser/parserextensiontesting/ExtensionSqlParserTest.java
@@ -16,10 +16,12 @@
  */
 package org.apache.calcite.sql.parser.parserextensiontesting;
 
+import org.apache.calcite.sql.SqlNode;
 import org.apache.calcite.sql.parser.SqlParseException;
 import org.apache.calcite.sql.parser.SqlParserImplFactory;
 import org.apache.calcite.sql.parser.SqlParserTest;
 
+import org.hamcrest.core.IsNull;
 import org.junit.Test;
 
 /**
@@ -49,6 +51,13 @@ public class ExtensionSqlParserTest extends SqlParserTest {
     sql("CREATE TABLE foo.baz(i INTEGER, j VARCHAR(10) NOT NULL)")
         .ok("CREATE TABLE `FOO`.`BAZ` (`I` INTEGER, `J` VARCHAR(10) NOT NULL)");
   }
+
+  @Test public void testExtendedSqlStmt() {
+    sql("DESCRIBE SPACE POWER")
+        .node(new IsNull<SqlNode>());
+    sql("DESCRIBE SEA ^POWER^")
+        .fails("(?s)Encountered \"POWER\" at line 1, column 14..*");
+  }
 }
 
 // End ExtensionSqlParserTest.java


Mime
View raw message