mirror of
https://github.com/apache/impala.git
synced 2025-12-19 18:12:08 -05:00
IMPALA-10571: ImpalaJdbcClient might silently choose a different driver than the one specified
ImpalaJdbcClient might silently choose the HiveDriver when the connection string is not specified. It's because the default connection string is 'jdbc:hive2://...'. This patch adds a check to ImpalaJdbcClient to make sure the driver being used is the one specified by the user. If not, it raises an error. I also modified bin/run-jdbc-client.sh to make it easier to use different drivers. Users are now able to specify the classpath of their custom driver via the environment variable IMPALA_JDBC_DRIVER_CLASSPATH. Testing: * tested manually Change-Id: If7fdf49b7f04f4d9ae6286df5c8df6b205cbce8f Reviewed-on: http://gerrit.cloudera.org:8080/17164 Reviewed-by: Thomas Tauber-Marshall <tmarshall@cloudera.com> Tested-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com>
This commit is contained in:
committed by
Impala Public Jenkins
parent
d89c04bf80
commit
06fbb0d629
@@ -18,4 +18,5 @@
|
||||
# under the License.
|
||||
|
||||
. ${IMPALA_HOME}/bin/set-classpath.sh test
|
||||
CLASSPATH=${IMPALA_JDBC_DRIVER_CLASSPATH}:${CLASSPATH}
|
||||
"$JAVA" -cp $CLASSPATH org.apache.impala.testutil.ImpalaJdbcClient "$@"
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
package org.apache.impala.testutil;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.Driver;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.ResultSetMetaData;
|
||||
@@ -30,6 +31,7 @@ import org.apache.commons.cli.BasicParser;
|
||||
import org.apache.commons.cli.CommandLine;
|
||||
import org.apache.commons.cli.Options;
|
||||
import org.apache.commons.cli.ParseException;
|
||||
import org.apache.impala.common.ImpalaRuntimeException;
|
||||
import org.apache.log4j.ConsoleAppender;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.log4j.PatternLayout;
|
||||
@@ -85,13 +87,23 @@ public class ImpalaJdbcClient {
|
||||
}
|
||||
}
|
||||
|
||||
public void connect() throws ClassNotFoundException, SQLException {
|
||||
public void connect() throws ClassNotFoundException, SQLException,
|
||||
ImpalaRuntimeException {
|
||||
LOG.info("Using JDBC Driver Name: " + driverName_);
|
||||
LOG.info("Connecting to: " + connString_);
|
||||
|
||||
// Make sure the driver can be found, throws a ClassNotFoundException if
|
||||
// it is not available.
|
||||
Class.forName(driverName_);
|
||||
Driver d = DriverManager.getDriver(connString_);
|
||||
String driverClassName = d.getClass().getName();
|
||||
if (!driverClassName.equals(driverName_)) {
|
||||
throw new ImpalaRuntimeException(String.format(
|
||||
"Specified driver is %s, but for the given connection string %s the "+
|
||||
"selected driver is %s. You might want to specify a different connection " +
|
||||
"string with option -c.",
|
||||
driverName_, connString_, driverClassName));
|
||||
}
|
||||
conn_ = DriverManager.getConnection(connString_);
|
||||
stmt_ = conn_.createStatement();
|
||||
}
|
||||
@@ -335,7 +347,7 @@ public class ImpalaJdbcClient {
|
||||
* separated.
|
||||
*/
|
||||
public static void main(String[] args) throws SQLException, ClassNotFoundException,
|
||||
ParseException {
|
||||
ParseException, ImpalaRuntimeException {
|
||||
// Remove all prefixes from the logging output to make it easier to parse and disable
|
||||
// the root logger from spewing anything. This is done to make it easier to parse
|
||||
// the output.
|
||||
|
||||
Reference in New Issue
Block a user