Search in sources :

Example 1 with OperationLog

use of org.apache.hadoop.hive.ql.session.OperationLog in project hive by apache.

the class LogDivertAppender method append.

@Override
public void append(LogEvent event) {
    super.append(event);
    String logOutput = getOutput();
    manager.reset();
    OperationLog log = operationManager.getOperationLogByThread();
    if (log == null) {
        LOG.debug(" ---+++=== Dropped log event from thread " + event.getThreadName());
        return;
    }
    log.writeOperationLog(logOutput);
}
Also used : OperationLog(org.apache.hadoop.hive.ql.session.OperationLog)

Example 2 with OperationLog

use of org.apache.hadoop.hive.ql.session.OperationLog in project hive by apache.

the class OperationManager method getOperationLogRowSet.

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(), false);
    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;
}
Also used : TableSchema(org.apache.hive.service.cli.TableSchema) SQLException(java.sql.SQLException) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) RowSet(org.apache.hive.service.cli.RowSet) OperationLog(org.apache.hadoop.hive.ql.session.OperationLog)

Example 3 with OperationLog

use of org.apache.hadoop.hive.ql.session.OperationLog in project hive by apache.

the class Operation method createOperationLog.

protected void createOperationLog() {
    if (parentSession.isOperationLogEnabled()) {
        File operationLogFile = new File(parentSession.getOperationLogSessionDir(), opHandle.getHandleIdentifier().toString());
        isOperationLogEnabled = true;
        // create log file
        try {
            if (operationLogFile.exists()) {
                LOG.warn("The operation log file should not exist, but it is already there: " + operationLogFile.getAbsolutePath());
                operationLogFile.delete();
            }
            if (!operationLogFile.getParentFile().exists()) {
                LOG.warn("Operations log directory for this session does not exist, it could have been deleted " + "externally. Recreating the directory for future queries in this session but the older operation " + "logs for this session are no longer available");
                if (!operationLogFile.getParentFile().mkdir()) {
                    LOG.warn("Log directory for this session could not be created, disabling " + "operation logs: " + operationLogFile.getParentFile().getAbsolutePath());
                    isOperationLogEnabled = false;
                    return;
                }
            }
            if (!operationLogFile.createNewFile()) {
                // If it can be read/written, keep its contents and use it.
                if (!operationLogFile.canRead() || !operationLogFile.canWrite()) {
                    LOG.warn("The already existed operation log file cannot be recreated, " + "and it cannot be read or written: " + operationLogFile.getAbsolutePath());
                    isOperationLogEnabled = false;
                    return;
                }
            }
        } catch (Exception e) {
            LOG.warn("Unable to create operation log file: " + operationLogFile.getAbsolutePath(), e);
            isOperationLogEnabled = false;
            return;
        }
        // create OperationLog object with above log file
        try {
            operationLog = new OperationLog(opHandle.toString(), operationLogFile, parentSession.getHiveConf());
        } catch (FileNotFoundException e) {
            LOG.warn("Unable to instantiate OperationLog object for operation: " + opHandle, e);
            isOperationLogEnabled = false;
            return;
        }
        // register this operationLog to current thread
        OperationLog.setCurrentOperationLog(operationLog);
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) OperationLog(org.apache.hadoop.hive.ql.session.OperationLog) File(java.io.File) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) FileNotFoundException(java.io.FileNotFoundException)

Example 4 with OperationLog

use of org.apache.hadoop.hive.ql.session.OperationLog in project hive by apache.

the class HiveCommandOperation method runInternal.

@Override
public void runInternal() throws HiveSQLException {
    setState(OperationState.RUNNING);
    try {
        String command = getStatement().trim();
        String[] tokens = statement.split("\\s");
        String commandArgs = command.substring(tokens[0].length()).trim();
        CommandProcessorResponse response = commandProcessor.run(commandArgs);
        int returnCode = response.getResponseCode();
        if (returnCode != 0) {
            throw toSQLException("Error while processing statement", response);
        }
        Schema schema = response.getSchema();
        if (schema != null) {
            setHasResultSet(true);
            resultSchema = new TableSchema(schema);
        } else {
            setHasResultSet(false);
            resultSchema = new TableSchema();
        }
        if (response.getConsoleMessages() != null) {
            // Propagate processor messages (if any) to beeline or other client.
            OperationLog ol = OperationLog.getCurrentOperationLog();
            if (ol != null) {
                for (String consoleMsg : response.getConsoleMessages()) {
                    ol.writeOperationLog(LoggingLevel.EXECUTION, consoleMsg + "\n");
                }
            }
        }
    } catch (HiveSQLException e) {
        setState(OperationState.ERROR);
        throw e;
    } catch (Exception e) {
        setState(OperationState.ERROR);
        throw new HiveSQLException("Error running query: " + e.toString(), e);
    }
    setState(OperationState.FINISHED);
}
Also used : TableSchema(org.apache.hive.service.cli.TableSchema) CommandProcessorResponse(org.apache.hadoop.hive.ql.processors.CommandProcessorResponse) TableSchema(org.apache.hive.service.cli.TableSchema) Schema(org.apache.hadoop.hive.metastore.api.Schema) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) OperationLog(org.apache.hadoop.hive.ql.session.OperationLog) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 5 with OperationLog

use of org.apache.hadoop.hive.ql.session.OperationLog in project hive by apache.

the class ColumnStatsSemanticAnalyzer method logTypeWarning.

private void logTypeWarning(String colName, String colType) {
    String warning = "Only primitive type arguments are accepted but " + colType + " is passed for " + colName + ".";
    warning = "WARNING: " + warning;
    console.printInfo(warning);
    // Propagate warning to beeline via operation log.
    OperationLog ol = OperationLog.getCurrentOperationLog();
    if (ol != null) {
        ol.writeOperationLog(LoggingLevel.EXECUTION, warning + "\n");
    }
}
Also used : OperationLog(org.apache.hadoop.hive.ql.session.OperationLog)

Aggregations

OperationLog (org.apache.hadoop.hive.ql.session.OperationLog)8 HiveSQLException (org.apache.hive.service.cli.HiveSQLException)3 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 TableSchema (org.apache.hive.service.cli.TableSchema)2 OutputStream (java.io.OutputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 SQLException (java.sql.SQLException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Properties (java.util.Properties)1 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1 Path (org.apache.hadoop.fs.Path)1 CachingPrintStream (org.apache.hadoop.hive.common.io.CachingPrintStream)1 Schema (org.apache.hadoop.hive.metastore.api.Schema)1 CompilationOpContext (org.apache.hadoop.hive.ql.CompilationOpContext)1 Context (org.apache.hadoop.hive.ql.Context)1 DriverContext (org.apache.hadoop.hive.ql.DriverContext)1 SecureCmdDoAs (org.apache.hadoop.hive.ql.exec.SecureCmdDoAs)1