You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2018/12/20 09:31:59 UTC

[GitHub] ambition119 closed pull request #7339: [FLINK-11206] sql statement parser enhancement

ambition119 closed pull request #7339: [FLINK-11206] sql statement parser enhancement
URL: https://github.com/apache/flink/pull/7339
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/flink-libraries/flink-table/pom.xml b/flink-libraries/flink-table/pom.xml
index 1fe5a0964cd..c678871f5d0 100644
--- a/flink-libraries/flink-table/pom.xml
+++ b/flink-libraries/flink-table/pom.xml
@@ -94,7 +94,7 @@ under the License.
 		<!-- Used for translation of table programs -->
 		<dependency>
 			<groupId>org.apache.calcite</groupId>
-			<artifactId>calcite-core</artifactId>
+			<artifactId>calcite-server</artifactId>
 			<!-- When updating the Calcite version, make sure to update the dependency exclusions -->
 			<version>1.17.0</version>
 			<exclusions>
diff --git a/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/calcite/FlinkPlannerImpl.scala b/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/calcite/FlinkPlannerImpl.scala
index 400279d8c72..076ffe7a4e9 100644
--- a/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/calcite/FlinkPlannerImpl.scala
+++ b/flink-libraries/flink-table/src/main/scala/org/apache/flink/table/calcite/FlinkPlannerImpl.scala
@@ -18,6 +18,7 @@
 
 package org.apache.flink.table.calcite
 
+import java.io.{ByteArrayInputStream, InputStream}
 import java.util
 
 import com.google.common.collect.ImmutableList
@@ -30,6 +31,7 @@ import org.apache.calcite.rel.`type`.RelDataType
 import org.apache.calcite.rex.RexBuilder
 import org.apache.calcite.schema.SchemaPlus
 import org.apache.calcite.sql.advise.{SqlAdvisor, SqlAdvisorValidator}
+import org.apache.calcite.sql.parser.ddl.SqlDdlParserImpl
 import org.apache.calcite.sql.parser.{SqlParser, SqlParseException => CSqlParseException}
 import org.apache.calcite.sql.validate.SqlValidator
 import org.apache.calcite.sql.{SqlNode, SqlOperatorTable}
@@ -83,11 +85,22 @@ class FlinkPlannerImpl(
     hints.toArray
   }
 
+  def getParser(sql: String): SqlDdlParserImpl = {
+    val inputStream: InputStream = new ByteArrayInputStream(sql.getBytes)
+    val parser: SqlDdlParserImpl = new SqlDdlParserImpl(inputStream)
+    parser.setConformance(parserConfig.conformance)
+    parser.setIdentifierMaxLength(parserConfig.identifierMaxLength)
+    parser.setQuotedCasing(parserConfig.quotedCasing)
+    parser.setUnquotedCasing(parserConfig.unquotedCasing)
+    parser.switchTo("BTID")
+    parser
+  }
+
   def parse(sql: String): SqlNode = {
     try {
       ready()
-      val parser: SqlParser = SqlParser.create(sql, parserConfig)
-      val sqlNode: SqlNode = parser.parseStmt
+      val parser: SqlDdlParserImpl = getParser(sql)
+      val sqlNode: SqlNode = parser.parseSqlStmtEof
       sqlNode
     } catch {
       case e: CSqlParseException =>
@@ -147,10 +160,10 @@ class FlinkPlannerImpl(
         schemaPath: util.List[String],
         viewPath: util.List[String]): RelRoot = {
 
-      val parser: SqlParser = SqlParser.create(queryString, parserConfig)
+      val parser: SqlDdlParserImpl = getParser(queryString)
       var sqlNode: SqlNode = null
       try {
-        sqlNode = parser.parseQuery
+        sqlNode = parser.parseSqlStmtEof
       }
       catch {
         case e: CSqlParseException =>


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services