示例#1
0
  private static List<Column> getColumns(StatementClient client) {
    while (client.isValid()) {
      List<Column> columns = client.current().getColumns();
      if (columns != null) {
        return columns;
      }
      client.advance();
    }

    if (!client.isFailed()) {
      throw internalServerError("No columns");
    }
    throw internalServerError(failureMessage(client.finalResults()));
  }
示例#2
0
  public void renderFailure(PrintStream out) {
    QueryResults results = client.finalResults();
    QueryError error = results.getError();
    checkState(error != null);

    out.printf("Query %s failed: %s%n", results.getId(), error.getMessage());
    if (client.isDebug() && (error.getFailureInfo() != null)) {
      error.getFailureInfo().toException().printStackTrace(out);
    }
    if (error.getErrorLocation() != null) {
      renderErrorLocation(client.getQuery(), error.getErrorLocation(), out);
    }
    out.println();
  }
示例#3
0
    @Override
    protected Iterable<List<Object>> computeNext() {
      while (client.isValid()) {
        Iterable<List<Object>> data = client.current().getData();
        client.advance();
        if (data != null) {
          return data;
        }
      }

      if (client.isFailed()) {
        throw internalServerError(failureMessage(client.finalResults()));
      }

      return endOfData();
    }
示例#4
0
  private void renderQueryOutput(PrintStream out, OutputFormat outputFormat, boolean interactive) {
    StatusPrinter statusPrinter = null;
    @SuppressWarnings("resource")
    PrintStream errorChannel = interactive ? out : System.err;

    if (interactive) {
      statusPrinter = new StatusPrinter(client, out);
      statusPrinter.printInitialStatusUpdates();
    } else {
      waitForData();
    }

    if ((!client.isFailed()) && (!client.isGone()) && (!client.isClosed())) {
      QueryResults results = client.isValid() ? client.current() : client.finalResults();
      if (results.getUpdateType() != null) {
        renderUpdate(out, results);
      } else if (results.getColumns() == null) {
        errorChannel.printf("Query %s has no columns\n", results.getId());
        return;
      } else {
        renderResults(out, outputFormat, interactive, results.getColumns());
      }
    }

    if (statusPrinter != null) {
      statusPrinter.printFinalInfo();
    }

    if (client.isClosed()) {
      errorChannel.println("Query aborted by user");
    } else if (client.isGone()) {
      errorChannel.println("Query is gone (server restarted?)");
    } else if (client.isFailed()) {
      renderFailure(errorChannel);
    }
  }
示例#5
0
  public void printFinalInfo() {
    Duration wallTime = nanosSince(start);

    QueryResults results = client.finalResults();
    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 =
        String.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 =
        String.format(
            "Splits: %,d total, %,d done (%.2f%%)",
            stats.getTotalSplits(),
            stats.getCompletedSplits(),
            percentage(stats.getCompletedSplits(), stats.getTotalSplits()));
    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(
              "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 =
          String.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);

      out.println(String.format("Parallelism: %.1f", parallelism));
    }

    // 0:32 [2.12GB, 15M rows] [67MB/s, 463K rows/s]
    String statsLine =
        String.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();
  }