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/10 12:58:37 UTC

[incubator-kyuubi] branch master updated: [KYUUBI #1885] Add GetCatalogs 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 aa88c37  [KYUUBI #1885] Add GetCatalogs for trino engine
aa88c37 is described below

commit aa88c376b7c3fe8d190460d0e373e033009e116b
Author: hongdongdong <ho...@cmss.chinamobile.com>
AuthorDate: Thu Feb 10 20:58:27 2022 +0800

    [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 <ho...@cmss.chinamobile.com>
    Signed-off-by: Cheng Pan <ch...@apache.org>
---
 .../engine/trino/operation/GetCatalogs.scala       | 39 ++++++++++++++++++++++
 .../trino/operation/TrinoOperationManager.scala    |  5 ++-
 .../trino/operation/TrinoOperationSuite.scala      | 15 +++++++++
 3 files changed, 58 insertions(+), 1 deletion(-)

diff --git a/externals/kyuubi-trino-engine/src/main/scala/org/apache/kyuubi/engine/trino/operation/GetCatalogs.scala b/externals/kyuubi-trino-engine/src/main/scala/org/apache/kyuubi/engine/trino/operation/GetCatalogs.scala
new file mode 100644
index 0000000..fa75aa3
--- /dev/null
+++ b/externals/kyuubi-trino-engine/src/main/scala/org/apache/kyuubi/engine/trino/operation/GetCatalogs.scala
@@ -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()
+  }
+}
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 0f3a12d..823f463 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
@@ -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,
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 4e2289f..d985ef5 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
@@ -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")