public RowSet getOperationLogRowSet( OperationHandle opHandle, FetchOrientation orientation, long maxRows, HiveConf hConf) throws HiveSQLException { TableSchema tableSchema = new TableSchema(getLogSchema()); RowSet rowSet = RowSetFactory.create(tableSchema, getOperation(opHandle).getProtocolVersion()); if (hConf.getBoolVar(ConfVars.HIVE_SERVER2_LOGGING_OPERATION_ENABLED) == false) { LOG.warn( "Try to get operation log when hive.server2.logging.operation.enabled is false, no log will be returned. "); return rowSet; } // get the OperationLog object from the operation OperationLog operationLog = getOperation(opHandle).getOperationLog(); if (operationLog == null) { throw new HiveSQLException("Couldn't find log associated with operation handle: " + opHandle); } // read logs List<String> logs; try { logs = operationLog.readOperationLog(isFetchFirst(orientation), maxRows); } catch (SQLException e) { throw new HiveSQLException(e.getMessage(), e.getCause()); } // convert logs to RowSet for (String log : logs) { rowSet.addRow(new String[] {log}); } return rowSet; }
private void initOperationLogCapture(String loggingMode) { // Register another Appender (with the same layout) that talks to us. Appender ap = LogDivertAppender.createInstance(this, OperationLog.getLoggingLevel(loggingMode)); LoggerContext context = (LoggerContext) LogManager.getContext(false); Configuration configuration = context.getConfiguration(); LoggerConfig loggerConfig = configuration.getLoggerConfig(LoggerFactory.getLogger(getClass()).getName()); loggerConfig.addAppender(ap, null, null); context.updateLoggers(); ap.start(); }
private void registerCurrentOperationLog() { if (isOperationLogEnabled) { if (operationLog == null) { LOG.warn( "Failed to get current OperationLog object of Operation: " + getHandle().getHandleIdentifier()); isOperationLogEnabled = false; return; } OperationLog.setCurrentOperationLog(operationLog); } }
public OperationLog getOperationLogByThread() { return OperationLog.getCurrentOperationLog(); }