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();
}
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();
}
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();
}
}
}
}
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);
}
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;
}
Aggregations