You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@kyuubi.apache.org by GitBox <gi...@apache.org> on 2022/12/29 07:22:09 UTC

[GitHub] [kyuubi] Yikf opened a new pull request, #4040: Abstract and rename parser module related classes

Yikf opened a new pull request, #4040:
URL: https://github.com/apache/kyuubi/pull/4040

   <!--
   Thanks for sending a pull request!
   
   Here are some tips for you:
     1. If this is your first time, please read our contributor guidelines: https://kyuubi.readthedocs.io/en/latest/community/CONTRIBUTING.html
     2. If the PR is related to an issue in https://github.com/apache/incubator-kyuubi/issues, add '[KYUUBI #XXXX]' in your PR title, e.g., '[KYUUBI #XXXX] Your PR title ...'.
     3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][KYUUBI #XXXX] Your PR title ...'.
   -->
   
   ### _Why are the changes needed?_
   <!--
   Please clarify why the changes are needed. For instance,
     1. If you add a feature, you can talk about the use case of it.
     2. If you fix a bug, you can clarify why it is a bug.
   -->
   This pr aims to abstract and rename parser module related classes.
   
   ### _How was this patch tested?_
   - [ ] Add some test cases that check the changes thoroughly including negative and positive cases if possible
   
   - [ ] Add screenshots for manual tests if appropriate
   
   - [x] [Run test](https://kyuubi.apache.org/docs/latest/develop_tools/testing.html#running-tests) locally before make a pull request
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org


[GitHub] [kyuubi] ulysses-you commented on a diff in pull request #4040: Abstract and rename parser module related classes

Posted by GitBox <gi...@apache.org>.
ulysses-you commented on code in PR #4040:
URL: https://github.com/apache/kyuubi/pull/4040#discussion_r1058787643


##########
kyuubi-server/src/main/scala/org/apache/kyuubi/sql/parser/KyuubiParserBase.scala:
##########
@@ -20,49 +20,34 @@ package org.apache.kyuubi.sql.parser
 import java.lang.{Long => JLong}
 import java.nio.CharBuffer
 
-import org.antlr.v4.runtime._
-import org.antlr.v4.runtime.atn.PredictionMode
-import org.antlr.v4.runtime.misc.{Interval, ParseCancellationException}
+import org.antlr.v4.runtime.{CharStream, CodePointCharStream, IntStream}
+import org.antlr.v4.runtime.misc.Interval
+import org.antlr.v4.runtime.tree.{AbstractParseTreeVisitor, ParseTree}
 
-import org.apache.kyuubi.sql.{KyuubiSqlBaseLexer, KyuubiSqlBaseParser, KyuubiSqlBaseParserBaseListener}
+import org.apache.kyuubi.sql.{KyuubiSqlBaseParser, KyuubiSqlBaseParserBaseListener, KyuubiTrinoFeBaseParser}
 import org.apache.kyuubi.sql.plan.KyuubiTreeNode
 
-class KyuubiParser {
+abstract class KyuubiParserBase[P] {
 
-  lazy val astBuilder = new KyuubiAstBuilder
+  val astBuilder: AbstractParseTreeVisitor[AnyRef]
+
+  protected def parse[T](command: String)(toResult: P => T): T
 
   def parsePlan(sqlText: String): KyuubiTreeNode = parse(sqlText) { parser =>
-    astBuilder.visit(parser.singleStatement) match {
+    astBuilder.visit(parseTree(parser)) match {
       case plan: KyuubiTreeNode => plan
     }
   }
 
-  protected def parse[T](command: String)(toResult: KyuubiSqlBaseParser => T): T = {
-    val lexer = new KyuubiSqlBaseLexer(
-      new UpperCaseCharStream(CharStreams.fromString(command)))
-    lexer.removeErrorListeners()
-
-    val tokenStream = new CommonTokenStream(lexer)
-    val parser = new KyuubiSqlBaseParser(tokenStream)
-    parser.addParseListener(PostProcessor)
-    parser.removeErrorListeners()
-
-    try {
-      // first, try parsing with potentially faster SLL mode
-      parser.getInterpreter.setPredictionMode(PredictionMode.SLL)
-      toResult(parser)
-    } catch {
-      case _: ParseCancellationException =>
-        // if we fail, parse with LL mode
-        tokenStream.seek(0) // rewind input stream
-        parser.reset()
-
-        // Try Again.
-        parser.getInterpreter.setPredictionMode(PredictionMode.LL)
-        toResult(parser)
+  private def parseTree(parser: P): ParseTree = {
+    parser match {
+      case _: KyuubiSqlBaseParser => parser.asInstanceOf[KyuubiSqlBaseParser].singleStatement()
+      case _: KyuubiTrinoFeBaseParser =>
+        parser.asInstanceOf[KyuubiTrinoFeBaseParser].singleStatement()

Review Comment:
   we can define a parse method then we do not need to match implementation in abstract class



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org


[GitHub] [kyuubi] Yikf commented on a diff in pull request #4040: Abstract and rename parser module related classes

Posted by GitBox <gi...@apache.org>.
Yikf commented on code in PR #4040:
URL: https://github.com/apache/kyuubi/pull/4040#discussion_r1058787744


##########
kyuubi-server/src/main/scala/org/apache/kyuubi/sql/plan/trino/TrinoFeOperations.scala:
##########
@@ -15,14 +15,14 @@
  * limitations under the License.
  */
 
-package org.apache.kyuubi.sql.trino
+package org.apache.kyuubi.sql.plan.trino
 
 import org.apache.kyuubi.sql.plan.KyuubiTreeNode
 
 /////////////////////////////////////////////////////////////////////////////////////////
 // This file contains all Trino JDBC operation nodes which are parsed from statement
 /////////////////////////////////////////////////////////////////////////////////////////
 
-case class TrinoGetSchemas(catalogName: String, schemaPattern: String) extends KyuubiTreeNode {
+case class GetSchemas(catalogName: String, schemaPattern: String) extends KyuubiTreeNode {

Review Comment:
   Kyuubi supports trino **engine** and trino **fe**, Trinoxxx seems to be ambiguous, or rename to TrinoFexxx?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org


[GitHub] [kyuubi] ulysses-you commented on pull request #4040: Abstract and rename parser module related classes

Posted by GitBox <gi...@apache.org>.
ulysses-you commented on PR #4040:
URL: https://github.com/apache/kyuubi/pull/4040#issuecomment-1367671084

   thanks, merging to master


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org


[GitHub] [kyuubi] ulysses-you closed pull request #4040: Abstract and rename parser module related classes

Posted by GitBox <gi...@apache.org>.
ulysses-you closed pull request #4040: Abstract and rename parser module related classes
URL: https://github.com/apache/kyuubi/pull/4040


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org


[GitHub] [kyuubi] Yikf commented on pull request #4040: Abstract and rename parser module related classes

Posted by GitBox <gi...@apache.org>.
Yikf commented on PR #4040:
URL: https://github.com/apache/kyuubi/pull/4040#issuecomment-1367122912

   cc @ulysses-you , Please take a look if you find a moment, i redefine the pacakge location:
   ![image](https://user-images.githubusercontent.com/51110188/209917896-736b5b4f-e43d-4fbe-9ed5-a3f6e74190a9.png)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org


[GitHub] [kyuubi] ulysses-you commented on a diff in pull request #4040: Abstract and rename parser module related classes

Posted by GitBox <gi...@apache.org>.
ulysses-you commented on code in PR #4040:
URL: https://github.com/apache/kyuubi/pull/4040#discussion_r1058785880


##########
kyuubi-server/src/main/scala/org/apache/kyuubi/sql/plan/trino/TrinoFeOperations.scala:
##########
@@ -15,14 +15,14 @@
  * limitations under the License.
  */
 
-package org.apache.kyuubi.sql.trino
+package org.apache.kyuubi.sql.plan.trino
 
 import org.apache.kyuubi.sql.plan.KyuubiTreeNode
 
 /////////////////////////////////////////////////////////////////////////////////////////
 // This file contains all Trino JDBC operation nodes which are parsed from statement
 /////////////////////////////////////////////////////////////////////////////////////////
 
-case class TrinoGetSchemas(catalogName: String, schemaPattern: String) extends KyuubiTreeNode {
+case class GetSchemas(catalogName: String, schemaPattern: String) extends KyuubiTreeNode {

Review Comment:
   does this change necessary ? Seems Trinoxxx is more cleaer to me



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org