use of org.apache.flink.table.client.gateway.ResultDescriptor in project flink by apache.
the class CliTableauResultViewTest method testBatchResult.
@Test
public void testBatchResult() {
final Configuration testConfig = new Configuration();
testConfig.set(EXECUTION_RESULT_MODE, ResultMode.TABLEAU);
testConfig.set(RUNTIME_MODE, RuntimeExecutionMode.BATCH);
ResultDescriptor resultDescriptor = new ResultDescriptor("", schema, true, testConfig, rowDataToStringConverter);
TestingExecutor mockExecutor = new TestingExecutorBuilder().setResultChangesSupplier(() -> TypedResult.payload(data.subList(0, data.size() / 2)), () -> TypedResult.payload(data.subList(data.size() / 2, data.size())), TypedResult::endOfStream).build();
CliTableauResultView view = new CliTableauResultView(terminal, mockExecutor, "session", resultDescriptor);
view.displayResults();
view.close();
Assert.assertEquals("+---------+-------------+----------------------+--------------------------------+----------------+----------------------------+" + System.lineSeparator() + "| boolean | int | bigint | varchar | decimal(10, 5) | timestamp |" + System.lineSeparator() + "+---------+-------------+----------------------+--------------------------------+----------------+----------------------------+" + System.lineSeparator() + "| <NULL> | 1 | 2 | abc | 1.23000 | 2020-03-01 18:39:14.000000 |" + System.lineSeparator() + "| FALSE | <NULL> | 0 | | 1.00000 | 2020-03-01 18:39:14.100000 |" + System.lineSeparator() + "| TRUE | 2147483647 | <NULL> | abcdefg | 12345.00000 | 2020-03-01 18:39:14.120000 |" + System.lineSeparator() + "| FALSE | -2147483648 | 9223372036854775807 | <NULL> | 12345.06789 | 2020-03-01 18:39:14.123000 |" + System.lineSeparator() + "| TRUE | 100 | -9223372036854775808 | abcdefg111 | <NULL> | 2020-03-01 18:39:14.123456 |" + System.lineSeparator() + "| <NULL> | -1 | -1 | abcdefghijklmnopqrstuvwxyz | -12345.06789 | <NULL> |" + System.lineSeparator() + "| <NULL> | -1 | -1 | 这是一段中文 | -12345.06789 | 2020-03-04 18:39:14.000000 |" + System.lineSeparator() + "| <NULL> | -1 | -1 | これは日本語をテストするた... | -12345.06789 | 2020-03-04 18:39:14.000000 |" + System.lineSeparator() + "+---------+-------------+----------------------+--------------------------------+----------------+----------------------------+" + System.lineSeparator() + "8 rows in set" + System.lineSeparator(), terminalOutput.toString());
assertThat(mockExecutor.getNumCancelCalls(), is(0));
}
use of org.apache.flink.table.client.gateway.ResultDescriptor in project flink by apache.
the class CliTableauResultViewTest method testCancelBatchResult.
@Test
public void testCancelBatchResult() throws Exception {
final Configuration testConfig = new Configuration();
testConfig.set(EXECUTION_RESULT_MODE, ResultMode.TABLEAU);
testConfig.set(RUNTIME_MODE, RuntimeExecutionMode.BATCH);
ResultDescriptor resultDescriptor = new ResultDescriptor("", schema, true, testConfig, rowDataToStringConverter);
TestingExecutor mockExecutor = new TestingExecutorBuilder().setResultChangesSupplier(() -> TypedResult.payload(data.subList(0, data.size() / 2)), TypedResult::empty).build();
CliTableauResultView view = new CliTableauResultView(terminal, mockExecutor, "session", resultDescriptor);
// submit result display in another thread
ExecutorService executorService = Executors.newSingleThreadExecutor();
Future<?> furture = executorService.submit(view::displayResults);
// wait until we trying to get batch result
CommonTestUtils.waitUntilCondition(() -> mockExecutor.getNumRetrieveResultChancesCalls() > 1, Deadline.now().plus(Duration.ofSeconds(5)), 50L);
// send signal to cancel
terminal.raise(Terminal.Signal.INT);
furture.get(5, TimeUnit.SECONDS);
Assert.assertEquals("Query terminated, received a total of 0 row" + System.lineSeparator(), terminalOutput.toString());
// didn't have a chance to read page
assertThat(mockExecutor.getNumRetrieveResultPageCalls(), is(0));
// tried to cancel query
assertThat(mockExecutor.getNumCancelCalls(), is(1));
view.close();
}
use of org.apache.flink.table.client.gateway.ResultDescriptor in project flink by apache.
the class CliTableauResultViewTest method testFailedBatchResult.
@Test
public void testFailedBatchResult() {
final Configuration testConfig = new Configuration();
testConfig.set(EXECUTION_RESULT_MODE, ResultMode.TABLEAU);
testConfig.set(RUNTIME_MODE, RuntimeExecutionMode.BATCH);
ResultDescriptor resultDescriptor = new ResultDescriptor("", schema, true, testConfig, rowDataToStringConverter);
TestingExecutor mockExecutor = new TestingExecutorBuilder().setResultChangesSupplier(() -> {
throw new SqlExecutionException("query failed");
}, TypedResult::endOfStream).build();
CliTableauResultView view = new CliTableauResultView(terminal, mockExecutor, "session", resultDescriptor);
try {
view.displayResults();
Assert.fail("Shouldn't get here");
} catch (SqlExecutionException e) {
Assert.assertEquals("query failed", e.getMessage());
}
view.close();
assertThat(mockExecutor.getNumCancelCalls(), is(1));
}
use of org.apache.flink.table.client.gateway.ResultDescriptor in project flink by apache.
the class CliTableauResultViewTest method testEmptyBatchResult.
@Test
public void testEmptyBatchResult() {
final Configuration testConfig = new Configuration();
testConfig.set(EXECUTION_RESULT_MODE, ResultMode.TABLEAU);
testConfig.set(RUNTIME_MODE, RuntimeExecutionMode.BATCH);
ResultDescriptor resultDescriptor = new ResultDescriptor("", schema, true, testConfig, rowDataToStringConverter);
TestingExecutor mockExecutor = new TestingExecutorBuilder().setResultChangesSupplier(TypedResult::endOfStream).setResultPageSupplier(() -> {
throw new SqlExecutionException("query failed");
}).build();
CliTableauResultView view = new CliTableauResultView(terminal, mockExecutor, "session", resultDescriptor);
view.displayResults();
view.close();
Assert.assertEquals("Empty set" + System.lineSeparator(), terminalOutput.toString());
assertThat(mockExecutor.getNumCancelCalls(), is(0));
}
use of org.apache.flink.table.client.gateway.ResultDescriptor in project flink by apache.
the class CliTableauResultViewTest method testCancelStreamingResult.
@Test
public void testCancelStreamingResult() throws Exception {
final Configuration testConfig = new Configuration();
testConfig.set(EXECUTION_RESULT_MODE, ResultMode.TABLEAU);
testConfig.set(RUNTIME_MODE, RuntimeExecutionMode.STREAMING);
ResultDescriptor resultDescriptor = new ResultDescriptor("", schema, true, testConfig, rowDataToStringConverter);
TestingExecutor mockExecutor = new TestingExecutorBuilder().setResultChangesSupplier(() -> TypedResult.payload(streamingData.subList(0, streamingData.size() / 2)), TypedResult::empty).build();
CliTableauResultView view = new CliTableauResultView(terminal, mockExecutor, "session", resultDescriptor);
// submit result display in another thread
ExecutorService executorService = Executors.newSingleThreadExecutor();
Future<?> furture = executorService.submit(view::displayResults);
// wait until we processed first result
CommonTestUtils.waitUntilCondition(() -> mockExecutor.getNumRetrieveResultChancesCalls() > 1, Deadline.now().plus(Duration.ofSeconds(5)), 50L);
// send signal to cancel
terminal.raise(Terminal.Signal.INT);
furture.get(5, TimeUnit.SECONDS);
view.close();
Assert.assertEquals("+----+---------+-------------+----------------------+--------------------------------+----------------+----------------------------+" + System.lineSeparator() + "| op | boolean | int | bigint | varchar | decimal(10, 5) | timestamp |" + System.lineSeparator() + "+----+---------+-------------+----------------------+--------------------------------+----------------+----------------------------+" + System.lineSeparator() + "| +I | <NULL> | 1 | 2 | abc | 1.23000 | 2020-03-01 18:39:14.000000 |" + System.lineSeparator() + "| -U | FALSE | <NULL> | 0 | | 1.00000 | 2020-03-01 18:39:14.100000 |" + System.lineSeparator() + "| +U | TRUE | 2147483647 | <NULL> | abcdefg | 12345.00000 | 2020-03-01 18:39:14.120000 |" + System.lineSeparator() + "| -D | FALSE | -2147483648 | 9223372036854775807 | <NULL> | 12345.06789 | 2020-03-01 18:39:14.123000 |" + System.lineSeparator() + "Query terminated, received a total of 4 rows" + System.lineSeparator(), terminalOutput.toString());
assertThat(mockExecutor.getNumCancelCalls(), is(1));
}
Aggregations