Search in sources :

Example 1 with QueryStatusInfo

use of com.facebook.presto.client.QueryStatusInfo in project presto by prestodb.

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(com.facebook.presto.client.QueryStatusInfo) QueryError(com.facebook.presto.client.QueryError)

Example 2 with QueryStatusInfo

use of com.facebook.presto.client.QueryStatusInfo in project presto by prestodb.

the class StatusPrinter method printFinalInfo.

public void printFinalInfo() {
    Duration wallTime = nanosSince(start);
    QueryStatusInfo results = client.finalStatusInfo();
    StatementStats stats = results.getStats();
    int nodes = stats.getNodes();
    if ((nodes == 0) || (stats.getTotalSplits() == 0)) {
        return;
    }
    // blank line
    out.println();
    // Query 12, FINISHED, 1 node
    String querySummary = format("Query %s, %s, %,d %s", results.getId(), stats.getState(), nodes, pluralize("node", nodes));
    out.println(querySummary);
    if (debug) {
        out.println(results.getInfoUri().toString());
    }
    // Splits: 1000 total, 842 done (84.20%)
    String splitsSummary = format("Splits: %,d total, %,d done (%.2f%%)", stats.getTotalSplits(), stats.getCompletedSplits(), stats.getProgressPercentage().orElse(0.0));
    out.println(splitsSummary);
    if (debug) {
        // CPU Time: 565.2s total,   26K rows/s, 3.85MB/s
        Duration cpuTime = millis(stats.getCpuTimeMillis());
        String cpuTimeSummary = format("CPU Time: %.1fs total, %5s rows/s, %8s, %d%% active", cpuTime.getValue(SECONDS), formatCountRate(stats.getProcessedRows(), cpuTime, false), formatDataRate(bytes(stats.getProcessedBytes()), cpuTime, true), (int) percentage(stats.getCpuTimeMillis(), stats.getWallTimeMillis()));
        out.println(cpuTimeSummary);
        double parallelism = cpuTime.getValue(MILLISECONDS) / wallTime.getValue(MILLISECONDS);
        // Per Node: 3.5 parallelism, 83.3K rows/s, 0.7 MB/s
        String perNodeSummary = format("Per Node: %.1f parallelism, %5s rows/s, %8s", parallelism / nodes, formatCountRate((double) stats.getProcessedRows() / nodes, wallTime, false), formatDataRate(bytes(stats.getProcessedBytes() / nodes), wallTime, true));
        reprintLine(perNodeSummary);
        // Parallelism: 5.3
        out.println(format("Parallelism: %.1f", parallelism));
        // Peak User Memory: 1.97GB
        reprintLine("Peak User Memory: " + formatDataSize(bytes(stats.getPeakMemoryBytes()), true));
        // Peak Total Memory: 1.98GB
        reprintLine("Peak Total Memory: " + formatDataSize(bytes(stats.getPeakTotalMemoryBytes()), true));
        // Peak Task Total Memory: 1.99GB
        reprintLine("Peak Task Total Memory: " + formatDataSize(bytes(stats.getPeakTaskTotalMemoryBytes()), true));
        // Spilled Data: 20GB
        if (stats.getSpilledBytes() > 0) {
            reprintLine("Spilled: " + formatDataSize(bytes(stats.getSpilledBytes()), true));
        }
        // bytesFromCache: sum=2K count=2 min=1K max=1K
        if (stats.getRuntimeStats() != null) {
            stats.getRuntimeStats().getMetrics().values().stream().sorted(Comparator.comparing(RuntimeMetric::getName)).forEach(metric -> reprintLine(format("%s: sum=%s count=%s min=%s max=%s", metric.getName(), autoFormatMetricValue(metric.getName(), metric.getSum()), formatCount(metric.getCount()), autoFormatMetricValue(metric.getName(), metric.getMin()), autoFormatMetricValue(metric.getName(), metric.getMax()))));
        }
    }
    // 0:32 [2.12GB, 15M rows] [67MB/s, 463K rows/s]
    String statsLine = format("%s [%s rows, %s] [%s rows/s, %s]", formatTime(wallTime), formatCount(stats.getProcessedRows()), formatDataSize(bytes(stats.getProcessedBytes()), true), formatCountRate(stats.getProcessedRows(), wallTime, false), formatDataRate(bytes(stats.getProcessedBytes()), wallTime, true));
    out.println(statsLine);
    // blank line
    out.println();
}
Also used : StatementStats(com.facebook.presto.client.StatementStats) Duration(io.airlift.units.Duration) QueryStatusInfo(com.facebook.presto.client.QueryStatusInfo) RuntimeMetric(com.facebook.presto.common.RuntimeMetric)

Example 3 with QueryStatusInfo

use of com.facebook.presto.client.QueryStatusInfo in project presto by prestodb.

the class PrestoStatement method internalExecute.

final boolean internalExecute(String sql) throws SQLException {
    clearCurrentResults();
    checkOpen();
    StatementClient client = null;
    PrestoResultSet resultSet = null;
    boolean intercepted = false;
    try {
        WarningsManager warningsManager = new WarningsManager();
        currentWarningsManager.set(Optional.of(warningsManager));
        int statementDepth = this.statementDepth.incrementAndGet();
        boolean shouldIntercept = !connection().getQueryInterceptorInstances().isEmpty() && statementDepth == 1;
        if (shouldIntercept) {
            Optional<PrestoResultSet> newResultSet = connection().invokeQueryInterceptorsPre(sql, this);
            if (newResultSet.isPresent()) {
                resultSet = newResultSet.get();
            }
        }
        // Check if no resultSet is returned from an interceptor
        if (resultSet != null) {
            currentResult.set(resultSet);
            intercepted = true;
        } else {
            client = connection().startQuery(sql, getStatementSessionProperties());
            if (client.isFinished()) {
                QueryStatusInfo finalStatusInfo = client.finalStatusInfo();
                if (finalStatusInfo.getError() != null) {
                    throw resultsException(finalStatusInfo);
                }
            }
            executingClient.set(client);
            resultSet = new PrestoResultSet(this, client, maxRows.get(), progressConsumer, warningsManager);
            for (Map.Entry<String, SelectedRole> entry : client.getSetRoles().entrySet()) {
                connection.get().setRole(entry.getKey(), entry.getValue());
            }
        }
        // check if this is a query
        if (intercepted || client.currentStatusInfo().getUpdateType() == null) {
            currentResult.set(resultSet);
            if (shouldIntercept) {
                resultSet = connection().invokeQueryInterceptorsPost(sql, this, resultSet);
                verifyNotNull(resultSet, "invokeQueryInterceptorsPost should never return a null ResultSet");
                currentResult.set(resultSet);
            }
            return true;
        }
        // this is an update, not a query
        while (resultSet.next()) {
        // ignore rows
        }
        connection().updateSession(client);
        Long updateCount = client.finalStatusInfo().getUpdateCount();
        currentUpdateCount.set((updateCount != null) ? updateCount : 0);
        currentUpdateType.set(client.finalStatusInfo().getUpdateType());
        warningsManager.addWarnings(client.finalStatusInfo().getWarnings());
        return false;
    } catch (ClientException e) {
        throw new SQLException(e.getMessage(), e);
    } catch (RuntimeException e) {
        throw new SQLException("Error executing query", e);
    } finally {
        this.statementDepth.decrementAndGet();
        executingClient.set(null);
        if (currentResult.get() == null) {
            if (resultSet != null) {
                resultSet.close();
            }
            if (client != null) {
                client.close();
            }
        }
    }
}
Also used : SQLException(java.sql.SQLException) SelectedRole(com.facebook.presto.spi.security.SelectedRole) StatementClient(com.facebook.presto.client.StatementClient) QueryStatusInfo(com.facebook.presto.client.QueryStatusInfo) AtomicLong(java.util.concurrent.atomic.AtomicLong) ClientException(com.facebook.presto.client.ClientException) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map)

Example 4 with QueryStatusInfo

use of com.facebook.presto.client.QueryStatusInfo in project presto by prestodb.

the class PrestoResultSet method getColumns.

private static List<Column> getColumns(StatementClient client, Consumer<QueryStats> progressCallback) throws SQLException {
    while (client.isRunning()) {
        QueryStatusInfo results = client.currentStatusInfo();
        progressCallback.accept(QueryStats.create(results.getId(), results.getStats()));
        List<Column> columns = results.getColumns();
        if (columns != null) {
            return columns;
        }
        client.advance();
    }
    verify(client.isFinished());
    QueryStatusInfo results = client.finalStatusInfo();
    if (results.getError() == null) {
        throw new SQLException(format("Query has no columns (#%s)", results.getId()));
    }
    throw resultsException(results);
}
Also used : Column(com.facebook.presto.client.Column) SQLException(java.sql.SQLException) QueryStatusInfo(com.facebook.presto.client.QueryStatusInfo)

Example 5 with QueryStatusInfo

use of com.facebook.presto.client.QueryStatusInfo in project presto by prestodb.

the class Query method renderQueryOutput.

private boolean renderQueryOutput(PrintStream out, OutputFormat outputFormat, boolean interactive) {
    StatusPrinter statusPrinter = null;
    @SuppressWarnings("resource") PrintStream errorChannel = interactive ? out : System.err;
    WarningsPrinter warningsPrinter = new PrintStreamWarningsPrinter(System.err);
    if (interactive) {
        statusPrinter = new StatusPrinter(client, out, debug);
        statusPrinter.printInitialStatusUpdates();
    } else {
        processInitialStatusUpdates(warningsPrinter);
    }
    // if running or finished
    if (client.isRunning() || (client.isFinished() && client.finalStatusInfo().getError() == null)) {
        QueryStatusInfo results = client.isRunning() ? client.currentStatusInfo() : client.finalStatusInfo();
        if (results.getUpdateType() != null) {
            renderUpdate(errorChannel, results);
        } else if (results.getColumns() == null) {
            errorChannel.printf("Query %s has no columns\n", results.getId());
            return false;
        } else {
            renderResults(out, outputFormat, interactive, results.getColumns());
        }
    }
    checkState(!client.isRunning());
    if (statusPrinter != null) {
        // Print all warnings at the end of the query
        new PrintStreamWarningsPrinter(System.err).print(client.finalStatusInfo().getWarnings(), true, true);
        statusPrinter.printFinalInfo();
    } else {
        // Print remaining warnings separated
        warningsPrinter.print(client.finalStatusInfo().getWarnings(), true, true);
    }
    if (client.isClientAborted()) {
        errorChannel.println("Query aborted by user");
        return false;
    }
    if (client.isClientError()) {
        errorChannel.println("Query is gone (server restarted?)");
        return false;
    }
    verify(client.isFinished());
    if (client.finalStatusInfo().getError() != null) {
        renderFailure(errorChannel);
        return false;
    }
    return true;
}
Also used : PrintStream(java.io.PrintStream) QueryStatusInfo(com.facebook.presto.client.QueryStatusInfo)

Aggregations

QueryStatusInfo (com.facebook.presto.client.QueryStatusInfo)6 QueryError (com.facebook.presto.client.QueryError)2 StatementClient (com.facebook.presto.client.StatementClient)2 Duration (io.airlift.units.Duration)2 SQLException (java.sql.SQLException)2 ClientException (com.facebook.presto.client.ClientException)1 ClientSession (com.facebook.presto.client.ClientSession)1 Column (com.facebook.presto.client.Column)1 StatementClientFactory.newStatementClient (com.facebook.presto.client.StatementClientFactory.newStatementClient)1 StatementStats (com.facebook.presto.client.StatementStats)1 RuntimeMetric (com.facebook.presto.common.RuntimeMetric)1 QueryId (com.facebook.presto.spi.QueryId)1 SelectedRole (com.facebook.presto.spi.security.SelectedRole)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 PrintStream (java.io.PrintStream)1 Map (java.util.Map)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1