Search in sources :

Example 1 with QueryError

use of io.prestosql.client.QueryError in project hetu-core by openlookeng.

the class Query method renderFailure.

public void renderFailure(PrintStream out) {
    QueryStatusInfo results = client.finalStatusInfo();
    QueryError error = results.getError();
    checkState(error != null);
    out.printf("Query %s failed: %s%n", results.getId(), error.getMessage());
    if (debug && (error.getFailureInfo() != null)) {
        error.getFailureInfo().toException().printStackTrace(out);
    }
    if (error.getErrorLocation() != null) {
        renderErrorLocation(client.getQuery(), error.getErrorLocation(), out);
    }
    out.println();
}
Also used : QueryStatusInfo(io.prestosql.client.QueryStatusInfo) QueryError(io.prestosql.client.QueryError)

Example 2 with QueryError

use of io.prestosql.client.QueryError in project hetu-core by openlookeng.

the class PrestoResultSet method resultsException.

static SQLException resultsException(QueryStatusInfo results) {
    QueryError error = requireNonNull(results.getError());
    String message = format("Query failed (#%s): %s", results.getId(), error.getMessage());
    Throwable cause = (error.getFailureInfo() == null) ? null : error.getFailureInfo().toException();
    return new SQLException(message, error.getSqlState(), error.getErrorCode(), cause);
}
Also used : SQLException(java.sql.SQLException) QueryError(io.prestosql.client.QueryError)

Example 3 with QueryError

use of io.prestosql.client.QueryError in project hetu-core by openlookeng.

the class ExecutionClient method scheduleExecution.

private UUID scheduleExecution(Duration timeout, QueryRunner queryRunner, QueryExecutionAuthorizer authorizer, BlockingQueue<Job> jobs, URI requestUri) {
    final Job job;
    try {
        job = jobs.take();
    } catch (InterruptedException e) {
        return null;
    }
    final Execution execution = new Execution(job, queryRunner, queryInfoClient, authorizer, timeout, outputBuilderFactory, persistorFactory, requestUri);
    executionMap.put(job.getUuid(), 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);
            }
            // Add Active Job
            if (jobs.peek() != null) {
                QueryRunner nextQueryRunner = getNextQueryRunner();
                scheduleExecution(timeout, nextQueryRunner, authorizer, jobs, requestUri);
            }
            jobFinished(result);
        }

        // Re-Use session level fields among multi statement queries.
        private QueryRunner getNextQueryRunner() {
            StatementClient client = queryRunner.getCurrentClient();
            ClientSession session = queryRunner.getSession();
            ClientSession.Builder builder = ClientSession.builder(session).withoutTransactionId();
            if (client.getSetCatalog().isPresent()) {
                builder.withCatalog(client.getSetCatalog().get());
            }
            if (client.getSetSchema().isPresent()) {
                builder.withSchema(client.getSetSchema().get());
            }
            if (client.getStartedTransactionId() != null) {
                builder = builder.withTransactionId(client.getStartedTransactionId());
            }
            if (client.getSetPath().isPresent()) {
                builder = builder.withPath(client.getSetPath().get());
            }
            if (!client.getSetSessionProperties().isEmpty() || !client.getResetSessionProperties().isEmpty()) {
                Map<String, String> sessionProperties = new HashMap<>(session.getProperties());
                sessionProperties.putAll(client.getSetSessionProperties());
                sessionProperties.keySet().removeAll(client.getResetSessionProperties());
                builder = builder.withProperties(sessionProperties);
            }
            if (!client.getSetRoles().isEmpty()) {
                Map<String, ClientSelectedRole> roles = new HashMap<>(session.getRoles());
                roles.putAll(client.getSetRoles());
                builder = builder.withRoles(roles);
            }
            if (!client.getAddedPreparedStatements().isEmpty() || !client.getDeallocatedPreparedStatements().isEmpty()) {
                Map<String, String> preparedStatements = new HashMap<>(session.getPreparedStatements());
                preparedStatements.putAll(client.getAddedPreparedStatements());
                preparedStatements.keySet().removeAll(client.getDeallocatedPreparedStatements());
                builder = builder.withPreparedStatements(preparedStatements);
            }
            return queryRunnerFactory.create(builder.build());
        }

        @Override
        public void onFailure(@NotNull Throwable t) {
            job.setState(JobState.FAILED);
            if (job.getError() == null) {
                job.setError(new QueryError(t.getMessage(), null, -1, null, null, null, null, null));
            }
            jobFinished(job);
        }
    }, MoreExecutors.directExecutor());
    return job.getUuid();
}
Also used : ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) StatementClient(io.prestosql.client.StatementClient) ClientSession(io.prestosql.client.ClientSession) Job(io.prestosql.queryeditorui.protocol.Job) QueryError(io.prestosql.client.QueryError) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 4 with QueryError

use of io.prestosql.client.QueryError in project hetu-core by openlookeng.

the class CubeQuery method renderFailure.

public void renderFailure(PrintStream out) {
    QueryStatusInfo results = client.finalStatusInfo();
    QueryError error = results.getError();
    checkState(error != null);
    out.printf("Query %s failed: %s%n", results.getId(), error.getMessage());
    if (debug && (error.getFailureInfo() != null)) {
        error.getFailureInfo().toException().printStackTrace(out);
    }
    if (error.getErrorLocation() != null) {
        renderErrorLocation(client.getQuery(), error.getErrorLocation(), out);
    }
    out.println();
}
Also used : QueryStatusInfo(io.prestosql.client.QueryStatusInfo) QueryError(io.prestosql.client.QueryError)

Example 5 with QueryError

use of io.prestosql.client.QueryError in project hetu-core by openlookeng.

the class DataCenterClient method resultsException.

private static SQLException resultsException(QueryStatusInfo results) {
    QueryError error = requireNonNull(results.getError());
    String message = format("Query failed (#%s): %s", results.getId(), error.getMessage());
    Throwable cause = (error.getFailureInfo() == null) ? null : error.getFailureInfo().toException();
    return new SQLException(message, error.getSqlState(), error.getErrorCode(), cause);
}
Also used : SQLException(java.sql.SQLException) QueryError(io.prestosql.client.QueryError)

Aggregations

QueryError (io.prestosql.client.QueryError)11 QueryStatusInfo (io.prestosql.client.QueryStatusInfo)4 StatementClient (io.prestosql.client.StatementClient)3 ClientSession (io.prestosql.client.ClientSession)2 FailureInfo (io.prestosql.client.FailureInfo)2 StatementClientFactory.newStatementClient (io.prestosql.client.StatementClientFactory.newStatementClient)2 SQLException (java.sql.SQLException)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 Request (io.airlift.http.client.Request)1 Duration (io.airlift.units.Duration)1 Column (io.prestosql.client.Column)1 ErrorLocation (io.prestosql.client.ErrorLocation)1 QueryData (io.prestosql.client.QueryData)1 QueryResults (io.prestosql.client.QueryResults)1 ExecutionFailureInfo (io.prestosql.execution.ExecutionFailureInfo)1 QueryState (io.prestosql.execution.QueryState)1 QueryStats (io.prestosql.execution.QueryStats)1 ExecutionFailureException (io.prestosql.queryeditorui.execution.ExecutionClient.ExecutionFailureException)1