Shi Yuxiang created HIVE-8570:
---------------------------------

             Summary: Unexpected "IllegalArgumentException" from parseURL 
method in org.apache.hive.jdbc.Utils interrupts java.sql.driverManager running 
before choosing the right driver when using multiple datasource
                 Key: HIVE-8570
                 URL: https://issues.apache.org/jira/browse/HIVE-8570
             Project: Hive
          Issue Type: Bug
          Components: JDBC
    Affects Versions: 0.10.0
         Environment: centos 6,cdh 4.3.1
            Reporter: Shi Yuxiang


My JDK is 1.6. 
I checked the source code in jdbc-hive 0.10-cdh4.3.1. I found the code in 
parseURL is not appropriate. When uri is not start with URL_PREFIX, parseURL 
will throw an exception. This exception is thrown to the outside of hive-jdbc. 
It will interrupt some logic outside of this driver, especially when I use 
multiple datesources besides hive.

if (!uri.startsWith(URL_PREFIX)) {
      throw new IllegalArgumentException("Bad URL format");
}

For example, I use mysql-connector-java and hive-jdbc to connect to mysql and 
hive respectively in my project. And I use java.sql.drivermanager to get 
connections after I initialize both hive and mysql jdbc drivers.
In java.sql.drivermanager, getconnection (...) method, we will choose the right 
driver according to url. In fact, it scans the driver list and tries each 
driver to get connection according to url. The code is like following:
for (int i = 0; i < drivers.size(); i++) {
            DriverInfo di = (DriverInfo)drivers.elementAt(i);
            // If the caller does not have permission to load the driver then 
            // skip it.
            if ( getCallerClass(callerCL, di.driverClassName ) != 
di.driverClass ) {
                println("    skipping: " + di);
                continue;
            }
            try {
                println("    trying " + di);
// ---------------------------------- try to get connection here 
--------------------------
                Connection result = di.driver.connect(url, info);
// ---------------------------------- if the connection is not null, return 
---------------
                if (result != null) {
                    // Success!
                    println("getConnection returning " + di);
                    return (result);
                }
            } catch (SQLException ex) {
                if (reason == null) {
                    reason = ex;
                }
            }
        }
In this way, if I use hive.jdbc.Utils.parseURL to parse a mysql uri, parseURL 
will throw an IllegalArgumentException("Bad URL format"). Because drivermanager 
does not handler this exception, so drivermanager stops trying other drivers.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to