From eeb35f31dde92a633da1208fc5365b91f66740e9 Mon Sep 17 00:00:00 2001 From: Cheng Pan Date: Fri, 24 Sep 2021 13:36:19 +0800 Subject: [PATCH] [KYUUBI #1131] Rename KyuubiDriver to KyuubiHiveDriver ### _Why are the changes needed?_ This PR is based on discussion https://www.mail-archive.com/devkyuubi.apache.org/msg00977.html ### _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 - [ ] [Run test](https://kyuubi.readthedocs.io/en/latest/develop_tools/testing.html#running-tests) locally before make a pull request Closes #1147 from pan3793/jdbc-rename. Closes #1131 500edae6 [Cheng Pan] Add javadoc bd9f94c2 [Cheng Pan] Add deprecated KyuubiDriver test d9688d8b [Cheng Pan] [KYUUBI #1131] Rename KyuubiDriver to KyuubiHiveDriver Authored-by: Cheng Pan Signed-off-by: Kent Yao --- .../org/apache/kyuubi/jdbc/KyuubiDriver.java | 25 +++-------- .../apache/kyuubi/jdbc/KyuubiHiveDriver.java | 44 +++++++++++++++++++ .../jdbc/{ => hive}/KyuubiConnection.java | 2 +- .../{ => hive}/KyuubiDatabaseMetaData.java | 2 +- .../META-INF/services/java.sql.Driver | 1 + ...uite.scala => KyuubiHiveDriverSuite.scala} | 25 +++++++++-- 6 files changed, 73 insertions(+), 26 deletions(-) create mode 100644 kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/KyuubiHiveDriver.java rename kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/{ => hive}/KyuubiConnection.java (98%) rename kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/{ => hive}/KyuubiDatabaseMetaData.java (98%) rename kyuubi-hive-jdbc/src/test/scala/org/apache/kyuubi/jdbc/{KyuubiDriverSuite.scala => KyuubiHiveDriverSuite.scala} (76%) diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/KyuubiDriver.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/KyuubiDriver.java index d4e83705d..4238d523d 100644 --- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/KyuubiDriver.java +++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/KyuubiDriver.java @@ -17,24 +17,9 @@ package org.apache.kyuubi.jdbc; -import org.apache.hive.jdbc.HiveDriver; - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.SQLException; -import java.util.Properties; - -public class KyuubiDriver extends HiveDriver { - static { - try { - DriverManager.registerDriver(new KyuubiDriver()); - } catch (SQLException e) { - throw new RuntimeException("Failed to register driver", e); - } - } - - @Override - public Connection connect(String url, Properties info) throws SQLException { - return acceptsURL(url) ? new KyuubiConnection(url, info) : null; - } +/** + * @deprecated Use `KyuubiHiveDriver` instead. + */ +@Deprecated +public class KyuubiDriver extends KyuubiHiveDriver { } diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/KyuubiHiveDriver.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/KyuubiHiveDriver.java new file mode 100644 index 000000000..a3ca8fbeb --- /dev/null +++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/KyuubiHiveDriver.java @@ -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.jdbc; + +import org.apache.hive.jdbc.HiveDriver; +import org.apache.kyuubi.jdbc.hive.KyuubiConnection; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.util.Properties; + +/** + * Kyuubi JDBC driver to connect to Kyuubi server via HiveServer2 thrift protocol. + */ +public class KyuubiHiveDriver extends HiveDriver { + static { + try { + DriverManager.registerDriver(new KyuubiHiveDriver()); + } catch (SQLException e) { + throw new RuntimeException("Failed to register driver", e); + } + } + + @Override + public Connection connect(String url, Properties info) throws SQLException { + return acceptsURL(url) ? new KyuubiConnection(url, info) : null; + } +} diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/KyuubiConnection.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiConnection.java similarity index 98% rename from kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/KyuubiConnection.java rename to kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiConnection.java index c7a832a9c..bccecc3cb 100644 --- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/KyuubiConnection.java +++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiConnection.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.kyuubi.jdbc; +package org.apache.kyuubi.jdbc.hive; import java.lang.reflect.Field; import java.sql.DatabaseMetaData; diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/KyuubiDatabaseMetaData.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiDatabaseMetaData.java similarity index 98% rename from kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/KyuubiDatabaseMetaData.java rename to kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiDatabaseMetaData.java index 1a45bf936..435f0c7b1 100644 --- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/KyuubiDatabaseMetaData.java +++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiDatabaseMetaData.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.kyuubi.jdbc; +package org.apache.kyuubi.jdbc.hive; import org.apache.hive.jdbc.HiveDatabaseMetaData; import org.apache.hive.jdbc.HiveQueryResultSet; diff --git a/kyuubi-hive-jdbc/src/main/resources/META-INF/services/java.sql.Driver b/kyuubi-hive-jdbc/src/main/resources/META-INF/services/java.sql.Driver index 6611c7e36..ab16876b7 100644 --- a/kyuubi-hive-jdbc/src/main/resources/META-INF/services/java.sql.Driver +++ b/kyuubi-hive-jdbc/src/main/resources/META-INF/services/java.sql.Driver @@ -14,3 +14,4 @@ # limitations under the License. org.apache.kyuubi.jdbc.KyuubiDriver +org.apache.kyuubi.jdbc.KyuubiHiveDriver diff --git a/kyuubi-hive-jdbc/src/test/scala/org/apache/kyuubi/jdbc/KyuubiDriverSuite.scala b/kyuubi-hive-jdbc/src/test/scala/org/apache/kyuubi/jdbc/KyuubiHiveDriverSuite.scala similarity index 76% rename from kyuubi-hive-jdbc/src/test/scala/org/apache/kyuubi/jdbc/KyuubiDriverSuite.scala rename to kyuubi-hive-jdbc/src/test/scala/org/apache/kyuubi/jdbc/KyuubiHiveDriverSuite.scala index b1f68111f..f6116a22c 100644 --- a/kyuubi-hive-jdbc/src/test/scala/org/apache/kyuubi/jdbc/KyuubiDriverSuite.scala +++ b/kyuubi-hive-jdbc/src/test/scala/org/apache/kyuubi/jdbc/KyuubiHiveDriverSuite.scala @@ -22,10 +22,11 @@ import java.util.Properties import org.apache.kyuubi.IcebergSuiteMixin import org.apache.kyuubi.engine.spark.WithSparkSQLEngine import org.apache.kyuubi.engine.spark.shim.SparkCatalogShim +import org.apache.kyuubi.jdbc.hive.{KyuubiConnection, KyuubiDatabaseMetaData} import org.apache.kyuubi.tags.IcebergTest @IcebergTest -class KyuubiDriverSuite extends WithSparkSQLEngine with IcebergSuiteMixin { +class KyuubiHiveDriverSuite extends WithSparkSQLEngine with IcebergSuiteMixin { override def withKyuubiConf: Map[String, String] = extraConfigs - "spark.sql.defaultCatalog" - @@ -39,8 +40,8 @@ class KyuubiDriverSuite extends WithSparkSQLEngine with IcebergSuiteMixin { } test("get tables with kyuubi driver") { - val kyuubiDriver = new KyuubiDriver() - val connection = kyuubiDriver.connect(getJdbcUrl, new Properties()) + val driver = new KyuubiHiveDriver() + val connection = driver.connect(getJdbcUrl, new Properties()) assert(connection.isInstanceOf[KyuubiConnection]) val metaData = connection.getMetaData assert(metaData.isInstanceOf[KyuubiDatabaseMetaData]) @@ -68,6 +69,22 @@ class KyuubiDriverSuite extends WithSparkSQLEngine with IcebergSuiteMixin { statement.close() connection.close() } - connection + } + + test("deprecated KyuubiDriver also works") { + val driver = new KyuubiDriver() + val connection = driver.connect(getJdbcUrl, new Properties()) + assert(connection.isInstanceOf[KyuubiConnection]) + val metaData = connection.getMetaData + assert(metaData.isInstanceOf[KyuubiDatabaseMetaData]) + val statement = connection.createStatement() + try { + val resultSet = statement.executeQuery(s"SELECT 1") + assert(resultSet.next()) + assert(resultSet.getInt(1) === 1) + } finally { + statement.close() + connection.close() + } } }