@Nullable private static ErrorCode toErrorCode(Throwable throwable) { requireNonNull(throwable); if (throwable instanceof PrestoException) { return ((PrestoException) throwable).getErrorCode(); } if (throwable instanceof Failure && ((Failure) throwable).getErrorCode() != null) { return ((Failure) throwable).getErrorCode(); } if (throwable instanceof ParsingException || throwable instanceof SemanticException) { return SYNTAX_ERROR.toErrorCode(); } return null; }
private void assertDriverInterrupted(Throwable cause) { checkArgument(cause instanceof PrestoException, "Expected root cause exception to be an instance of PrestoException"); assertEquals(((PrestoException) cause).getErrorCode(), GENERIC_INTERNAL_ERROR.toErrorCode()); assertEquals(cause.getMessage(), "Driver was interrupted"); }
public static void assertInvalidPath(String path) { try { tokenizePath(path); fail("Expected PrestoException"); } catch (PrestoException e) { assertEquals(e.getErrorCode(), INVALID_FUNCTION_ARGUMENT.toErrorCode()); } }
public void assertInvalidFunction(String projection, ErrorCode errorCode) { try { assertFunction(projection, UNKNOWN, null); fail("Expected error " + errorCode + " from " + projection); } catch (PrestoException e) { assertEquals(e.getErrorCode(), errorCode); } }
private void testInvalidAggregation(Double[] x, int n) { try { testAggregation(new long[] {}, createDoublesBlock(x), createLongRepeatBlock(n, x.length)); } catch (PrestoException e) { assertEquals(e.getErrorCode().getName(), INVALID_FUNCTION_ARGUMENT.name()); } }
@Test public void testExecuteStatementDoesNotExist() { try { QUERY_PREPARER.prepareQuery(TEST_SESSION, "execute my_query"); fail("expected exception"); } catch (PrestoException e) { assertEquals(e.getErrorCode(), NOT_FOUND.toErrorCode()); } }
@Test(timeOut = 60_000) public void testTimeout() { try { queryRunner.execute("SELECT * FROM disks"); fail(); } catch (PrestoException e) { assertEquals(e.getErrorCode(), ATOP_READ_TIMEOUT.toErrorCode(), e.getMessage()); } }
private void testInvalidAggregation(Long[] x, int n) { try { testAggregation(null, createLongArraysBlock(x), createLongRepeatBlock(n, x.length)); } catch (PrestoException e) { assertEquals(e.getErrorCode().getName(), INVALID_FUNCTION_ARGUMENT.name()); } }
private static void assertInvalidExtract(String inputJson, String jsonPath, String message) { try { doJsonExtract(inputJson, jsonPath); } catch (PrestoException e) { assertEquals(e.getErrorCode(), INVALID_FUNCTION_ARGUMENT.toErrorCode()); assertEquals(e.getMessage(), message); } } }
private static void propagateIfUnhandled(PrestoException e) throws PrestoException { int errorCode = e.getErrorCode().getCode(); if (errorCode == DIVISION_BY_ZERO.toErrorCode().getCode() || errorCode == INVALID_CAST_ARGUMENT.toErrorCode().getCode() || errorCode == INVALID_FUNCTION_ARGUMENT.toErrorCode().getCode() || errorCode == NUMERIC_VALUE_OUT_OF_RANGE.toErrorCode().getCode()) { return; } throw e; } }
@Test public void testDeallocateNoSuchStatement() { try { executeDeallocate("my_query", "DEALLOCATE PREPARE my_query", TEST_SESSION); fail("expected exception"); } catch (PrestoException e) { assertEquals(e.getErrorCode(), NOT_FOUND.toErrorCode()); assertEquals(e.getMessage(), "Prepared statement not found: my_query"); } }
private void assertFails(@Language("SQL") String sql, ErrorCodeSupplier supplier) { try { runner.execute(sql); fail("expected exception"); } catch (PrestoException e) { assertEquals(e.getErrorCode(), supplier.toErrorCode()); } } }
private void testInvalidAggregation(Long[] x, int n) { try { testAggregation(new long[] {}, createLongsBlock(x), createLongRepeatBlock(n, x.length)); } catch (PrestoException e) { assertEquals(e.getErrorCode().getName(), INVALID_FUNCTION_ARGUMENT.name()); } }
@Test public void testInvalidBinaryLength() { try { byte[] invalidLengthBinaryTimestamp = new byte[8]; getTimestampMillis(Binary.fromByteArray(invalidLengthBinaryTimestamp)); } catch (PrestoException e) { assertEquals(e.getErrorCode(), NOT_SUPPORTED.toErrorCode()); assertEquals(e.getMessage(), "Parquet timestamp must be 12 bytes, actual 8"); } }
public boolean isRegistered(Signature signature) { try { // TODO: this is hacky, but until the magic literal and row field reference hacks are cleaned up it's difficult to implement this. getScalarFunctionImplementation(signature); return true; } catch (PrestoException e) { if (e.getErrorCode().getCode() == FUNCTION_IMPLEMENTATION_MISSING.toErrorCode().getCode()) { return false; } throw e; } }
public void assertInvalidCast(String projection) { try { evaluateInvalid(projection); fail("Expected to throw an INVALID_CAST_ARGUMENT exception"); } catch (PrestoException e) { try { assertEquals(e.getErrorCode(), INVALID_CAST_ARGUMENT.toErrorCode()); } catch (Throwable failure) { failure.addSuppressed(e); throw failure; } } }
public void assertInvalidFunction(String projection, ErrorCodeSupplier expectedErrorCode) { try { evaluateInvalid(projection); fail(format("Expected to throw %s exception", expectedErrorCode.toErrorCode())); } catch (PrestoException e) { try { assertEquals(e.getErrorCode(), expectedErrorCode.toErrorCode()); } catch (Throwable failure) { failure.addSuppressed(e); throw failure; } } }
@Test public void testInvalidBinaryLength() { try { byte[] invalidLengthBinaryTimestamp = new byte[8]; getTimestampMillis(Binary.fromByteArray(invalidLengthBinaryTimestamp)); } catch (PrestoException e) { assertEquals(e.getErrorCode(), HIVE_BAD_DATA.toErrorCode()); assertEquals(e.getMessage(), "Parquet timestamp must be 12 bytes, actual 8"); } }
private static void assertState(QueryStateMachine stateMachine, QueryState expectedState, Exception expectedException) assertEquals(stateMachine.getQueryId(), TEST_SESSION.getQueryId()); assertEqualSessionsWithoutTransactionId(stateMachine.getSession(), TEST_SESSION); assertSame(stateMachine.getMemoryPool(), MEMORY_POOL); assertEquals(stateMachine.getSetSessionProperties(), SET_SESSION_PROPERTIES); assertEquals(stateMachine.getResetSessionProperties(), RESET_SESSION_PROPERTIES); assertEquals(failure.getType(), expectedException.getClass().getName()); if (expectedException instanceof PrestoException) { assertEquals(queryInfo.getErrorCode(), ((PrestoException) expectedException).getErrorCode()); assertEquals(queryInfo.getErrorCode(), GENERIC_INTERNAL_ERROR.toErrorCode());
public Signature getCoercion(TypeSignature fromType, TypeSignature toType) { Signature signature = internalOperator(OperatorType.CAST.name(), toType, ImmutableList.of(fromType)); try { getScalarFunctionImplementation(signature); } catch (PrestoException e) { if (e.getErrorCode().getCode() == FUNCTION_IMPLEMENTATION_MISSING.toErrorCode().getCode()) { throw new OperatorNotFoundException(OperatorType.CAST, ImmutableList.of(fromType), toType); } throw e; } return signature; }