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 4170659..4c73d6a 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; @@ -3008,6 +3009,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 d6067e7..764007c 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 @@ -81,7 +81,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 c1621e0..53fbf26 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 @@ -81,7 +81,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; } }; @@ -279,7 +279,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();