use of com.facebook.presto.client.QueryError in project presto by prestodb.
the class BenchmarkQueryRunner method getSchemas.
public List<String> getSchemas(ClientSession session) {
failures = 0;
while (true) {
// start query
StatementClient client = new StatementClient(httpClient, queryResultsCodec, session, "show schemas");
// read query output
ImmutableList.Builder<String> schemas = ImmutableList.builder();
while (client.isValid() && client.advance()) {
// we do not process the output
Iterable<List<Object>> data = client.current().getData();
if (data != null) {
for (List<Object> objects : data) {
schemas.add(objects.get(0).toString());
}
}
}
// verify final state
if (client.isClosed()) {
throw new IllegalStateException("Query aborted by user");
}
if (client.isGone()) {
throw new IllegalStateException("Query is gone (server restarted?)");
}
QueryError resultsError = client.finalResults().getError();
if (resultsError != null) {
RuntimeException cause = null;
if (resultsError.getFailureInfo() != null) {
cause = resultsError.getFailureInfo().toException();
}
handleFailure(cause);
continue;
}
return schemas.build();
}
}
use of com.facebook.presto.client.QueryError in project presto by prestodb.
the class TestServer method testInvalidSessionError.
@Test
public void testInvalidSessionError() throws Exception {
String invalidTimeZone = "this_is_an_invalid_time_zone";
Request request = preparePost().setHeader(PRESTO_USER, "user").setUri(uriFor("/v1/statement")).setBodyGenerator(createStaticBodyGenerator("show catalogs", UTF_8)).setHeader(PRESTO_SOURCE, "source").setHeader(PRESTO_CATALOG, "catalog").setHeader(PRESTO_SCHEMA, "schema").setHeader(PRESTO_TIME_ZONE, invalidTimeZone).build();
QueryResults queryResults = client.execute(request, createJsonResponseHandler(jsonCodec(QueryResults.class)));
QueryError queryError = queryResults.getError();
assertNotNull(queryError);
TimeZoneNotSupportedException expected = new TimeZoneNotSupportedException(invalidTimeZone);
assertEquals(queryError.getErrorCode(), expected.getErrorCode().getCode());
assertEquals(queryError.getErrorName(), expected.getErrorCode().getName());
assertEquals(queryError.getErrorType(), expected.getErrorCode().getType().name());
assertEquals(queryError.getMessage(), expected.getMessage());
}
use of com.facebook.presto.client.QueryError in project presto by prestodb.
the class AbstractTestingPrestoClient method execute.
public T execute(Session session, @Language("SQL") String sql) {
ResultsSession<T> resultsSession = getResultSession(session);
ClientSession clientSession = toClientSession(session, prestoServer.getBaseUrl(), true, new Duration(2, TimeUnit.MINUTES));
try (StatementClient client = new StatementClient(httpClient, QUERY_RESULTS_CODEC, clientSession, sql)) {
while (client.isValid()) {
QueryResults results = client.current();
resultsSession.addResults(results);
client.advance();
}
if (!client.isFailed()) {
QueryResults results = client.finalResults();
if (results.getUpdateType() != null) {
resultsSession.setUpdateType(results.getUpdateType());
}
if (results.getUpdateCount() != null) {
resultsSession.setUpdateCount(results.getUpdateCount());
}
return resultsSession.build(client.getSetSessionProperties(), client.getResetSessionProperties());
}
QueryError error = client.finalResults().getError();
verify(error != null, "no error");
if (error.getFailureInfo() != null) {
throw error.getFailureInfo().toException();
}
throw new RuntimeException("Query failed: " + error.getMessage());
// dump query info to console for debugging (NOTE: not pretty printed)
// JsonCodec<QueryInfo> queryInfoJsonCodec = createCodecFactory().prettyPrint().jsonCodec(QueryInfo.class);
// log.info("\n" + queryInfoJsonCodec.toJson(queryInfo));
}
}
use of com.facebook.presto.client.QueryError in project airpal by airbnb.
the class ExecutionClient method runQuery.
public UUID runQuery(final String query, final String tmpTable, final AirpalUser user, final String schema, final Duration timeout) {
final UUID uuid = UUID.randomUUID();
final Job job = new Job(user.getUserName(), query, uuid, persistentJobOutputFactory.create(tmpTable, uuid), null, JobState.QUEUED, Collections.<Column>emptyList(), null, null);
final Execution execution = new Execution(job, eventBus, queryRunnerFactory.create(user.getUserName(), schema), queryInfoClient, new QueryExecutionAuthorizer(user, "hive", user.getDefaultSchema()), timeout, columnCache, outputBuilderFactory, persistorFactory);
executionMap.put(uuid, execution);
activeJobsStore.jobStarted(job);
ListenableFuture<Job> result = executor.submit(execution);
Futures.addCallback(result, new FutureCallback<Job>() {
@Override
public void onSuccess(@Nullable Job result) {
if (result != null) {
result.setState(JobState.FINISHED);
}
jobFinished(result);
}
@Override
public void onFailure(@NotNull Throwable t) {
if (t instanceof ExecutionFailureException) {
ExecutionFailureException e = (ExecutionFailureException) t;
Job j = e.getJob();
j.setState(JobState.FAILED);
if (j.getError() == null) {
j.setError(new QueryError(e.getMessage(), null, -1, null, null, null, null));
}
jobFinished(j);
}
}
});
return uuid;
}
Aggregations