Skip to content

Commit fd7a729

Browse files
SteNicholaspan3793
authored andcommitted
[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 33a4dff [SteNicholas] [KYUUBI #1911] Add GetTypeInfo for trino engine Authored-by: SteNicholas <programgeek@163.com> Signed-off-by: Cheng Pan <chengpan@apache.org>
1 parent 24e265d commit fd7a729

File tree

3 files changed

+108
-1
lines changed

3 files changed

+108
-1
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.kyuubi.engine.trino.operation
19+
20+
import org.apache.kyuubi.engine.trino.TrinoStatement
21+
import org.apache.kyuubi.operation.{IterableFetchIterator, OperationType}
22+
import org.apache.kyuubi.session.Session
23+
24+
class GetTypeInfo(session: Session)
25+
extends TrinoOperation(OperationType.GET_TYPE_INFO, session) {
26+
27+
override protected def runInternal(): Unit = {
28+
try {
29+
val trinoStatement = TrinoStatement(
30+
trinoContext,
31+
session.sessionManager.getConf,
32+
"""
33+
|SELECT TYPE_NAME, DATA_TYPE, PRECISION, LITERAL_PREFIX, LITERAL_SUFFIX,
34+
|CREATE_PARAMS, NULLABLE, CASE_SENSITIVE, SEARCHABLE, UNSIGNED_ATTRIBUTE,
35+
|FIXED_PREC_SCALE, AUTO_INCREMENT, LOCAL_TYPE_NAME, MINIMUM_SCALE,
36+
|MAXIMUM_SCALE, SQL_DATA_TYPE, SQL_DATETIME_SUB, NUM_PREC_RADIX
37+
|FROM system.jdbc.types
38+
|""".stripMargin)
39+
schema = trinoStatement.getColumns
40+
val resultSet = trinoStatement.execute()
41+
iter = new IterableFetchIterator(resultSet)
42+
} catch onError()
43+
}
44+
}

externals/kyuubi-trino-engine/src/main/scala/org/apache/kyuubi/engine/trino/operation/TrinoOperationManager.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ class TrinoOperationManager extends OperationManager("TrinoOperationManager") {
3838
addOperation(operation)
3939
}
4040

41-
override def newGetTypeInfoOperation(session: Session): Operation = null
41+
override def newGetTypeInfoOperation(session: Session): Operation = {
42+
val op = new GetTypeInfo(session)
43+
addOperation(op)
44+
}
4245

4346
override def newGetCatalogsOperation(session: Session): Operation = {
4447
val op = new GetCatalogs(session)

externals/kyuubi-trino-engine/src/test/scala/org/apache/kyuubi/engine/trino/operation/TrinoOperationSuite.scala

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ package org.apache.kyuubi.engine.trino.operation
1919

2020
import scala.collection.JavaConverters._
2121
import scala.collection.mutable.ArrayBuffer
22+
import scala.collection.mutable.Set
2223

24+
import io.trino.client.ClientStandardTypes._
2325
import org.apache.hive.service.rpc.thrift.TCancelOperationReq
2426
import org.apache.hive.service.rpc.thrift.TCloseOperationReq
2527
import org.apache.hive.service.rpc.thrift.TCloseSessionReq
@@ -45,6 +47,64 @@ class TrinoOperationSuite extends WithTrinoEngine with HiveJDBCTestHelper {
4547

4648
override protected def jdbcUrl: String = getJdbcUrl
4749

50+
test("trino - get type info") {
51+
withJdbcStatement() { statement =>
52+
val typeInfo = statement.getConnection.getMetaData.getTypeInfo
53+
val types: Set[String] = Set(
54+
BIGINT,
55+
INTEGER,
56+
SMALLINT,
57+
TINYINT,
58+
BOOLEAN,
59+
DATE,
60+
DECIMAL,
61+
REAL,
62+
DOUBLE,
63+
HYPER_LOG_LOG,
64+
QDIGEST,
65+
P4_HYPER_LOG_LOG,
66+
INTERVAL_DAY_TO_SECOND,
67+
INTERVAL_YEAR_TO_MONTH,
68+
TIMESTAMP,
69+
TIMESTAMP_WITH_TIME_ZONE,
70+
TIME,
71+
TIME_WITH_TIME_ZONE,
72+
VARBINARY,
73+
VARCHAR,
74+
CHAR,
75+
ROW,
76+
ARRAY,
77+
MAP,
78+
JSON,
79+
IPADDRESS,
80+
UUID,
81+
GEOMETRY,
82+
SPHERICAL_GEOGRAPHY,
83+
BING_TILE,
84+
"color",
85+
"KdbTree",
86+
"CodePoints",
87+
"JsonPath",
88+
"Regressor",
89+
"JoniRegExp",
90+
"unknown",
91+
"ObjectId",
92+
"SetDigest",
93+
"Re2JRegExp",
94+
"Model",
95+
"tdigest",
96+
"LikePattern",
97+
"function",
98+
"Classifier")
99+
val typeInfos: Set[String] = Set()
100+
while (typeInfo.next()) {
101+
assert(types.contains(typeInfo.getString(TYPE_NAME)))
102+
typeInfos += typeInfo.getString(TYPE_NAME)
103+
}
104+
assert(types.size === typeInfos.size)
105+
}
106+
}
107+
48108
test("trino - get catalogs") {
49109
withJdbcStatement() { statement =>
50110
val meta = statement.getConnection.getMetaData

0 commit comments

Comments
 (0)