mdayakar commented on code in PR #6207:
URL: https://github.com/apache/hive/pull/6207#discussion_r2567637463
##########
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:
I don't think `jdbcCompliant()`, `getMajorVersion()`, `getMinorVersion()`
these APIs throw any RuntimeExceptions from driver. Anyway its not a major
issue, you can take a call.
--
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]