Search in sources :

Example 31 with HiveSQLException

use of org.apache.hive.service.cli.HiveSQLException in project hive by apache.

the class HiveSessionImpl method getFunctions.

@Override
public OperationHandle getFunctions(String catalogName, String schemaName, String functionName) throws HiveSQLException {
    acquire(true, true);
    OperationManager operationManager = getOperationManager();
    GetFunctionsOperation operation = operationManager.newGetFunctionsOperation(getSession(), catalogName, schemaName, functionName);
    OperationHandle opHandle = operation.getHandle();
    try {
        operation.run();
        addOpHandle(opHandle);
        return opHandle;
    } catch (HiveSQLException e) {
        operationManager.closeOperation(opHandle);
        throw e;
    } finally {
        release(true, true);
    }
}
Also used : HiveSQLException(org.apache.hive.service.cli.HiveSQLException) GetFunctionsOperation(org.apache.hive.service.cli.operation.GetFunctionsOperation) OperationManager(org.apache.hive.service.cli.operation.OperationManager) OperationHandle(org.apache.hive.service.cli.OperationHandle)

Example 32 with HiveSQLException

use of org.apache.hive.service.cli.HiveSQLException in project hive by apache.

the class HiveSessionImplwithUGI method close.

/**
   * Close the file systems for the session and remove it from the FileSystem cache.
   * Cancel the session's delegation token and close the metastore connection
   */
@Override
public void close() throws HiveSQLException {
    try {
        acquire(true, false);
        cancelDelegationToken();
    } finally {
        release(true, false);
        try {
            super.close();
        } finally {
            try {
                FileSystem.closeAllForUGI(sessionUgi);
            } catch (IOException ioe) {
                throw new HiveSQLException("Could not clean up file-system handles for UGI: " + sessionUgi, ioe);
            }
        }
    }
}
Also used : HiveSQLException(org.apache.hive.service.cli.HiveSQLException) IOException(java.io.IOException)

Example 33 with HiveSQLException

use of org.apache.hive.service.cli.HiveSQLException in project hive by apache.

the class SessionManager method createSession.

public HiveSession createSession(SessionHandle sessionHandle, TProtocolVersion protocol, String username, String password, String ipAddress, Map<String, String> sessionConf, boolean withImpersonation, String delegationToken) throws HiveSQLException {
    HiveSession session;
    // Within the proxy object, we wrap the method call in a UserGroupInformation#doAs
    if (withImpersonation) {
        HiveSessionImplwithUGI hiveSessionUgi;
        if (sessionImplWithUGIclassName == null) {
            hiveSessionUgi = new HiveSessionImplwithUGI(sessionHandle, protocol, username, password, hiveConf, ipAddress, delegationToken);
        } else {
            try {
                Class<?> clazz = Class.forName(sessionImplWithUGIclassName);
                Constructor<?> constructor = clazz.getConstructor(SessionHandle.class, TProtocolVersion.class, String.class, String.class, HiveConf.class, String.class, String.class);
                hiveSessionUgi = (HiveSessionImplwithUGI) constructor.newInstance(sessionHandle, protocol, username, password, hiveConf, ipAddress, delegationToken);
            } catch (Exception e) {
                throw new HiveSQLException("Cannot initilize session class:" + sessionImplWithUGIclassName);
            }
        }
        session = HiveSessionProxy.getProxy(hiveSessionUgi, hiveSessionUgi.getSessionUgi());
        hiveSessionUgi.setProxySession(session);
    } else {
        if (sessionImplclassName == null) {
            session = new HiveSessionImpl(sessionHandle, protocol, username, password, hiveConf, ipAddress);
        } else {
            try {
                Class<?> clazz = Class.forName(sessionImplclassName);
                Constructor<?> constructor = clazz.getConstructor(SessionHandle.class, TProtocolVersion.class, String.class, String.class, HiveConf.class, String.class);
                session = (HiveSession) constructor.newInstance(sessionHandle, protocol, username, password, hiveConf, ipAddress);
            } catch (Exception e) {
                throw new HiveSQLException("Cannot initilize session class:" + sessionImplclassName, e);
            }
        }
    }
    session.setSessionManager(this);
    session.setOperationManager(operationManager);
    try {
        session.open(sessionConf);
    } catch (Exception e) {
        LOG.warn("Failed to open session", e);
        try {
            session.close();
        } catch (Throwable t) {
            LOG.warn("Error closing session", t);
        }
        session = null;
        throw new HiveSQLException("Failed to open new session: " + e.getMessage(), e);
    }
    if (isOperationLogEnabled) {
        session.setOperationLogSessionDir(operationLogRootDir);
    }
    try {
        executeSessionHooks(session);
    } catch (Exception e) {
        LOG.warn("Failed to execute session hooks", e);
        try {
            session.close();
        } catch (Throwable t) {
            LOG.warn("Error closing session", t);
        }
        session = null;
        throw new HiveSQLException("Failed to execute session hooks: " + e.getMessage(), e);
    }
    handleToSession.put(session.getSessionHandle(), session);
    LOG.info("Session opened, " + session.getSessionHandle() + ", current sessions:" + getOpenSessionCount());
    return session;
}
Also used : HiveSQLException(org.apache.hive.service.cli.HiveSQLException) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) IOException(java.io.IOException)

Example 34 with HiveSQLException

use of org.apache.hive.service.cli.HiveSQLException in project hive by apache.

the class OperationManager method closeOperation.

public void closeOperation(OperationHandle opHandle) throws HiveSQLException {
    LOG.info("Closing operation: " + opHandle);
    Operation operation = removeOperation(opHandle);
    if (operation == null) {
        throw new HiveSQLException("Operation does not exist: " + opHandle);
    }
    Metrics metrics = MetricsFactory.getInstance();
    if (metrics != null) {
        try {
            metrics.decrementCounter(MetricsConstant.OPEN_OPERATIONS);
        } catch (Exception e) {
            LOG.warn("Error Reporting close operation to Metrics system", e);
        }
    }
    operation.close();
}
Also used : Metrics(org.apache.hadoop.hive.common.metrics.common.Metrics) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) SQLException(java.sql.SQLException) HiveSQLException(org.apache.hive.service.cli.HiveSQLException)

Example 35 with HiveSQLException

use of org.apache.hive.service.cli.HiveSQLException 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)

Aggregations

HiveSQLException (org.apache.hive.service.cli.HiveSQLException)83 OperationHandle (org.apache.hive.service.cli.OperationHandle)38 TException (org.apache.thrift.TException)25 SessionHandle (org.apache.hive.service.cli.SessionHandle)20 ExploreException (co.cask.cdap.explore.service.ExploreException)14 IOException (java.io.IOException)12 QueryHandle (co.cask.cdap.proto.QueryHandle)11 TProtocolVersion (org.apache.hive.service.rpc.thrift.TProtocolVersion)11 OperationManager (org.apache.hive.service.cli.operation.OperationManager)10 QueryStatus (co.cask.cdap.proto.QueryStatus)7 IMetaStoreClient (org.apache.hadoop.hive.metastore.IMetaStoreClient)7 SQLException (java.sql.SQLException)6 OperationStatus (org.apache.hive.service.cli.OperationStatus)5 TableSchema (org.apache.hive.service.cli.TableSchema)5 FileNotFoundException (java.io.FileNotFoundException)4 ArrayList (java.util.ArrayList)4 Metrics (org.apache.hadoop.hive.common.metrics.common.Metrics)3 HivePrivilegeObject (org.apache.hadoop.hive.ql.security.authorization.plugin.HivePrivilegeObject)3 NamespaceNotFoundException (co.cask.cdap.common.NamespaceNotFoundException)2 HandleNotFoundException (co.cask.cdap.explore.service.HandleNotFoundException)2