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;
}
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;
}
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);
}
}
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);
}
}
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);
}
}
Aggregations