Search in sources :

Example 6 with QueryError

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();
    }
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) StatementClient(com.facebook.presto.client.StatementClient) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) QueryError(com.facebook.presto.client.QueryError)

Example 7 with QueryError

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());
}
Also used : Request(io.airlift.http.client.Request) QueryError(com.facebook.presto.client.QueryError) TimeZoneNotSupportedException(com.facebook.presto.spi.type.TimeZoneNotSupportedException) QueryResults(com.facebook.presto.client.QueryResults) Test(org.testng.annotations.Test)

Example 8 with QueryError

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));
    }
}
Also used : ClientSession(com.facebook.presto.client.ClientSession) StatementClient(com.facebook.presto.client.StatementClient) Duration(io.airlift.units.Duration) QueryError(com.facebook.presto.client.QueryError) QueryResults(com.facebook.presto.client.QueryResults)

Example 9 with QueryError

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;
}
Also used : UUID(java.util.UUID) Job(com.airbnb.airpal.api.Job) QueryError(com.facebook.presto.client.QueryError)

Aggregations

QueryError (com.facebook.presto.client.QueryError)9 QueryResults (com.facebook.presto.client.QueryResults)4 StatementClient (com.facebook.presto.client.StatementClient)4 ImmutableList (com.google.common.collect.ImmutableList)2 List (java.util.List)2 Job (com.airbnb.airpal.api.Job)1 JobState (com.airbnb.airpal.api.JobState)1 JobUpdateEvent (com.airbnb.airpal.api.event.JobUpdateEvent)1 InvalidQueryException (com.airbnb.airpal.api.output.InvalidQueryException)1 FileTooLargeException (com.airbnb.airpal.api.output.builders.FileTooLargeException)1 JobOutputBuilder (com.airbnb.airpal.api.output.builders.JobOutputBuilder)1 Persistor (com.airbnb.airpal.api.output.persistors.Persistor)1 ExecutionFailureException (com.airbnb.airpal.core.execution.ExecutionClient.ExecutionFailureException)1 QueryTimeOutException (com.airbnb.airpal.core.execution.QueryClient.QueryTimeOutException)1 BasicQueryInfo (com.airbnb.airpal.presto.QueryInfoClient.BasicQueryInfo)1 Table (com.airbnb.airpal.presto.Table)1 ClientSession (com.facebook.presto.client.ClientSession)1 ErrorLocation (com.facebook.presto.client.ErrorLocation)1 FailureInfo (com.facebook.presto.client.FailureInfo)1 QueryStats (com.facebook.presto.execution.QueryStats)1