Search in sources :

Example 41 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 {
    // if client proxies connection, use forwarded ip-addresses instead of just the gateway
    final List<String> forwardedAddresses = getForwardedAddresses();
    incrementConnections(username, ipAddress, forwardedAddresses);
    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, forwardedAddresses);
        } 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, List.class);
                hiveSessionUgi = (HiveSessionImplwithUGI) constructor.newInstance(sessionHandle, protocol, username, password, hiveConf, ipAddress, delegationToken, forwardedAddresses);
            } catch (Exception e) {
                throw new HiveSQLException("Cannot initialize 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, forwardedAddresses);
        } else {
            try {
                Class<?> clazz = Class.forName(sessionImplclassName);
                Constructor<?> constructor = clazz.getConstructor(SessionHandle.class, TProtocolVersion.class, String.class, String.class, HiveConf.class, String.class, List.class);
                session = (HiveSession) constructor.newInstance(sessionHandle, protocol, username, password, hiveConf, ipAddress, forwardedAddresses);
            } catch (Exception e) {
                throw new HiveSQLException("Cannot initialize 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 42 with HiveSQLException

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

the class ThriftCLIService method GetOperationStatus.

@Override
public TGetOperationStatusResp GetOperationStatus(TGetOperationStatusReq req) throws TException {
    TGetOperationStatusResp resp = new TGetOperationStatusResp();
    OperationHandle operationHandle = new OperationHandle(req.getOperationHandle());
    try {
        OperationStatus operationStatus = cliService.getOperationStatus(operationHandle, req.isGetProgressUpdate());
        resp.setOperationState(operationStatus.getState().toTOperationState());
        resp.setErrorMessage(operationStatus.getState().getErrorMessage());
        HiveSQLException opException = operationStatus.getOperationException();
        resp.setTaskStatus(operationStatus.getTaskStatus());
        resp.setOperationStarted(operationStatus.getOperationStarted());
        resp.setOperationCompleted(operationStatus.getOperationCompleted());
        resp.setHasResultSet(operationStatus.getHasResultSet());
        JobProgressUpdate progressUpdate = operationStatus.jobProgressUpdate();
        ProgressMonitorStatusMapper mapper = ProgressMonitorStatusMapper.DEFAULT;
        if ("tez".equals(hiveConf.getVar(ConfVars.HIVE_EXECUTION_ENGINE))) {
            mapper = new TezProgressMonitorStatusMapper();
        }
        TJobExecutionStatus executionStatus = mapper.forStatus(progressUpdate.status);
        resp.setProgressUpdateResponse(new TProgressUpdateResp(progressUpdate.headers(), progressUpdate.rows(), progressUpdate.progressedPercentage, executionStatus, progressUpdate.footerSummary, progressUpdate.startTimeMillis));
        if (opException != null) {
            resp.setSqlState(opException.getSQLState());
            resp.setErrorCode(opException.getErrorCode());
            if (opException.getErrorCode() == 29999)
                resp.setErrorMessage(org.apache.hadoop.util.StringUtils.stringifyException(opException));
            else
                resp.setErrorMessage(opException.getMessage());
        } else if (executionStatus == TJobExecutionStatus.NOT_AVAILABLE && OperationType.EXECUTE_STATEMENT.equals(operationHandle.getOperationType())) {
            resp.getProgressUpdateResponse().setProgressedPercentage(getProgressedPercentage(operationHandle));
        }
        resp.setStatus(OK_STATUS);
    } catch (Exception e) {
        LOG.warn("Error getting operation status: ", e);
        resp.setStatus(HiveSQLException.toTStatus(e));
    }
    return resp;
}
Also used : TJobExecutionStatus(org.apache.hive.service.rpc.thrift.TJobExecutionStatus) JobProgressUpdate(org.apache.hive.service.cli.JobProgressUpdate) TezProgressMonitorStatusMapper(org.apache.hive.service.cli.TezProgressMonitorStatusMapper) TGetOperationStatusResp(org.apache.hive.service.rpc.thrift.TGetOperationStatusResp) OperationStatus(org.apache.hive.service.cli.OperationStatus) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) TezProgressMonitorStatusMapper(org.apache.hive.service.cli.TezProgressMonitorStatusMapper) ProgressMonitorStatusMapper(org.apache.hive.service.cli.ProgressMonitorStatusMapper) TProgressUpdateResp(org.apache.hive.service.rpc.thrift.TProgressUpdateResp) OperationHandle(org.apache.hive.service.cli.OperationHandle) LoginException(javax.security.auth.login.LoginException) ServiceException(org.apache.hive.service.ServiceException) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) TException(org.apache.thrift.TException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 43 with HiveSQLException

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

the class ThriftCLIServiceClient method setApplicationName.

@Override
public void setApplicationName(SessionHandle sh, String value) throws HiveSQLException {
    try {
        TSetClientInfoReq req = new TSetClientInfoReq(sh.toTSessionHandle());
        req.putToConfiguration("ApplicationName", value);
        TSetClientInfoResp resp = cliService.SetClientInfo(req);
        checkStatus(resp.getStatus());
    } catch (TException e) {
        throw new HiveSQLException(e);
    }
}
Also used : TException(org.apache.thrift.TException) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) TSetClientInfoResp(org.apache.hive.service.rpc.thrift.TSetClientInfoResp) TSetClientInfoReq(org.apache.hive.service.rpc.thrift.TSetClientInfoReq)

Example 44 with HiveSQLException

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

the class ThriftCLIServiceClient method executeStatementInternal.

private OperationHandle executeStatementInternal(SessionHandle sessionHandle, String statement, Map<String, String> confOverlay, boolean isAsync, long queryTimeout) throws HiveSQLException {
    try {
        TExecuteStatementReq req = new TExecuteStatementReq(sessionHandle.toTSessionHandle(), statement);
        req.setConfOverlay(confOverlay);
        req.setRunAsync(isAsync);
        req.setQueryTimeout(queryTimeout);
        TExecuteStatementResp resp = cliService.ExecuteStatement(req);
        checkStatus(resp.getStatus());
        TProtocolVersion protocol = sessionHandle.getProtocolVersion();
        return new OperationHandle(resp.getOperationHandle(), protocol);
    } catch (HiveSQLException e) {
        throw e;
    } catch (Exception e) {
        throw new HiveSQLException(e);
    }
}
Also used : TProtocolVersion(org.apache.hive.service.rpc.thrift.TProtocolVersion) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) TExecuteStatementReq(org.apache.hive.service.rpc.thrift.TExecuteStatementReq) TOperationHandle(org.apache.hive.service.rpc.thrift.TOperationHandle) OperationHandle(org.apache.hive.service.cli.OperationHandle) TExecuteStatementResp(org.apache.hive.service.rpc.thrift.TExecuteStatementResp) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) TException(org.apache.thrift.TException)

Example 45 with HiveSQLException

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

the class ThriftCLIServiceClient method getOperationStatus.

/* (non-Javadoc)
   * @see org.apache.hive.service.cli.ICLIService#getOperationStatus(org.apache.hive.service.cli.OperationHandle)
   */
@Override
public OperationStatus getOperationStatus(OperationHandle opHandle, boolean getProgressUpdate) throws HiveSQLException {
    try {
        TGetOperationStatusReq req = new TGetOperationStatusReq(opHandle.toTOperationHandle());
        req.setGetProgressUpdate(getProgressUpdate);
        TGetOperationStatusResp resp = cliService.GetOperationStatus(req);
        // Checks the status of the RPC call, throws an exception in case of error
        checkStatus(resp.getStatus());
        OperationState opState = OperationState.getOperationState(resp.getOperationState());
        HiveSQLException opException = null;
        if (opState == OperationState.ERROR) {
            opException = new HiveSQLException(resp.getErrorMessage(), resp.getSqlState(), resp.getErrorCode());
        }
        return new OperationStatus(opState, resp.getTaskStatus(), resp.getOperationStarted(), resp.getOperationCompleted(), resp.isHasResultSet(), opException);
    } catch (HiveSQLException e) {
        throw e;
    } catch (Exception e) {
        throw new HiveSQLException(e);
    }
}
Also used : TGetOperationStatusResp(org.apache.hive.service.rpc.thrift.TGetOperationStatusResp) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) OperationStatus(org.apache.hive.service.cli.OperationStatus) TGetOperationStatusReq(org.apache.hive.service.rpc.thrift.TGetOperationStatusReq) OperationState(org.apache.hive.service.cli.OperationState) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) TException(org.apache.thrift.TException)

Aggregations

HiveSQLException (org.apache.hive.service.cli.HiveSQLException)88 OperationHandle (org.apache.hive.service.cli.OperationHandle)39 TException (org.apache.thrift.TException)26 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 TOperationHandle (org.apache.hive.service.rpc.thrift.TOperationHandle)10 QueryStatus (co.cask.cdap.proto.QueryStatus)7 SQLException (java.sql.SQLException)7 IMetaStoreClient (org.apache.hadoop.hive.metastore.IMetaStoreClient)7 OperationStatus (org.apache.hive.service.cli.OperationStatus)5 TableSchema (org.apache.hive.service.cli.TableSchema)5 Test (org.junit.Test)5 FileNotFoundException (java.io.FileNotFoundException)4 ArrayList (java.util.ArrayList)4 Metrics (org.apache.hadoop.hive.common.metrics.common.Metrics)3 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)3