use of org.apache.commons.dbcp2.DelegatingStatement in project zeppelin by apache.
the class HiveUtils method startHiveMonitorThread.
/**
* Display hive job execution info, and progress info for hive >= 2.3
*
* @param stmt
* @param context
* @param displayLog
*/
public static void startHiveMonitorThread(Statement stmt, InterpreterContext context, boolean displayLog, JDBCInterpreter jdbcInterpreter) {
HiveStatement hiveStmt = (HiveStatement) ((DelegatingStatement) ((DelegatingStatement) stmt).getDelegate()).getDelegate();
String hiveVersion = HiveVersionInfo.getVersion();
ProgressBar progressBarTemp = null;
if (isProgressBarSupported(hiveVersion)) {
LOGGER.debug("ProgressBar is supported for hive version: {}", hiveVersion);
progressBarTemp = new ProgressBar();
} else {
LOGGER.debug("ProgressBar is not supported for hive version: {}", hiveVersion);
}
// need to use final variable progressBar in thread, so need progressBarTemp here.
final ProgressBar progressBar = progressBarTemp;
final long queryInterval = Long.parseLong(jdbcInterpreter.getProperty("zeppelin.jdbc.hive.monitor.query_interval", DEFAULT_QUERY_PROGRESS_INTERVAL + ""));
Thread thread = new Thread(() -> {
String jobUrlTemplate = jdbcInterpreter.getProperty("zeppelin.jdbc.hive.jobUrl.template");
boolean jobUrlExtracted = false;
try {
while (hiveStmt.hasMoreLogs() && !hiveStmt.isClosed() && !Thread.interrupted()) {
Thread.sleep(queryInterval);
List<String> logs = hiveStmt.getQueryLog();
String logsOutput = StringUtils.join(logs, System.lineSeparator());
LOGGER.debug("Hive job output: {}", logsOutput);
boolean displayLogProperty = context.getBooleanLocalProperty("displayLog", displayLog);
if (!StringUtils.isBlank(logsOutput) && displayLogProperty) {
context.out.write(logsOutput + "\n");
context.out.flush();
}
if (!StringUtils.isBlank(logsOutput) && progressBar != null && displayLogProperty) {
progressBar.operationLogShowedToUser();
}
if (!jobUrlExtracted) {
jobUrlExtracted = extractJobURL(logsOutput, jobUrlTemplate, context);
}
}
} catch (InterruptedException e) {
LOGGER.warn("Hive monitor thread is interrupted", e);
Thread.currentThread().interrupt();
} catch (Exception e) {
LOGGER.warn("Fail to monitor hive statement", e);
}
LOGGER.info("HiveMonitor-Thread is finished");
});
thread.setName("HiveMonitor-Thread");
thread.setDaemon(true);
thread.start();
LOGGER.info("Start HiveMonitor-Thread for sql: {}", hiveStmt);
if (progressBar != null) {
// old: hiveStmt.setInPlaceUpdateStream(progressBar.getInPlaceUpdateStream(context.out));
// Move codes into ProgressBar to delay NoClassDefFoundError of InPlaceUpdateStream
// until ProgressBar instanced.
// When hive < 2.3, ProgressBar will not be instanced, so it works well.
progressBar.setInPlaceUpdateStream(hiveStmt, context.out);
}
}
Aggregations