diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java index 4450ad3..f04c819 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java @@ -47,6 +47,7 @@ import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException; +import java.sql.SQLFeatureNotSupportedException; import java.sql.SQLTransientException; import java.sql.Timestamp; import java.text.SimpleDateFormat; @@ -2752,6 +2753,24 @@ public static PreparedStatement prepareWithRetry(Connection conn, String stmt, } } + public static void setQueryTimeout(java.sql.Statement stmt, int timeout) throws SQLException { + if (timeout < 0) { + LOG.info("Invalid query timeout " + timeout); + return; + } + try { + stmt.setQueryTimeout(timeout); + } catch (SQLException e) { + String message = e.getMessage() == null ? null : e.getMessage().toLowerCase(); + if (e instanceof SQLFeatureNotSupportedException || + (message != null && (message.contains("implemented") || message.contains("supported")))) { + LOG.info("setQueryTimeout is not supported"); + return; + } + throw e; + } + } + /** * Introducing a random factor to the wait time before another retry. * The wait time is dependent on # of failures and a random factor. diff --git ql/src/java/org/apache/hadoop/hive/ql/stats/jdbc/JDBCStatsAggregator.java ql/src/java/org/apache/hadoop/hive/ql/stats/jdbc/JDBCStatsAggregator.java index f636cff..d0c48ee 100644 --- ql/src/java/org/apache/hadoop/hive/ql/stats/jdbc/JDBCStatsAggregator.java +++ ql/src/java/org/apache/hadoop/hive/ql/stats/jdbc/JDBCStatsAggregator.java @@ -76,7 +76,7 @@ public boolean connect(Configuration hiveconf, Task sourceTask) { Utilities.SQLCommand setQueryTimeout = new Utilities.SQLCommand() { @Override public Void run(PreparedStatement stmt) throws SQLException { - stmt.setQueryTimeout(timeout); + Utilities.setQueryTimeout(stmt, timeout); return null; } }; diff --git ql/src/java/org/apache/hadoop/hive/ql/stats/jdbc/JDBCStatsPublisher.java ql/src/java/org/apache/hadoop/hive/ql/stats/jdbc/JDBCStatsPublisher.java index db62721..9b2a70c 100644 --- ql/src/java/org/apache/hadoop/hive/ql/stats/jdbc/JDBCStatsPublisher.java +++ ql/src/java/org/apache/hadoop/hive/ql/stats/jdbc/JDBCStatsPublisher.java @@ -77,7 +77,7 @@ public boolean connect(Configuration hiveconf) { Utilities.SQLCommand setQueryTimeout = new Utilities.SQLCommand() { @Override public Void run(PreparedStatement stmt) throws SQLException { - stmt.setQueryTimeout(timeout); + Utilities.setQueryTimeout(stmt, timeout); return null; } }; @@ -271,7 +271,7 @@ public boolean init(Configuration hconf) { conn = DriverManager.getConnection(connectionString); stmt = conn.createStatement(); - stmt.setQueryTimeout(timeout); + Utilities.setQueryTimeout(stmt, timeout); // Check if the table exists DatabaseMetaData dbm = conn.getMetaData();