Search in sources :

Example 1 with TableauStyle

use of org.apache.flink.table.utils.print.TableauStyle in project flink by apache.

the class CliTableauResultView method printStreamingResults.

private void printStreamingResults(AtomicInteger receivedRowCount) {
    TableauStyle style = PrintStyle.tableauWithTypeInferredColumnWidths(resultDescriptor.getResultSchema(), resultDescriptor.getRowDataStringConverter(), resultDescriptor.maxColumnWidth(), false, true);
    // print filed names
    style.printBorderLine(terminal.writer());
    style.printColumnNamesTableauRow(terminal.writer());
    style.printBorderLine(terminal.writer());
    terminal.flush();
    while (true) {
        final TypedResult<List<RowData>> result = sqlExecutor.retrieveResultChanges(sessionId, resultDescriptor.getResultId());
        switch(result.getType()) {
            case EMPTY:
                try {
                    // prevent busy loop
                    Thread.sleep(1);
                } catch (InterruptedException e) {
                    // get ctrl+c from terminal and fallback
                    return;
                }
                break;
            case EOS:
                if (receivedRowCount.get() > 0) {
                    style.printBorderLine(terminal.writer());
                }
                String rowTerm = getRowTerm(receivedRowCount);
                terminal.writer().println("Received a total of " + receivedRowCount.get() + " " + rowTerm);
                terminal.flush();
                return;
            case PAYLOAD:
                List<RowData> changes = result.getPayload();
                for (RowData change : changes) {
                    style.printTableauRow(style.rowFieldsToString(change), terminal.writer());
                    receivedRowCount.incrementAndGet();
                }
                break;
            default:
                throw new SqlExecutionException("Unknown result type: " + result.getType());
        }
    }
}
Also used : SqlExecutionException(org.apache.flink.table.client.gateway.SqlExecutionException) RowData(org.apache.flink.table.data.RowData) ArrayList(java.util.ArrayList) List(java.util.List) TableauStyle(org.apache.flink.table.utils.print.TableauStyle)

Example 2 with TableauStyle

use of org.apache.flink.table.utils.print.TableauStyle in project flink by apache.

the class CliTableauResultView method printBatchResults.

private void printBatchResults(AtomicInteger receivedRowCount) {
    final List<RowData> resultRows = waitBatchResults();
    receivedRowCount.addAndGet(resultRows.size());
    TableauStyle style = PrintStyle.tableauWithDataInferredColumnWidths(resultDescriptor.getResultSchema(), resultDescriptor.getRowDataStringConverter(), PrintStyle.DEFAULT_MAX_COLUMN_WIDTH, false, false);
    style.print(resultRows.iterator(), terminal.writer());
}
Also used : RowData(org.apache.flink.table.data.RowData) TableauStyle(org.apache.flink.table.utils.print.TableauStyle)

Aggregations

RowData (org.apache.flink.table.data.RowData)2 TableauStyle (org.apache.flink.table.utils.print.TableauStyle)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 SqlExecutionException (org.apache.flink.table.client.gateway.SqlExecutionException)1