mdayakar commented on code in PR #6207:
URL: https://github.com/apache/hive/pull/6207#discussion_r2560178801
##########
beeline/src/java/org/apache/hive/beeline/Commands.java:
##########
@@ -340,48 +341,48 @@ public boolean reconnect(String line) {
return true;
}
-
public boolean scan(String line) throws IOException {
- TreeSet<String> names = new TreeSet<String>();
-
if (beeLine.getDrivers() == null) {
beeLine.setDrivers(beeLine.scanDrivers());
}
- beeLine.info(beeLine.loc("drivers-found-count",
beeLine.getDrivers().size()));
+ // Use a TreeSet to get a unique, sorted list of drivers by class name.
+ Set<Driver> drivers =
+ new TreeSet<>(Comparator.comparing(d -> d.getClass().getName()));
+ drivers.addAll(beeLine.getDrivers());
- // unique the list
- for (Iterator<Driver> i = beeLine.getDrivers().iterator(); i.hasNext();) {
- names.add(i.next().getClass().getName());
- }
+ // Get count of the unique driver in classpath
+ beeLine.info(beeLine.loc("drivers-found-count", drivers.size()));
- beeLine.output(beeLine.getColorBuffer()
- .bold(beeLine.getColorBuffer().pad(beeLine.loc("compliant"),
10).getMono())
- .bold(beeLine.getColorBuffer().pad(beeLine.loc("jdbc-version"),
8).getMono())
- .bold(beeLine.getColorBuffer(beeLine.loc("driver-class")).getMono()));
+ beeLine.output(
+ beeLine
+ .getColorBuffer()
+ .bold(beeLine.getColorBuffer().pad(beeLine.loc("compliant"),
10).getMono())
+ .bold(beeLine.getColorBuffer().pad(beeLine.loc("jdbc-version"),
8).getMono())
+
.bold(beeLine.getColorBuffer(beeLine.loc("driver-class")).getMono()));
- for (Iterator<String> i = names.iterator(); i.hasNext();) {
- String name = i.next().toString();
+ for (Driver driver : drivers) {
+ String name = driver.getClass().getName();
try {
- Driver driver = (Driver) Class.forName(name).newInstance();
- ColorBuffer msg = beeLine.getColorBuffer()
- .pad(driver.jdbcCompliant() ? "yes" : "no", 10)
- .pad(driver.getMajorVersion() + "."
- + driver.getMinorVersion(), 8)
- .append(name);
+ // Use the driver instance that ServiceLoader already created for us.
+ ColorBuffer msg =
+ beeLine
+ .getColorBuffer()
+ .pad(driver.jdbcCompliant() ? "yes" : "no", 10)
+ .pad(driver.getMajorVersion() + "." +
driver.getMinorVersion(), 8)
+ .append(name);
if (driver.jdbcCompliant()) {
beeLine.output(msg);
} else {
beeLine.output(beeLine.getColorBuffer().red(msg.getMono()));
}
} catch (Throwable t) {
Review Comment:
is the `catch (Throwable t)` still required?
##########
beeline/src/java/org/apache/hive/beeline/DatabaseConnection.java:
##########
@@ -59,10 +58,8 @@ public boolean isClosed() {
return (null == connection);
}
- public DatabaseConnection(BeeLine beeLine, String driver, String url,
- Properties info) throws SQLException {
+ public DatabaseConnection(BeeLine beeLine, String url, Properties info)
throws SQLException {
Review Comment:
From the `DatabaseConnection` constructor code it won't throw any exception
so `throws SQLException` can be removed.
##########
hplsql/src/main/java/org/apache/hive/hplsql/Conn.java:
##########
@@ -146,15 +146,11 @@ synchronized Connection getConnection(String connName)
throws Exception {
* @throws Exception
*/
Connection openConnection(String connStr) throws Exception {
- String driver = "org.apache.hadoop.hive.jdbc.HiveDriver";
StringBuilder url = new StringBuilder();
String usr = "";
String pwd = "";
if (connStr != null) {
String[] c = connStr.split(";");
- if (c.length >= 1) {
- driver = c[0];
Review Comment:
if driver name is not expected in the `connStr` then `connStr.split(";");`
need to be adjusted accordingly.
##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/jdbc/NoPoolConnectionPool.java:
##########
@@ -62,38 +60,23 @@ public Connection getConnection() throws SQLException {
@Override
public Connection getConnection(String username, String password) throws
SQLException {
- // Find the JDBC driver
- if (driver == null) {
- String driverName = MetastoreConf.getVar(conf,
MetastoreConf.ConfVars.CONNECTION_DRIVER);
- if (driverName == null || driverName.equals("")) {
- String msg = "JDBC driver for transaction db not set in configuration
" +
- "file, need to set " +
MetastoreConf.ConfVars.CONNECTION_DRIVER.getVarname();
- LOG.error(msg);
- throw new RuntimeException(msg);
- }
- try {
- LOG.info("Going to load JDBC driver {}", driverName);
- driver = (Driver) Class.forName(driverName).newInstance();
- } catch (InstantiationException e) {
- throw new RuntimeException("Unable to instantiate driver " +
driverName + ", " +
- e.getMessage(), e);
- } catch (IllegalAccessException e) {
- throw new RuntimeException(
- "Unable to access driver " + driverName + ", " + e.getMessage(),
- e);
- } catch (ClassNotFoundException e) {
- throw new RuntimeException("Unable to find driver " + driverName + ",
" + e.getMessage(),
- e);
- }
- connString = MetastoreConf.getVar(conf,
MetastoreConf.ConfVars.CONNECT_URL_KEY);
+ String driverName = MetastoreConf.getVar(conf,
MetastoreConf.ConfVars.CONNECTION_DRIVER);
Review Comment:
Here we are reading the drivername from config and not using it. If not
configured throwing exception for the config which we are not using, I feel
this is not correct.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]