presto-cli/src/main/java/io/prestosql/cli/OutputHandler.java/OutputHandler/processRows
class OutputHandler:    public void processRows(StatementClient client)
            throws IOException
    {
        BlockingQueue<List<?>> rowQueue = new LinkedBlockingQueue<>(MAX_QUEUED_ROWS);
        CompletableFuture<Void> readerFuture = CompletableFuture.runAsync(() -> {
            while (client.isRunning()) {
                Iterable<List<Object>> data = client.currentData().getData();
                if (data != null) {
                    for (List<Object> row : data) {
                        putOrThrow(rowQueue, row);
                    }
                }
                client.advance();
            }
        }).whenComplete((result, ex) -> putOrThrow(rowQueue, END_TOKEN));

        List<List<?>> rowBuffer = new ArrayList<>(MAX_BUFFERED_ROWS);
        long bufferStart = System.nanoTime();
        try {
            while (!readerFuture.isDone()) {
                boolean atEnd = drainDetectingEnd(rowQueue, rowBuffer, MAX_BUFFERED_ROWS, END_TOKEN);
                if (atEnd) {
                    break;
                }

                // Flush if needed
                if (rowBuffer.size() >= MAX_BUFFERED_ROWS || nanosSince(bufferStart).compareTo(MAX_BUFFER_TIME) >= 0) {
                    printer.printRows(unmodifiableList(rowBuffer), false);
                    rowBuffer.clear();
                    bufferStart = System.nanoTime();
                }

                List<?> row = rowQueue.poll(MAX_BUFFER_TIME.toMillis(), MILLISECONDS);
                if (row == END_TOKEN) {
                    break;
                }
                else if (row != null) {
                    rowBuffer.add(row);
                }
            }
            if (!rowQueue.isEmpty()) {
                drainDetectingEnd(rowQueue, rowBuffer, Integer.MAX_VALUE, END_TOKEN);
            }
            printer.printRows(unmodifiableList(rowBuffer), true);
            readerFuture.get(); // propagate any exceptions
        }
        catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new RuntimeException(e);
        }
        catch (ExecutionException e) {
            propagateIfPossible(e.getCause(), IOException.class);
            throw new RuntimeException(e.getCause());
        }
    }