Skip to content

Commit aa88c37

Browse files
hddongpan3793
authored andcommitted
[KYUUBI #1885] Add GetCatalogs 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 `GetCatalogs` for trino engine. ### _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 - [ ] [Run test](https://kyuubi.apache.org/docs/latest/develop_tools/testing.html#running-tests) locally before make a pull request Closes #1888 from hddong/add-trino-get-catalogs. Closes #1885 f09dcbc [hongdongdong] [KYUUBI #1885] Add GetCatalogs for trino engine Authored-by: hongdongdong <hongdongdong@cmss.chinamobile.com> Signed-off-by: Cheng Pan <chengpan@apache.org>
1 parent b952b7b commit aa88c37

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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
22+
import org.apache.kyuubi.operation.OperationType
23+
import org.apache.kyuubi.session.Session
24+
25+
class GetCatalogs(session: Session)
26+
extends TrinoOperation(OperationType.GET_CATALOGS, session) {
27+
28+
override protected def runInternal(): Unit = {
29+
try {
30+
val trinoStatement = TrinoStatement(
31+
trinoContext,
32+
session.sessionManager.getConf,
33+
"SELECT TABLE_CAT FROM system.jdbc.catalogs")
34+
schema = trinoStatement.getColumns
35+
val resultSet = trinoStatement.execute()
36+
iter = new IterableFetchIterator(resultSet)
37+
} catch onError()
38+
}
39+
}

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
@@ -39,7 +39,10 @@ class TrinoOperationManager extends OperationManager("TrinoOperationManager") {
3939

4040
override def newGetTypeInfoOperation(session: Session): Operation = null
4141

42-
override def newGetCatalogsOperation(session: Session): Operation = null
42+
override def newGetCatalogsOperation(session: Session): Operation = {
43+
val op = new GetCatalogs(session)
44+
addOperation(op)
45+
}
4346

4447
override def newGetSchemasOperation(
4548
session: Session,

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.apache.kyuubi.engine.trino.operation
1919

2020
import scala.collection.JavaConverters._
21+
import scala.collection.mutable.ArrayBuffer
2122

2223
import org.apache.hive.service.rpc.thrift.TCancelOperationReq
2324
import org.apache.hive.service.rpc.thrift.TCloseOperationReq
@@ -33,6 +34,7 @@ import org.apache.hive.service.rpc.thrift.TStatusCode
3334
import org.apache.kyuubi.config.KyuubiConf.ENGINE_TRINO_CONNECTION_CATALOG
3435
import org.apache.kyuubi.engine.trino.WithTrinoEngine
3536
import org.apache.kyuubi.operation.HiveJDBCTestHelper
37+
import org.apache.kyuubi.operation.meta.ResultSetSchemaConstant.TABLE_CAT
3638

3739
class TrinoOperationSuite extends WithTrinoEngine with HiveJDBCTestHelper {
3840
override def withKyuubiConf: Map[String, String] = Map(
@@ -43,6 +45,19 @@ class TrinoOperationSuite extends WithTrinoEngine with HiveJDBCTestHelper {
4345

4446
override protected def jdbcUrl: String = getJdbcUrl
4547

48+
test("trino - get catalogs") {
49+
withJdbcStatement() { statement =>
50+
val meta = statement.getConnection.getMetaData
51+
val catalogs = meta.getCatalogs
52+
val resultSetBuffer = ArrayBuffer[String]()
53+
while (catalogs.next()) {
54+
resultSetBuffer += catalogs.getString(TABLE_CAT)
55+
}
56+
assert(resultSetBuffer.contains("memory"))
57+
assert(resultSetBuffer.contains("system"))
58+
}
59+
}
60+
4661
test("execute statement - select decimal") {
4762
withJdbcStatement() { statement =>
4863
val resultSet = statement.executeQuery("SELECT DECIMAL '1.2' as col1, DECIMAL '1.23' AS col2")

0 commit comments

Comments
 (0)