Java Code Examples for org.apache.flink.table.client.gateway.TypedResult#getType()
The following examples show how to use
org.apache.flink.table.client.gateway.TypedResult#getType() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LocalExecutorITCase.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
private List<String> retrieveTableResult( Executor executor, SessionContext session, String resultID) throws InterruptedException { final List<String> actualResults = new ArrayList<>(); while (true) { Thread.sleep(50); // slow the processing down final TypedResult<Integer> result = executor.snapshotResult(session, resultID, 2); if (result.getType() == TypedResult.ResultType.PAYLOAD) { actualResults.clear(); IntStream.rangeClosed(1, result.getPayload()).forEach((page) -> { for (Row row : executor.retrieveResultPage(resultID, page)) { actualResults.add(row.toString()); } }); } else if (result.getType() == TypedResult.ResultType.EOS) { break; } } return actualResults; }
Example 2
Source File: LocalExecutorITCase.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
private List<String> retrieveChangelogResult( Executor executor, SessionContext session, String resultID) throws InterruptedException { final List<String> actualResults = new ArrayList<>(); while (true) { Thread.sleep(50); // slow the processing down final TypedResult<List<Tuple2<Boolean, Row>>> result = executor.retrieveResultChanges(session, resultID); if (result.getType() == TypedResult.ResultType.PAYLOAD) { for (Tuple2<Boolean, Row> change : result.getPayload()) { actualResults.add(change.toString()); } } else if (result.getType() == TypedResult.ResultType.EOS) { break; } } return actualResults; }
Example 3
Source File: LocalExecutorITCase.java From flink with Apache License 2.0 | 6 votes |
private List<String> retrieveTableResult( Executor executor, SessionContext session, String resultID) throws InterruptedException { final List<String> actualResults = new ArrayList<>(); while (true) { Thread.sleep(50); // slow the processing down final TypedResult<Integer> result = executor.snapshotResult(session, resultID, 2); if (result.getType() == TypedResult.ResultType.PAYLOAD) { actualResults.clear(); IntStream.rangeClosed(1, result.getPayload()).forEach((page) -> { for (Row row : executor.retrieveResultPage(resultID, page)) { actualResults.add(row.toString()); } }); } else if (result.getType() == TypedResult.ResultType.EOS) { break; } } return actualResults; }
Example 4
Source File: LocalExecutorITCase.java From flink with Apache License 2.0 | 6 votes |
private List<String> retrieveChangelogResult( Executor executor, SessionContext session, String resultID) throws InterruptedException { final List<String> actualResults = new ArrayList<>(); while (true) { Thread.sleep(50); // slow the processing down final TypedResult<List<Tuple2<Boolean, Row>>> result = executor.retrieveResultChanges(session, resultID); if (result.getType() == TypedResult.ResultType.PAYLOAD) { for (Tuple2<Boolean, Row> change : result.getPayload()) { actualResults.add(change.toString()); } } else if (result.getType() == TypedResult.ResultType.EOS) { break; } } return actualResults; }
Example 5
Source File: LocalExecutorITCase.java From flink with Apache License 2.0 | 6 votes |
private List<String> retrieveTableResult( Executor executor, String sessionId, String resultID) throws InterruptedException { final List<String> actualResults = new ArrayList<>(); while (true) { Thread.sleep(50); // slow the processing down final TypedResult<Integer> result = executor.snapshotResult(sessionId, resultID, 2); if (result.getType() == TypedResult.ResultType.PAYLOAD) { actualResults.clear(); IntStream.rangeClosed(1, result.getPayload()).forEach((page) -> { for (Row row : executor.retrieveResultPage(resultID, page)) { actualResults.add(row.toString()); } }); } else if (result.getType() == TypedResult.ResultType.EOS) { break; } } return actualResults; }
Example 6
Source File: LocalExecutorITCase.java From flink with Apache License 2.0 | 6 votes |
private List<String> retrieveChangelogResult( Executor executor, String sessionId, String resultID) throws InterruptedException { final List<String> actualResults = new ArrayList<>(); while (true) { Thread.sleep(50); // slow the processing down final TypedResult<List<Tuple2<Boolean, Row>>> result = executor.retrieveResultChanges(sessionId, resultID); if (result.getType() == TypedResult.ResultType.PAYLOAD) { for (Tuple2<Boolean, Row> change : result.getPayload()) { actualResults.add(change.toString()); } } else if (result.getType() == TypedResult.ResultType.EOS) { break; } } return actualResults; }
Example 7
Source File: CliTableResultView.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Override protected void refresh() { // take snapshot TypedResult<Integer> result; try { result = client.getExecutor().snapshotResult(client.getContext(), resultDescriptor.getResultId(), getVisibleMainHeight()); } catch (SqlExecutionException e) { close(e); return; } // stop retrieval if job is done if (result.getType() == TypedResult.ResultType.EOS) { stopRetrieval(false); } // update page else if (result.getType() == TypedResult.ResultType.PAYLOAD) { int newPageCount = result.getPayload(); pageCount = newPageCount; if (page > newPageCount) { page = LAST_PAGE; } updatePage(); } lastRetrieval = LocalTime.now(); // reset view resetAllParts(); }
Example 8
Source File: CliTableResultView.java From flink with Apache License 2.0 | 5 votes |
@Override protected void refresh() { // take snapshot TypedResult<Integer> result; try { result = client.getExecutor().snapshotResult(client.getContext(), resultDescriptor.getResultId(), getVisibleMainHeight()); } catch (SqlExecutionException e) { close(e); return; } // stop retrieval if job is done if (result.getType() == TypedResult.ResultType.EOS) { stopRetrieval(false); } // update page else if (result.getType() == TypedResult.ResultType.PAYLOAD) { int newPageCount = result.getPayload(); pageCount = newPageCount; if (page > newPageCount) { page = LAST_PAGE; } updatePage(); } lastRetrieval = LocalTime.now(); // reset view resetAllParts(); }
Example 9
Source File: CliTableauResultView.java From flink with Apache License 2.0 | 5 votes |
private List<Row> waitBatchResults() { List<Row> resultRows; // take snapshot and make all results in one page do { try { Thread.sleep(50); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } TypedResult<Integer> result = sqlExecutor.snapshotResult( sessionId, resultDescriptor.getResultId(), Integer.MAX_VALUE); if (result.getType() == TypedResult.ResultType.EOS) { resultRows = Collections.emptyList(); break; } else if (result.getType() == TypedResult.ResultType.PAYLOAD) { resultRows = sqlExecutor.retrieveResultPage(resultDescriptor.getResultId(), 1); break; } else { // result not retrieved yet } } while (true); return resultRows; }
Example 10
Source File: CliTableResultView.java From flink with Apache License 2.0 | 5 votes |
@Override protected void refresh() { // take snapshot TypedResult<Integer> result; try { result = client.getExecutor().snapshotResult(client.getSessionId(), resultDescriptor.getResultId(), getVisibleMainHeight()); } catch (SqlExecutionException e) { close(e); return; } // stop retrieval if job is done if (result.getType() == TypedResult.ResultType.EOS) { stopRetrieval(false); } // update page else if (result.getType() == TypedResult.ResultType.PAYLOAD) { int newPageCount = result.getPayload(); pageCount = newPageCount; if (page > newPageCount) { page = LAST_PAGE; } updatePage(); } lastRetrieval = LocalTime.now(); // reset view resetAllParts(); }
Example 11
Source File: CliChangelogResultView.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
@Override protected void refresh() { // retrieve change record final TypedResult<List<Tuple2<Boolean, Row>>> result; try { result = client.getExecutor().retrieveResultChanges(client.getContext(), resultDescriptor.getResultId()); } catch (SqlExecutionException e) { close(e); return; } // do nothing if result is empty switch (result.getType()) { case EMPTY: // do nothing break; // stop retrieval if job is done case EOS: stopRetrieval(false); break; default: List<Tuple2<Boolean, Row>> changes = result.getPayload(); for (Tuple2<Boolean, Row> change : changes) { // convert row final String[] changeRow = new String[change.f1.getArity() + 1]; final String[] row = rowToString(change.f1); System.arraycopy(row, 0, changeRow, 1, row.length); if (change.f0) { changeRow[0] = "+"; } else { changeRow[0] = "-"; } // update results // formatting and printing of rows is expensive in the current implementation, // therefore we limit the maximum number of lines shown in changelog mode to // keep the CLI responsive if (results.size() >= DEFAULT_MAX_ROW_COUNT) { results.remove(0); } results.add(changeRow); scrolling++; } break; } // reset view resetAllParts(); lastRetrieval = LocalTime.now(); }
Example 12
Source File: CliChangelogResultView.java From flink with Apache License 2.0 | 4 votes |
@Override protected void refresh() { // retrieve change record final TypedResult<List<Tuple2<Boolean, Row>>> result; try { result = client.getExecutor().retrieveResultChanges(client.getContext(), resultDescriptor.getResultId()); } catch (SqlExecutionException e) { close(e); return; } // do nothing if result is empty switch (result.getType()) { case EMPTY: // do nothing break; // stop retrieval if job is done case EOS: stopRetrieval(false); break; default: List<Tuple2<Boolean, Row>> changes = result.getPayload(); for (Tuple2<Boolean, Row> change : changes) { // convert row final String[] changeRow = new String[change.f1.getArity() + 1]; final String[] row = rowToString(change.f1); System.arraycopy(row, 0, changeRow, 1, row.length); if (change.f0) { changeRow[0] = "+"; } else { changeRow[0] = "-"; } // update results // formatting and printing of rows is expensive in the current implementation, // therefore we limit the maximum number of lines shown in changelog mode to // keep the CLI responsive if (results.size() >= DEFAULT_MAX_ROW_COUNT) { results.remove(0); } results.add(changeRow); scrolling++; } break; } // reset view resetAllParts(); lastRetrieval = LocalTime.now(); }
Example 13
Source File: CliChangelogResultView.java From flink with Apache License 2.0 | 4 votes |
@Override protected void refresh() { // retrieve change record final TypedResult<List<Tuple2<Boolean, Row>>> result; try { result = client.getExecutor().retrieveResultChanges(client.getSessionId(), resultDescriptor.getResultId()); } catch (SqlExecutionException e) { close(e); return; } // do nothing if result is empty switch (result.getType()) { case EMPTY: // do nothing break; // stop retrieval if job is done case EOS: stopRetrieval(false); break; default: List<Tuple2<Boolean, Row>> changes = result.getPayload(); for (Tuple2<Boolean, Row> change : changes) { // convert row final String[] changeRow = new String[change.f1.getArity() + 1]; final String[] row = PrintUtils.rowToString(change.f1); System.arraycopy(row, 0, changeRow, 1, row.length); if (change.f0) { changeRow[0] = "+"; } else { changeRow[0] = "-"; } // update results // formatting and printing of rows is expensive in the current implementation, // therefore we limit the maximum number of lines shown in changelog mode to // keep the CLI responsive if (results.size() >= DEFAULT_MAX_ROW_COUNT) { results.remove(0); } results.add(changeRow); scrolling++; } break; } // reset view resetAllParts(); lastRetrieval = LocalTime.now(); }
Example 14
Source File: CliTableauResultView.java From flink with Apache License 2.0 | 4 votes |
private void printStreamResults(AtomicInteger receivedRowCount) { List<TableColumn> columns = resultDescriptor.getResultSchema().getTableColumns(); String[] fieldNames = Stream.concat( Stream.of(CHANGEFLAG_COLUMN_NAME), columns.stream().map(TableColumn::getName) ).toArray(String[]::new); int[] colWidths = PrintUtils.columnWidthsByType( columns, DEFAULT_COLUMN_WIDTH, CliStrings.NULL_COLUMN, CHANGEFLAG_COLUMN_NAME); String borderline = PrintUtils.genBorderLine(colWidths); // print filed names terminal.writer().println(borderline); PrintUtils.printSingleRow(colWidths, fieldNames, terminal.writer()); terminal.writer().println(borderline); terminal.flush(); while (true) { final TypedResult<List<Tuple2<Boolean, Row>>> result = sqlExecutor.retrieveResultChanges(sessionId, resultDescriptor.getResultId()); switch (result.getType()) { case EMPTY: // do nothing break; case EOS: if (receivedRowCount.get() > 0) { terminal.writer().println(borderline); } terminal.writer().println("Received a total of " + receivedRowCount.get() + " rows"); terminal.flush(); return; case PAYLOAD: List<Tuple2<Boolean, Row>> changes = result.getPayload(); for (Tuple2<Boolean, Row> change : changes) { final String[] cols = PrintUtils.rowToString(change.f1); String[] row = new String[cols.length + 1]; row[0] = change.f0 ? "+" : "-"; System.arraycopy(cols, 0, row, 1, cols.length); PrintUtils.printSingleRow(colWidths, row, terminal.writer()); receivedRowCount.incrementAndGet(); } break; default: throw new SqlExecutionException("Unknown result type: " + result.getType()); } } }