[KYUUBI #1131] Rename KyuubiDriver to KyuubiHiveDriver

<!--
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.
-->
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 <chengpan@apache.org>
Signed-off-by: Kent Yao <yao@apache.org>
This commit is contained in:
Cheng Pan 2021-09-24 13:36:19 +08:00 committed by Kent Yao
parent 0ee8eff5a0
commit eeb35f31dd
No known key found for this signature in database
GPG Key ID: F7051850A0AF904D
6 changed files with 73 additions and 26 deletions

View File

@ -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 {
}

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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;

View File

@ -14,3 +14,4 @@
# limitations under the License.
org.apache.kyuubi.jdbc.KyuubiDriver
org.apache.kyuubi.jdbc.KyuubiHiveDriver

View File

@ -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()
}
}
}