You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kyuubi.apache.org by ul...@apache.org on 2023/01/03 12:31:30 UTC
[kyuubi] branch master updated: [KYUUBI #4065] Support GetTypeInfo for Trino Fe
This is an automated email from the ASF dual-hosted git repository.
ulyssesyou pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kyuubi.git
The following commit(s) were added to refs/heads/master by this push:
new 9342a2928 [KYUUBI #4065] Support GetTypeInfo for Trino Fe
9342a2928 is described below
commit 9342a29284234e21c73f96024a740c6e93e7cb33
Author: Yikf <yi...@gmail.com>
AuthorDate: Tue Jan 3 20:31:15 2023 +0800
[KYUUBI #4065] Support GetTypeInfo for Trino Fe
### _Why are the changes needed?_
Close https://github.com/apache/kyuubi/issues/4065, This pr aims to support `GetTypeInfo` for Trino Fe
### _How was this patch tested?_
- [x] 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
Closes #4066 from Yikf/master.
Closes #4065
bafe4ba4 [Yikf] Support GetTypeInfo for Trino Fe
Authored-by: Yikf <yi...@gmail.com>
Signed-off-by: ulysses-you <ul...@apache.org>
---
.../org/apache/kyuubi/sql/KyuubiSqlBaseLexer.g4 | 19 +++++++++++++++++++
.../org/apache/kyuubi/sql/KyuubiTrinoFeBaseParser.g4 | 5 +++++
.../trino/api/KyuubiTrinoOperationTranslator.scala | 4 +++-
.../sql/parser/trino/KyuubiTrinoFeAstBuilder.scala | 6 +++++-
.../kyuubi/sql/plan/trino/TrinoFeOperations.scala | 4 ++++
.../parser/trino/KyuubiTrinoFeParserSuite.scala | 16 +++++++++++++++-
6 files changed, 51 insertions(+), 3 deletions(-)
diff --git a/kyuubi-server/src/main/antlr4/org/apache/kyuubi/sql/KyuubiSqlBaseLexer.g4 b/kyuubi-server/src/main/antlr4/org/apache/kyuubi/sql/KyuubiSqlBaseLexer.g4
index 494c2e847..cdf0ce5e7 100644
--- a/kyuubi-server/src/main/antlr4/org/apache/kyuubi/sql/KyuubiSqlBaseLexer.g4
+++ b/kyuubi-server/src/main/antlr4/org/apache/kyuubi/sql/KyuubiSqlBaseLexer.g4
@@ -69,16 +69,35 @@ LIKE: 'LIKE';
KYUUBI: 'KYUUBI';
KYUUBIADMIN: 'KYUUBIADMIN';
+AUTO_INCREMENT: 'AUTO_INCREMENT';
+CASE_SENSITIVE: 'CASE_SENSITIVE';
+CREATE_PARAMS: 'CREATE_PARAMS';
+DATA_TYPE: 'DATA_TYPE';
+FIXED_PREC_SCALE: 'FIXED_PREC_SCALE';
+LITERAL_PREFIX: 'LITERAL_PREFIX';
+LITERAL_SUFFIX: 'LITERAL_SUFFIX';
+LOCAL_TYPE_NAME: 'LOCAL_TYPE_NAME';
+MAXIMUM_SCALE: 'MAXIMUM_SCALE';
+MINIMUM_SCALE: 'MINIMUM_SCALE';
+NULLABLE: 'NULLABLE';
+NUM_PREC_RADIX: 'NUM_PREC_RADIX';
ORDER: 'ORDER';
+PRECISION: 'PRECISION';
+SEARCHABLE: 'SEARCHABLE';
SELECT: 'SELECT';
SESSION: 'SESSION';
+SQL_DATA_TYPE: 'SQL_DATA_TYPE';
+SQL_DATETIME_SUB: 'SQL_DATETIME_SUB';
SYSTEM_JDBC_CATALOGS: 'SYSTEM.JDBC.CATALOGS';
SYSTEM_JDBC_SCHEMAS: 'SYSTEM.JDBC.SCHEMAS';
SYSTEM_JDBC_TABLE_TYPES: 'SYSTEM.JDBC.TABLE_TYPES';
+SYSTEM_JDBC_TYPES: 'SYSTEM.JDBC.TYPES';
+UNSIGNED_ATTRIBUTE: 'UNSIGNED_ATTRIBUTE';
TABLE_CAT: 'TABLE_CAT';
TABLE_CATALOG: 'TABLE_CATALOG';
TABLE_SCHEM: 'TABLE_SCHEM';
TABLE_TYPE: 'TABLE_TYPE';
+TYPE_NAME: 'TYPE_NAME';
WHERE: 'WHERE';
diff --git a/kyuubi-server/src/main/antlr4/org/apache/kyuubi/sql/KyuubiTrinoFeBaseParser.g4 b/kyuubi-server/src/main/antlr4/org/apache/kyuubi/sql/KyuubiTrinoFeBaseParser.g4
index 87d1200b9..7bf4c6656 100644
--- a/kyuubi-server/src/main/antlr4/org/apache/kyuubi/sql/KyuubiTrinoFeBaseParser.g4
+++ b/kyuubi-server/src/main/antlr4/org/apache/kyuubi/sql/KyuubiTrinoFeBaseParser.g4
@@ -29,5 +29,10 @@ statement
ORDER BY TABLE_CATALOG COMMA TABLE_SCHEM #getSchemas
| SELECT TABLE_CAT FROM SYSTEM_JDBC_CATALOGS ORDER BY TABLE_CAT #getCatalogs
| SELECT TABLE_TYPE FROM SYSTEM_JDBC_TABLE_TYPES ORDER BY TABLE_TYPE #getTableTypes
+ | SELECT TYPE_NAME COMMA DATA_TYPE COMMA PRECISION COMMA LITERAL_PREFIX COMMA
+ LITERAL_SUFFIX COMMA CREATE_PARAMS COMMA NULLABLE COMMA CASE_SENSITIVE COMMA
+ SEARCHABLE COMMA UNSIGNED_ATTRIBUTE COMMA FIXED_PREC_SCALE COMMA AUTO_INCREMENT
+ COMMA LOCAL_TYPE_NAME COMMA MINIMUM_SCALE COMMA MAXIMUM_SCALE COMMA SQL_DATA_TYPE
+ COMMA SQL_DATETIME_SUB COMMA NUM_PREC_RADIX FROM SYSTEM_JDBC_TYPES ORDER BY DATA_TYPE #getTypeInfo
| .*? #passThrough
;
diff --git a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/trino/api/KyuubiTrinoOperationTranslator.scala b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/trino/api/KyuubiTrinoOperationTranslator.scala
index ee75b400f..15608d6c2 100644
--- a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/trino/api/KyuubiTrinoOperationTranslator.scala
+++ b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/trino/api/KyuubiTrinoOperationTranslator.scala
@@ -23,7 +23,7 @@ import org.apache.kyuubi.operation.OperationHandle
import org.apache.kyuubi.service.BackendService
import org.apache.kyuubi.sql.parser.trino.KyuubiTrinoFeParser
import org.apache.kyuubi.sql.plan.PassThroughNode
-import org.apache.kyuubi.sql.plan.trino.{GetCatalogs, GetSchemas, GetTableTypes}
+import org.apache.kyuubi.sql.plan.trino.{GetCatalogs, GetSchemas, GetTableTypes, GetTypeInfo}
class KyuubiTrinoOperationTranslator(backendService: BackendService) {
lazy val parser = new KyuubiTrinoFeParser()
@@ -48,6 +48,8 @@ class KyuubiTrinoOperationTranslator(backendService: BackendService) {
backendService.getCatalogs(sessionHandle)
case GetTableTypes() =>
backendService.getTableTypes(sessionHandle)
+ case GetTypeInfo() =>
+ backendService.getTypeInfo(sessionHandle)
case PassThroughNode() =>
backendService.executeStatement(sessionHandle, statement, configs, runAsync, queryTimeout)
}
diff --git a/kyuubi-server/src/main/scala/org/apache/kyuubi/sql/parser/trino/KyuubiTrinoFeAstBuilder.scala b/kyuubi-server/src/main/scala/org/apache/kyuubi/sql/parser/trino/KyuubiTrinoFeAstBuilder.scala
index 3d83e6f96..86df35bc5 100644
--- a/kyuubi-server/src/main/scala/org/apache/kyuubi/sql/parser/trino/KyuubiTrinoFeAstBuilder.scala
+++ b/kyuubi-server/src/main/scala/org/apache/kyuubi/sql/parser/trino/KyuubiTrinoFeAstBuilder.scala
@@ -21,7 +21,7 @@ import org.apache.kyuubi.sql.KyuubiTrinoFeBaseParser._
import org.apache.kyuubi.sql.KyuubiTrinoFeBaseParserBaseVisitor
import org.apache.kyuubi.sql.parser.KyuubiParser
import org.apache.kyuubi.sql.plan.{KyuubiTreeNode, PassThroughNode}
-import org.apache.kyuubi.sql.plan.trino.{GetCatalogs, GetSchemas, GetTableTypes}
+import org.apache.kyuubi.sql.plan.trino.{GetCatalogs, GetSchemas, GetTableTypes, GetTypeInfo}
class KyuubiTrinoFeAstBuilder extends KyuubiTrinoFeBaseParserBaseVisitor[AnyRef] {
@@ -56,4 +56,8 @@ class KyuubiTrinoFeAstBuilder extends KyuubiTrinoFeBaseParserBaseVisitor[AnyRef]
override def visitGetTableTypes(ctx: GetTableTypesContext): KyuubiTreeNode = {
GetTableTypes()
}
+
+ override def visitGetTypeInfo(ctx: GetTypeInfoContext): KyuubiTreeNode = {
+ GetTypeInfo()
+ }
}
diff --git a/kyuubi-server/src/main/scala/org/apache/kyuubi/sql/plan/trino/TrinoFeOperations.scala b/kyuubi-server/src/main/scala/org/apache/kyuubi/sql/plan/trino/TrinoFeOperations.scala
index afe9182f1..a1841bcaa 100644
--- a/kyuubi-server/src/main/scala/org/apache/kyuubi/sql/plan/trino/TrinoFeOperations.scala
+++ b/kyuubi-server/src/main/scala/org/apache/kyuubi/sql/plan/trino/TrinoFeOperations.scala
@@ -34,3 +34,7 @@ case class GetCatalogs() extends KyuubiTreeNode {
case class GetTableTypes() extends KyuubiTreeNode {
override def name(): String = "Get Table Types"
}
+
+case class GetTypeInfo() extends KyuubiTreeNode {
+ override def name(): String = "Get Type Info"
+}
diff --git a/kyuubi-server/src/test/scala/org/apache/kyuubi/parser/trino/KyuubiTrinoFeParserSuite.scala b/kyuubi-server/src/test/scala/org/apache/kyuubi/parser/trino/KyuubiTrinoFeParserSuite.scala
index a1aa36d51..333f5a0d8 100644
--- a/kyuubi-server/src/test/scala/org/apache/kyuubi/parser/trino/KyuubiTrinoFeParserSuite.scala
+++ b/kyuubi-server/src/test/scala/org/apache/kyuubi/parser/trino/KyuubiTrinoFeParserSuite.scala
@@ -20,7 +20,7 @@ package org.apache.kyuubi.parser.trino
import org.apache.kyuubi.KyuubiFunSuite
import org.apache.kyuubi.sql.parser.trino.KyuubiTrinoFeParser
import org.apache.kyuubi.sql.plan.{KyuubiTreeNode, PassThroughNode}
-import org.apache.kyuubi.sql.plan.trino.{GetCatalogs, GetSchemas, GetTableTypes}
+import org.apache.kyuubi.sql.plan.trino.{GetCatalogs, GetSchemas, GetTableTypes, GetTypeInfo}
class KyuubiTrinoFeParserSuite extends KyuubiFunSuite {
val parser = new KyuubiTrinoFeParser()
@@ -94,4 +94,18 @@ class KyuubiTrinoFeParserSuite extends KyuubiFunSuite {
assert(kyuubiTreeNode.isInstanceOf[GetTableTypes])
}
+
+ test("Support GetTypeInfo for Trino Fe") {
+ val kyuubiTreeNode = parse(
+ """
+ |SELECT TYPE_NAME, DATA_TYPE, PRECISION, LITERAL_PREFIX, LITERAL_SUFFIX,
+ |CREATE_PARAMS, NULLABLE, CASE_SENSITIVE, SEARCHABLE, UNSIGNED_ATTRIBUTE,
+ |FIXED_PREC_SCALE, AUTO_INCREMENT, LOCAL_TYPE_NAME, MINIMUM_SCALE, MAXIMUM_SCALE,
+ |SQL_DATA_TYPE, SQL_DATETIME_SUB, NUM_PREC_RADIX
+ |FROM system.jdbc.types
+ |ORDER BY DATA_TYPE
+ |""".stripMargin)
+
+ assert(kyuubiTreeNode.isInstanceOf[GetTypeInfo])
+ }
}