[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 f09dcbc8 [hongdongdong] [KYUUBI #1885] Add GetCatalogs for trino engine Authored-by: hongdongdong <hongdongdong@cmss.chinamobile.com> Signed-off-by: Cheng Pan <chengpan@apache.org>
This commit is contained in:
parent
b952b7b5d8
commit
aa88c376b7
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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
|
||||
import org.apache.kyuubi.operation.OperationType
|
||||
import org.apache.kyuubi.session.Session
|
||||
|
||||
class GetCatalogs(session: Session)
|
||||
extends TrinoOperation(OperationType.GET_CATALOGS, session) {
|
||||
|
||||
override protected def runInternal(): Unit = {
|
||||
try {
|
||||
val trinoStatement = TrinoStatement(
|
||||
trinoContext,
|
||||
session.sessionManager.getConf,
|
||||
"SELECT TABLE_CAT FROM system.jdbc.catalogs")
|
||||
schema = trinoStatement.getColumns
|
||||
val resultSet = trinoStatement.execute()
|
||||
iter = new IterableFetchIterator(resultSet)
|
||||
} catch onError()
|
||||
}
|
||||
}
|
||||
@ -39,7 +39,10 @@ class TrinoOperationManager extends OperationManager("TrinoOperationManager") {
|
||||
|
||||
override def newGetTypeInfoOperation(session: Session): Operation = null
|
||||
|
||||
override def newGetCatalogsOperation(session: Session): Operation = null
|
||||
override def newGetCatalogsOperation(session: Session): Operation = {
|
||||
val op = new GetCatalogs(session)
|
||||
addOperation(op)
|
||||
}
|
||||
|
||||
override def newGetSchemasOperation(
|
||||
session: Session,
|
||||
|
||||
@ -18,6 +18,7 @@
|
||||
package org.apache.kyuubi.engine.trino.operation
|
||||
|
||||
import scala.collection.JavaConverters._
|
||||
import scala.collection.mutable.ArrayBuffer
|
||||
|
||||
import org.apache.hive.service.rpc.thrift.TCancelOperationReq
|
||||
import org.apache.hive.service.rpc.thrift.TCloseOperationReq
|
||||
@ -33,6 +34,7 @@ import org.apache.hive.service.rpc.thrift.TStatusCode
|
||||
import org.apache.kyuubi.config.KyuubiConf.ENGINE_TRINO_CONNECTION_CATALOG
|
||||
import org.apache.kyuubi.engine.trino.WithTrinoEngine
|
||||
import org.apache.kyuubi.operation.HiveJDBCTestHelper
|
||||
import org.apache.kyuubi.operation.meta.ResultSetSchemaConstant.TABLE_CAT
|
||||
|
||||
class TrinoOperationSuite extends WithTrinoEngine with HiveJDBCTestHelper {
|
||||
override def withKyuubiConf: Map[String, String] = Map(
|
||||
@ -43,6 +45,19 @@ class TrinoOperationSuite extends WithTrinoEngine with HiveJDBCTestHelper {
|
||||
|
||||
override protected def jdbcUrl: String = getJdbcUrl
|
||||
|
||||
test("trino - get catalogs") {
|
||||
withJdbcStatement() { statement =>
|
||||
val meta = statement.getConnection.getMetaData
|
||||
val catalogs = meta.getCatalogs
|
||||
val resultSetBuffer = ArrayBuffer[String]()
|
||||
while (catalogs.next()) {
|
||||
resultSetBuffer += catalogs.getString(TABLE_CAT)
|
||||
}
|
||||
assert(resultSetBuffer.contains("memory"))
|
||||
assert(resultSetBuffer.contains("system"))
|
||||
}
|
||||
}
|
||||
|
||||
test("execute statement - select decimal") {
|
||||
withJdbcStatement() { statement =>
|
||||
val resultSet = statement.executeQuery("SELECT DECIMAL '1.2' as col1, DECIMAL '1.23' AS col2")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user