Exemple #1
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();
  }
  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()));
  }
Exemple #3
0
 private void partialCancel() {
   try {
     client.cancelLeafStage(new Duration(1, SECONDS));
   } catch (RuntimeException e) {
     log.debug(e, "error canceling leaf stage");
   }
 }
    @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();
    }
Exemple #5
0
  public void printInitialStatusUpdates() {
    long lastPrint = System.nanoTime();
    try {
      while (client.isValid()) {
        try {
          // exit status loop if there is there is pending output
          if (client.current().getData() != null) {
            return;
          }

          // check if time to update screen
          boolean update = nanosSince(lastPrint).getValue(SECONDS) >= 0.5;

          // check for keyboard input
          int key = readKey();
          if (key == CTRL_P) {
            partialCancel();
          } else if (key == CTRL_C) {
            updateScreen();
            update = false;
            client.close();
          } else if (toUpperCase(key) == 'D') {
            debug = !debug;
            console.resetScreen();
            update = true;
          }

          // update screen
          if (update) {
            updateScreen();
            lastPrint = System.nanoTime();
          }

          // fetch next results (server will wait for a while if no data)
          client.advance();
        } catch (RuntimeException e) {
          log.debug(e, "error printing status");
          if (debug) {
            e.printStackTrace(out);
          }
        }
      }
    } finally {
      console.resetScreen();
    }
  }
Exemple #6
0
 public void renderOutput(PrintStream out, OutputFormat outputFormat, boolean interactive) {
   Thread clientThread = Thread.currentThread();
   SignalHandler oldHandler =
       Signal.handle(
           SIGINT,
           signal -> {
             if (ignoreUserInterrupt.get() || client.isClosed()) {
               return;
             }
             userAbortedQuery.set(true);
             client.close();
             clientThread.interrupt();
           });
   try {
     renderQueryOutput(out, outputFormat, interactive);
   } finally {
     Signal.handle(SIGINT, oldHandler);
     Thread.interrupted(); // clear interrupt status
   }
 }
Exemple #7
0
 private void renderResults(
     PrintStream out, OutputFormat outputFormat, boolean interactive, List<Column> columns) {
   try {
     doRenderResults(out, outputFormat, interactive, columns);
   } catch (QueryAbortedException e) {
     System.out.println("(query aborted by user)");
     client.close();
   } catch (IOException e) {
     throw Throwables.propagate(e);
   }
 }
Exemple #8
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);
    }
  }
Exemple #9
0
 private void waitForData() {
   while (client.isValid() && (client.current().getData() == null)) {
     client.advance();
   }
 }
Exemple #10
0
 @Override
 public void close() {
   client.close();
 }
Exemple #11
0
 public Map<String, String> getSetSessionProperties() {
   return client.getSetSessionProperties();
 }
Exemple #12
0
 public StatusPrinter(StatementClient client, PrintStream out) {
   this.client = client;
   this.out = out;
   this.console = new ConsolePrinter(out);
   this.debug = client.isDebug();
 }
Exemple #13
0
 public Set<String> getResetSessionProperties() {
   return client.getResetSessionProperties();
 }
Exemple #14
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();
  }
Exemple #15
0
 private void updateScreen() {
   console.repositionCursor();
   printQueryInfo(client.current());
 }
Exemple #16
0
 public boolean isClearTransactionId() {
   return client.isClearTransactionId();
 }
Exemple #17
0
 public String getStartedTransactionId() {
   return client.getStartedtransactionId();
 }