Search in sources :

Example 1 with QueryStatusInfo

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

the class CubeQuery method resultsCubeInitialQuery.

private boolean resultsCubeInitialQuery(Terminal terminal, PrintStream out, PrintStream errorChannel, ClientOptions.OutputFormat outputFormat, boolean usePager, boolean showProgress) {
    StatusPrinter statusPrinter = null;
    WarningsPrinter warningsPrinter = new PrintStreamWarningsPrinter(errorChannel);
    if (showProgress) {
        statusPrinter = new StatusPrinter(client, errorChannel, debug);
        statusPrinter.printInitialStatusUpdates(terminal);
    } 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, usePager, results.getColumns());
            // /populate results from here
            if (cubeConsole.getListRowBufferIterationItems().size() == EMPTY_ITERATION_LIST_SIZE) {
                if (client.isFinished() && client.finalStatusInfo().getError() == null) {
                    QueryData queryData = ((QueryResults) results);
                    if (queryData.getData() != null) {
                        if (queryData.getData().iterator().hasNext()) {
                            if (queryData.getData().iterator().next().iterator().hasNext()) {
                                cubeInitQueryResult = queryData.getData().iterator().next().iterator().next().toString();
                            }
                        }
                    }
                }
            }
        }
    }
    checkState(!client.isRunning());
    warningsPrinter.print(client.finalStatusInfo().getWarnings(), true, true);
    if (showProgress) {
        statusPrinter.printFinalInfo();
    }
    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 : QueryData(io.prestosql.client.QueryData) QueryStatusInfo(io.prestosql.client.QueryStatusInfo) QueryResults(io.prestosql.client.QueryResults)

Example 2 with QueryStatusInfo

use of io.prestosql.client.QueryStatusInfo 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 3 with QueryStatusInfo

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

the class PrestoResultSet method getColumns.

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

Example 4 with QueryStatusInfo

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

the class PrestoStatement method internalExecute.

final boolean internalExecute(String sql) throws SQLException {
    clearCurrentResults();
    checkOpen();
    StatementClient client = null;
    PrestoResultSet resultSet = null;
    try {
        client = connection().startQuery(sql, getStatementSessionProperties());
        if (client.isFinished()) {
            QueryStatusInfo finalStatusInfo = client.finalStatusInfo();
            if (finalStatusInfo.getError() != null) {
                throw resultsException(finalStatusInfo);
            }
        }
        executingClient.set(client);
        WarningsManager warningsManager = new WarningsManager();
        currentWarningsManager.set(Optional.of(warningsManager));
        resultSet = new PrestoResultSet(client, maxRows.get(), progressConsumer, warningsManager);
        // check if this is a query
        if (client.currentStatusInfo().getUpdateType() == null) {
            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 {
        executingClient.set(null);
        if (currentResult.get() == null) {
            if (resultSet != null) {
                resultSet.close();
            }
            if (client != null) {
                client.close();
            }
        }
    }
}
Also used : SQLException(java.sql.SQLException) StatementClient(io.prestosql.client.StatementClient) AtomicLong(java.util.concurrent.atomic.AtomicLong) ClientException(io.prestosql.client.ClientException) QueryStatusInfo(io.prestosql.client.QueryStatusInfo)

Example 5 with QueryStatusInfo

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

the class StatusPrinter method printFinalInfo.

public void printFinalInfo() {
    QueryStatusInfo results = client.finalStatusInfo();
    StatementStats stats = results.getStats();
    Duration wallTime = succinctDuration(stats.getElapsedTimeMillis(), MILLISECONDS);
    int nodes = stats.getNodes();
    if ((nodes == 0) || (stats.getTotalSplits() == 0)) {
        return;
    }
    // blank line
    out.println();
    // Query 12, FINISHED, 1 node
    String querySummary = String.format("Query %s, %s, %,d %s", results.getId(), stats.getState(), nodes, FormatUtils.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 = String.format(Locale.ROOT, "CPU Time: %.1fs total, %5s rows/s, %8s, %d%% active", cpuTime.getValue(SECONDS), FormatUtils.formatCountRate(stats.getProcessedRows(), cpuTime, false), FormatUtils.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 = String.format("Per Node: %.1f parallelism, %5s rows/s, %8s", parallelism / nodes, FormatUtils.formatCountRate((double) stats.getProcessedRows() / nodes, wallTime, false), FormatUtils.formatDataRate(bytes(stats.getProcessedBytes() / nodes), wallTime, true));
        reprintLine(perNodeSummary);
        // Parallelism: 5.3
        out.println(format("Parallelism: %.1f", parallelism));
        // Peak Memory: 1.97GB
        reprintLine("Peak Memory: " + FormatUtils.formatDataSize(bytes(stats.getPeakMemoryBytes()), true));
        // Spilled Data: 20GB, Writing Time Per Node: 22s, Reading Time Per Node: 1.2s
        if (stats.getSpilledBytes() > 0) {
            Duration readTime = millis(stats.getElapsedSpillReadTimeMillis() / stats.getSpilledNodes());
            Duration writeTime = millis(stats.getElapsedSpillWriteTimeMillis() / stats.getSpilledNodes());
            String summary = String.format("Spilled: %s, Writing Time Per Node: %.1fs, Reading Time Per Node: %.1fs", FormatUtils.formatDataSize(bytes(stats.getSpilledBytes()), true), writeTime.getValue(SECONDS), readTime.getValue(SECONDS));
            reprintLine(summary);
        }
        // Snapshot Capture stats All: 100MB/22s/18s, Last: 40MB/10s/7s
        SnapshotStats snapshotStats = stats.getSnapshotStats();
        // snapshotStats should be null in case snapshot feature is disabled
        if (snapshotStats != null) {
            Duration allCaptureCPUTime = millis(snapshotStats.getTotalCaptureCpuTime());
            Duration allCaptureWallTime = millis(snapshotStats.getTotalCaptureWallTime());
            Duration lastCaptureCPUTime = millis(snapshotStats.getLastCaptureCpuTime());
            Duration lastCaptureWallTime = millis(snapshotStats.getLastCaptureWallTime());
            String allSnapshotsSize = FormatUtils.formatDataSize(bytes(snapshotStats.getAllCaptureSize()), true);
            String lastSnapshotSize = FormatUtils.formatDataSize(bytes(snapshotStats.getLastCaptureSize()), true);
            String captureSummary = String.format("Snapshot Capture: All: %s/%.1fs/%.1fs, Last: %s/%.1fs/%.1fs", allSnapshotsSize, allCaptureCPUTime.getValue(SECONDS), allCaptureWallTime.getValue(SECONDS), lastSnapshotSize, lastCaptureCPUTime.getValue(SECONDS), lastCaptureWallTime.getValue(SECONDS));
            reprintLine(captureSummary);
            // Snapshot restore stats: 1/100MB/22s/18s
            long restoreCount = snapshotStats.getSuccessRestoreCount();
            if (restoreCount > 0) {
                Duration allRestoreCPUTime = millis(snapshotStats.getTotalRestoreCpuTime());
                Duration allRestoreWallTime = millis(snapshotStats.getTotalRestoreWallTime());
                String allRestoreSize = FormatUtils.formatDataSize(bytes(snapshotStats.getTotalRestoreSize()), true);
                String restoreSummary = String.format(Locale.ROOT, "Snapshot Restore: %d/%s/%.1fs/%.1fs", restoreCount, allRestoreSize, allRestoreCPUTime.getValue(SECONDS), allRestoreWallTime.getValue(SECONDS));
                reprintLine(restoreSummary);
            }
        }
    }
    // 0:32 [2.12GB, 15M rows] [67MB/s, 463K rows/s]
    String statsLine = String.format("%s [%s rows, %s] [%s rows/s, %s]", FormatUtils.formatTime(wallTime, timeInMilliseconds), FormatUtils.formatCount(stats.getProcessedRows()), FormatUtils.formatDataSize(bytes(stats.getProcessedBytes()), true), FormatUtils.formatCountRate(stats.getProcessedRows(), wallTime, false), FormatUtils.formatDataRate(bytes(stats.getProcessedBytes()), wallTime, true));
    out.println(statsLine);
    // blank line
    out.println();
}
Also used : StatementStats(io.prestosql.client.StatementStats) SnapshotStats(io.prestosql.client.SnapshotStats) Duration(io.airlift.units.Duration) Duration.succinctDuration(io.airlift.units.Duration.succinctDuration) QueryStatusInfo(io.prestosql.client.QueryStatusInfo)

Aggregations

QueryStatusInfo (io.prestosql.client.QueryStatusInfo)11 QueryError (io.prestosql.client.QueryError)4 StatementClient (io.prestosql.client.StatementClient)4 SQLException (java.sql.SQLException)4 ImmutableList (com.google.common.collect.ImmutableList)2 Duration (io.airlift.units.Duration)2 Column (io.prestosql.client.Column)2 DataCenterStatementClient (io.prestosql.client.DataCenterStatementClient)2 QueryData (io.prestosql.client.QueryData)2 List (java.util.List)2 Duration.succinctDuration (io.airlift.units.Duration.succinctDuration)1 ClientException (io.prestosql.client.ClientException)1 ClientSession (io.prestosql.client.ClientSession)1 ErrorLocation (io.prestosql.client.ErrorLocation)1 QueryResults (io.prestosql.client.QueryResults)1 SnapshotStats (io.prestosql.client.SnapshotStats)1 StatementClientFactory.newStatementClient (io.prestosql.client.StatementClientFactory.newStatementClient)1 StatementStats (io.prestosql.client.StatementStats)1 QueryStats (io.prestosql.execution.QueryStats)1 ExecutionFailureException (io.prestosql.queryeditorui.execution.ExecutionClient.ExecutionFailureException)1