You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kyuubi.apache.org by ch...@apache.org on 2022/02/16 05:27:51 UTC
[incubator-kyuubi] branch master updated: [KYUUBI #1911] Add GetTypeInfo for trino engine
This is an automated email from the ASF dual-hosted git repository.
chengpan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-kyuubi.git
The following commit(s) were added to refs/heads/master by this push:
new fd7a729 [KYUUBI #1911] Add GetTypeInfo for trino engine
fd7a729 is described below
commit fd7a72956b6dcd47b6a9a450165d48f76237aacd
Author: SteNicholas <pr...@163.com>
AuthorDate: Wed Feb 16 13:27:41 2022 +0800
[KYUUBI #1911] Add GetTypeInfo for trino engine
<!--
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/contributions.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.
-->
Add GetTypeInfo for trino engine.
### _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
Closes #1912 from SteNicholas/KYUUBI-1911.
Closes #1911
33a4dff8 [SteNicholas] [KYUUBI #1911] Add GetTypeInfo for trino engine
Authored-by: SteNicholas <pr...@163.com>
Signed-off-by: Cheng Pan <ch...@apache.org>
---
.../engine/trino/operation/GetTypeInfo.scala | 44 ++++++++++++++++
.../trino/operation/TrinoOperationManager.scala | 5 +-
.../trino/operation/TrinoOperationSuite.scala | 60 ++++++++++++++++++++++
3 files changed, 108 insertions(+), 1 deletion(-)
diff --git a/externals/kyuubi-trino-engine/src/main/scala/org/apache/kyuubi/engine/trino/operation/GetTypeInfo.scala b/externals/kyuubi-trino-engine/src/main/scala/org/apache/kyuubi/engine/trino/operation/GetTypeInfo.scala
new file mode 100644
index 0000000..ae644a2
--- /dev/null
+++ b/externals/kyuubi-trino-engine/src/main/scala/org/apache/kyuubi/engine/trino/operation/GetTypeInfo.scala
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.kyuubi.engine.trino.operation
+
+import org.apache.kyuubi.engine.trino.TrinoStatement
+import org.apache.kyuubi.operation.{IterableFetchIterator, OperationType}
+import org.apache.kyuubi.session.Session
+
+class GetTypeInfo(session: Session)
+ extends TrinoOperation(OperationType.GET_TYPE_INFO, session) {
+
+ override protected def runInternal(): Unit = {
+ try {
+ val trinoStatement = TrinoStatement(
+ trinoContext,
+ session.sessionManager.getConf,
+ """
+ |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
+ |""".stripMargin)
+ schema = trinoStatement.getColumns
+ val resultSet = trinoStatement.execute()
+ iter = new IterableFetchIterator(resultSet)
+ } catch onError()
+ }
+}
diff --git a/externals/kyuubi-trino-engine/src/main/scala/org/apache/kyuubi/engine/trino/operation/TrinoOperationManager.scala b/externals/kyuubi-trino-engine/src/main/scala/org/apache/kyuubi/engine/trino/operation/TrinoOperationManager.scala
index dc06e71..a6d0c69 100644
--- a/externals/kyuubi-trino-engine/src/main/scala/org/apache/kyuubi/engine/trino/operation/TrinoOperationManager.scala
+++ b/externals/kyuubi-trino-engine/src/main/scala/org/apache/kyuubi/engine/trino/operation/TrinoOperationManager.scala
@@ -38,7 +38,10 @@ class TrinoOperationManager extends OperationManager("TrinoOperationManager") {
addOperation(operation)
}
- override def newGetTypeInfoOperation(session: Session): Operation = null
+ override def newGetTypeInfoOperation(session: Session): Operation = {
+ val op = new GetTypeInfo(session)
+ addOperation(op)
+ }
override def newGetCatalogsOperation(session: Session): Operation = {
val op = new GetCatalogs(session)
diff --git a/externals/kyuubi-trino-engine/src/test/scala/org/apache/kyuubi/engine/trino/operation/TrinoOperationSuite.scala b/externals/kyuubi-trino-engine/src/test/scala/org/apache/kyuubi/engine/trino/operation/TrinoOperationSuite.scala
index 32bd5a5..59b7c93 100644
--- a/externals/kyuubi-trino-engine/src/test/scala/org/apache/kyuubi/engine/trino/operation/TrinoOperationSuite.scala
+++ b/externals/kyuubi-trino-engine/src/test/scala/org/apache/kyuubi/engine/trino/operation/TrinoOperationSuite.scala
@@ -19,7 +19,9 @@ package org.apache.kyuubi.engine.trino.operation
import scala.collection.JavaConverters._
import scala.collection.mutable.ArrayBuffer
+import scala.collection.mutable.Set
+import io.trino.client.ClientStandardTypes._
import org.apache.hive.service.rpc.thrift.TCancelOperationReq
import org.apache.hive.service.rpc.thrift.TCloseOperationReq
import org.apache.hive.service.rpc.thrift.TCloseSessionReq
@@ -45,6 +47,64 @@ class TrinoOperationSuite extends WithTrinoEngine with HiveJDBCTestHelper {
override protected def jdbcUrl: String = getJdbcUrl
+ test("trino - get type info") {
+ withJdbcStatement() { statement =>
+ val typeInfo = statement.getConnection.getMetaData.getTypeInfo
+ val types: Set[String] = Set(
+ BIGINT,
+ INTEGER,
+ SMALLINT,
+ TINYINT,
+ BOOLEAN,
+ DATE,
+ DECIMAL,
+ REAL,
+ DOUBLE,
+ HYPER_LOG_LOG,
+ QDIGEST,
+ P4_HYPER_LOG_LOG,
+ INTERVAL_DAY_TO_SECOND,
+ INTERVAL_YEAR_TO_MONTH,
+ TIMESTAMP,
+ TIMESTAMP_WITH_TIME_ZONE,
+ TIME,
+ TIME_WITH_TIME_ZONE,
+ VARBINARY,
+ VARCHAR,
+ CHAR,
+ ROW,
+ ARRAY,
+ MAP,
+ JSON,
+ IPADDRESS,
+ UUID,
+ GEOMETRY,
+ SPHERICAL_GEOGRAPHY,
+ BING_TILE,
+ "color",
+ "KdbTree",
+ "CodePoints",
+ "JsonPath",
+ "Regressor",
+ "JoniRegExp",
+ "unknown",
+ "ObjectId",
+ "SetDigest",
+ "Re2JRegExp",
+ "Model",
+ "tdigest",
+ "LikePattern",
+ "function",
+ "Classifier")
+ val typeInfos: Set[String] = Set()
+ while (typeInfo.next()) {
+ assert(types.contains(typeInfo.getString(TYPE_NAME)))
+ typeInfos += typeInfo.getString(TYPE_NAME)
+ }
+ assert(types.size === typeInfos.size)
+ }
+ }
+
test("trino - get catalogs") {
withJdbcStatement() { statement =>
val meta = statement.getConnection.getMetaData