@Override public SessionHandle openSessionWithImpersonation(String username, String password, Map<String, String> configuration, String delegationToken) throws HiveSQLException { throw new HiveSQLException("Impersonated session is not supported in the embedded mode"); }
/** * Converts current object to a {@link TStatus} object * @return a {@link TStatus} object */ public TStatus toTStatus() { // TODO: convert sqlState, etc. TStatus tStatus = new TStatus(TStatusCode.ERROR_STATUS); tStatus.setSqlState(getSQLState()); tStatus.setErrorCode(getErrorCode()); tStatus.setErrorMessage(getMessage()); tStatus.setInfoMessages(toString(this)); return tStatus; }
@Override public TCancelOperationResp CancelOperation(TCancelOperationReq req) throws TException { TCancelOperationResp resp = new TCancelOperationResp(); try { cliService.cancelOperation(new OperationHandle(req.getOperationHandle())); resp.setStatus(OK_STATUS); } catch (Exception e) { LOG.warn("Error cancelling operation: ", e); resp.setStatus(HiveSQLException.toTStatus(e)); } return resp; }
private static List<String> toString(Throwable cause, StackTraceElement[] parent) { StackTraceElement[] trace = cause.getStackTrace(); int m = trace.length - 1; if (parent != null) { int n = parent.length - 1; while (m >= 0 && n >= 0 && trace[m].equals(parent[n])) { m--; n--; } } List<String> detail = enroll(cause, trace, m); cause = cause.getCause(); if (cause != null) { detail.addAll(toString(cause, trace)); } return detail; }
/** * Converts the specified {@link Exception} object into a {@link TStatus} object * @param e a {@link Exception} object * @return a {@link TStatus} object */ public static TStatus toTStatus(Exception e) { if (e instanceof HiveSQLException) { return ((HiveSQLException)e).toTStatus(); } TStatus tStatus = new TStatus(TStatusCode.ERROR_STATUS); tStatus.setErrorMessage(e.getMessage()); tStatus.setInfoMessages(toString(e)); return tStatus; }
)); 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())) { } catch (Exception e) { LOG.warn("Error getting operation status: ", e); resp.setStatus(HiveSQLException.toTStatus(e));
protected HiveSQLException toSQLException(String prefix, CommandProcessorResponse response) { HiveSQLException ex = new HiveSQLException(prefix + ": " + response.getErrorMessage(), response.getSQLState(), response.getResponseCode()); if (response.getException() != null) { ex.initCause(response.getException()); } return ex; }
@Override protected QueryStatus doFetchStatus(OperationHandle operationHandle) throws HiveSQLException, ExploreException, HandleNotFoundException { OperationStatus operationStatus = getCliService().getOperationStatus(operationHandle); @SuppressWarnings("ThrowableResultOfMethodCallIgnored") HiveSQLException hiveExn = operationStatus.getOperationException(); if (hiveExn != null) { return new QueryStatus(hiveExn.getMessage(), hiveExn.getSQLState()); } return new QueryStatus(QueryStatus.OpStatus.valueOf(operationStatus.getState().toString()), operationHandle.hasResultSet()); }
/** * Tests the conversion from a HiveSQLException exception to the TStatus object */ @Test public void testHiveSQLExceptionToTStatus() { String expectedMessage = "reason"; String expectedSqlState = "sqlState"; int expectedVendorCode = 10; Exception ex1 = new HiveSQLException(expectedMessage, expectedSqlState, expectedVendorCode, createSimpleCause()); TStatus status = HiveSQLException.toTStatus(ex1); Assert.assertEquals(TStatusCode.ERROR_STATUS, status.getStatusCode()); Assert.assertEquals(expectedSqlState, status.getSqlState()); Assert.assertEquals(expectedMessage, status.getErrorMessage()); Assert.assertEquals(HiveSQLException.toString(ex1), status.getInfoMessages()); }
public void testExceptionConversion() { Exception ex1 = createException(); ex1.initCause(createSimpleCause()); Throwable ex = HiveSQLException.toCause(HiveSQLException.toString(ex1)); Assert.assertSame(RuntimeException.class, ex.getClass()); Assert.assertEquals("exception1", ex.getMessage()); Assert.assertSame(UnsupportedOperationException.class, ex.getCause().getClass()); Assert.assertEquals("exception2", ex.getCause().getMessage()); } };
} else { throw new HiveSQLException("No privilege"); throw new HiveSQLException("No privilege"); throw new HiveException(e.getMessage(), e);
OperationState.ERROR, state); assertEquals(opStatus.getOperationException().getSQLState(), "08S01"); assertEquals(opStatus.getOperationException().getErrorCode(), 1);
@Test public void testRestore() throws HiveSQLException { SessionHandle session = service.openSession("foo", "bar", null); service.stop(); service = getService(); try { service.getSessionManager().getSession(session); Assert.fail("session already exists before restore"); } catch (HiveSQLException e) { Assert.assertTrue(e.getMessage().contains("Invalid SessionHandle")); } service.createSessionWithSessionHandle(session, "foo", "bar", null); Assert.assertNotNull(service.getSessionManager().getSession(session)); service.stop(); }
/** * Converts a {@link Throwable} object into a flattened list of texts including its stack trace * and the stack traces of the nested causes. * @param ex a {@link Throwable} object * @return a flattened list of texts including the {@link Throwable} object's stack trace * and the stack traces of the nested causes. */ public static List<String> toString(Throwable ex) { return toString(ex, null); }
fail("Expected to throw exception for invalid port"); } catch (HiveSQLException sqlExc) { assertTrue(sqlExc.getCause() instanceof TTransportException); assertTrue(sqlExc.getMessage().contains("3")); cliServiceClient.openSession("anonymous", "anonymous"); } catch (HiveSQLException exc) { exc.printStackTrace(); assertTrue(exc.getCause() instanceof TException); assertEquals(1, RetryingThriftCLIServiceClientTest.handlerInst.callCount); assertEquals(3, RetryingThriftCLIServiceClientTest.handlerInst.connectCount);
String exceptionClass = detail.substring(1, i1); String exceptionMessage = detail.substring(i1 + 1, i2); Throwable ex = newInstance(exceptionClass, exceptionMessage); ex.initCause(toStackTrace(details, trace, index));
/** * Checks if is session invalid. * * @param exc the exc * @param sessionHandle the session handle * @return true, if is session invalid */ protected boolean isSessionInvalid(HiveSQLException exc, SessionHandle sessionHandle) { if (exc.getMessage().contains("Invalid SessionHandle") && exc.getMessage().contains(sessionHandle.toString())) { return true; } // Check if there is underlying cause if (exc.getCause() instanceof HiveSQLException) { isSessionInvalid((HiveSQLException) exc.getCause(), sessionHandle); } return false; }
private RuntimeException getSqlException(HiveSQLException e) throws ExploreException, SQLException { if (e.getSQLState() != null) { throw e; } throw new ExploreException(e); } }
@Override public TGetOperationStatusResp GetOperationStatus(TGetOperationStatusReq req) throws TException { TGetOperationStatusResp resp = new TGetOperationStatusResp(); try { OperationStatus operationStatus = cliService.getOperationStatus( new OperationHandle(req.getOperationHandle())); resp.setOperationState(operationStatus.getState().toTOperationState()); HiveSQLException opException = operationStatus.getOperationException(); if (opException != null) { resp.setSqlState(opException.getSQLState()); resp.setErrorCode(opException.getErrorCode()); resp.setErrorMessage(opException.getMessage()); } resp.setStatus(OK_STATUS); } catch (Exception e) { LOG.warn("Error getting operation status: ", e); resp.setStatus(HiveSQLException.toTStatus(e)); } return resp; }