Refine search
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; } }
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"); }
@Test public void testErrorCodes() { assertEquals(new PageTooLargeException().getErrorCode(), PAGE_TOO_LARGE.toErrorCode()); assertEquals(new PageTransportErrorException("").getErrorCode(), PAGE_TRANSPORT_ERROR.toErrorCode()); assertEquals(new PageTransportTimeoutException(HostAddress.fromParts("127.0.0.1", 8080), "", null).getErrorCode(), PAGE_TRANSPORT_TIMEOUT.toErrorCode()); }
public static void assertInvalidPath(String path) { try { tokenizePath(path); fail("Expected PrestoException"); } catch (PrestoException e) { assertEquals(e.getErrorCode(), INVALID_FUNCTION_ARGUMENT.toErrorCode()); } }
assertEquals(failure.getMessage(), "fake exception 1"); assertNull(failure.getCause()); assertEquals(failure.getSuppressed().size(), 1); assertEquals(failure.getSuppressed().get(0).getMessage(), "fake exception 2"); assertEquals(failure.getErrorCode(), TOO_MANY_REQUESTS_FAILED.toErrorCode()); assertEquals(failure.getCause().getMessage(), "fake exception 1"); assertEquals(failure.getSuppressed().size(), 0); assertEquals(failure.getErrorCode(), TOO_MANY_REQUESTS_FAILED.toErrorCode()); assertEquals(failure.getSuppressed().size(), 1); assertEquals(failure.getSuppressed().get(0).getMessage(), "fake exception 2"); assertEquals(failure.getErrorCode(), TOO_MANY_REQUESTS_FAILED.toErrorCode()); assertEquals(failure.getCause().getMessage(), "fake exception 1"); assertEquals(failure.getSuppressed().size(), 0); assertEquals(failure.getErrorCode(), GENERIC_INTERNAL_ERROR.toErrorCode());
@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; }
@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()); } }
private void waitForQueryToBeKilled(DistributedQueryRunner queryRunner) throws InterruptedException { while (true) { for (BasicQueryInfo info : queryRunner.getCoordinator().getQueryManager().getQueries()) { if (info.getState().isDone()) { assertNotNull(info.getErrorCode()); assertEquals(info.getErrorCode().getCode(), CLUSTER_OUT_OF_MEMORY.toErrorCode().getCode()); return; } } MILLISECONDS.sleep(10); } }
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; } }
@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"); } }
@Test(timeOut = 60_000L) public void testQueryCpuLimit() throws Exception { try (DistributedQueryRunner queryRunner = builder().setSingleExtraProperty("query.max-cpu-time", "1ms").build()) { QueryId queryId = createQuery(queryRunner, TEST_SESSION, "SELECT COUNT(*) FROM lineitem"); waitForQueryState(queryRunner, queryId, FAILED); QueryManager queryManager = queryRunner.getCoordinator().getQueryManager(); BasicQueryInfo queryInfo = queryManager.getQueryInfo(queryId); assertEquals(queryInfo.getState(), FAILED); assertEquals(queryInfo.getErrorCode(), EXCEEDED_CPU_LIMIT.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; }
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; } } }
@Test(timeOut = 60_000L) public void testFailQuery() throws Exception { QueryManager queryManager = queryRunner.getCoordinator().getQueryManager(); QueryId queryId = queryManager.createQueryId(); queryManager.createQuery( queryId, new TestingSessionContext(TEST_SESSION), "SELECT * FROM lineitem") .get(); // wait until query starts running while (true) { QueryState state = queryManager.getQueryState(queryId); if (state.isDone()) { fail("unexpected query state: " + state); } if (state == RUNNING) { break; } Thread.sleep(100); } // cancel query queryManager.failQuery(queryId, new PrestoException(GENERIC_INTERNAL_ERROR, "mock exception")); QueryInfo queryInfo = queryManager.getFullQueryInfo(queryId); assertEquals(queryInfo.getState(), FAILED); assertEquals(queryInfo.getErrorCode(), GENERIC_INTERNAL_ERROR.toErrorCode()); assertNotNull(queryInfo.getFailureInfo()); assertEquals(queryInfo.getFailureInfo().getMessage(), "mock exception"); }
public static Signature resolveFunction(FunctionCall node, List<TypeSignatureProvider> argumentTypes, FunctionRegistry functionRegistry) { try { return functionRegistry.resolveFunction(node.getName(), argumentTypes); } catch (PrestoException e) { if (e.getErrorCode().getCode() == StandardErrorCode.FUNCTION_NOT_FOUND.toErrorCode().getCode()) { throw new SemanticException(SemanticErrorCode.FUNCTION_NOT_FOUND, node, e.getMessage()); } if (e.getErrorCode().getCode() == StandardErrorCode.AMBIGUOUS_FUNCTION_CALL.toErrorCode().getCode()) { throw new SemanticException(SemanticErrorCode.AMBIGUOUS_FUNCTION_CALL, node, e.getMessage()); } throw e; } }
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 void testRejection() throws Exception { try (DistributedQueryRunner queryRunner = createQueryRunner()) { queryRunner.installPlugin(new ResourceGroupManagerPlugin()); queryRunner.getCoordinator().getResourceGroupManager().get().setConfigurationManager("file", ImmutableMap.of("resource-groups.config-file", getResourceFilePath("resource_groups_config_dashboard.json"))); QueryId queryId = createQuery(queryRunner, newRejectionSession(), LONG_LASTING_QUERY); waitForQueryState(queryRunner, queryId, FAILED); QueryManager queryManager = queryRunner.getCoordinator().getQueryManager(); assertEquals(queryManager.getQueryInfo(queryId).getErrorCode(), QUERY_REJECTED.toErrorCode()); } }
public Signature resolveOperator(OperatorType operatorType, List<? extends Type> argumentTypes) throws OperatorNotFoundException { try { return resolveFunction(QualifiedName.of(mangleOperatorName(operatorType)), fromTypes(argumentTypes)); } catch (PrestoException e) { if (e.getErrorCode().getCode() == FUNCTION_NOT_FOUND.toErrorCode().getCode()) { throw new OperatorNotFoundException( operatorType, argumentTypes.stream() .map(Type::getTypeSignature) .collect(toImmutableList())); } else { throw e; } } }
@Test public void testCreateTableInNotExistSchema() { SchemaTableName schemaTableName = new SchemaTableName("schema1", "test_table"); try { metadata.beginCreateTable(SESSION, new ConnectorTableMetadata(schemaTableName, ImmutableList.of(), tableProperties), Optional.empty()); fail("Should fail because schema does not exist"); } catch (PrestoException ex) { assertEquals(ex.getErrorCode(), NOT_FOUND.toErrorCode()); assertTrue(ex.getMessage().equals("Schema schema1 not found")); } }
Optional.empty(), null, StandardErrorCode.ABANDONED_QUERY.toErrorCode(), ImmutableList.of(), ImmutableSet.of(), Optional.empty())); assertEquals(basicInfo.getQueryId().getId(), "0"); assertEquals(basicInfo.getState(), RUNNING); assertEquals(basicInfo.getMemoryPool().getId(), "reserved"); assertEquals(basicInfo.isScheduled(), false); assertEquals(basicInfo.getQuery(), "SELECT 4"); assertEquals(basicInfo.getQueryStats().getProgressPercentage(), OptionalDouble.of(100)); assertEquals(basicInfo.getErrorCode(), StandardErrorCode.ABANDONED_QUERY.toErrorCode()); assertEquals(basicInfo.getErrorType(), StandardErrorCode.ABANDONED_QUERY.toErrorCode().getType());