use of org.apache.flink.table.client.gateway.ResultDescriptor in project flink by apache.
the class CliTableauResultViewTest method testEmptyStreamingResult.
@Test
public void testEmptyStreamingResult() {
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::endOfStream).build();
CliTableauResultView view = new CliTableauResultView(terminal, mockExecutor, "session", resultDescriptor);
view.displayResults();
view.close();
Assert.assertEquals("+----+---------+-------------+----------------------+--------------------------------+----------------+----------------------------+" + System.lineSeparator() + "| op | boolean | int | bigint | varchar | decimal(10, 5) | timestamp |" + System.lineSeparator() + "+----+---------+-------------+----------------------+--------------------------------+----------------+----------------------------+" + System.lineSeparator() + "Received a total of 0 row" + 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 testStreamingResult.
@Test
public void testStreamingResult() {
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.payload(streamingData.subList(streamingData.size() / 2, streamingData.size())), TypedResult::endOfStream).build();
CliTableauResultView view = new CliTableauResultView(terminal, mockExecutor, "session", resultDescriptor);
view.displayResults();
view.close();
// note: the expected result may look irregular because every CJK(Chinese/Japanese/Korean)
// character's
// width < 2 in IDE by default, every CJK character usually's width is 2, you can open this
// source file
// by vim or just cat the file to check the regular result.
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() + "| +I | TRUE | 100 | -9223372036854775808 | abcdefg111 | <NULL> | 2020-03-01 18:39:14.123456 |" + System.lineSeparator() + "| -D | <NULL> | -1 | -1 | abcdefghijklmnopqrstuvwxyz | -12345.06789 | <NULL> |" + System.lineSeparator() + "| +I | <NULL> | -1 | -1 | 这是一段中文 | -12345.06789 | 2020-03-04 18:39:14.000000 |" + System.lineSeparator() + "| -D | <NULL> | -1 | -1 | これは日本語をテストするた... | -12345.06789 | 2020-03-04 18:39:14.000000 |" + System.lineSeparator() + "+----+---------+-------------+----------------------+--------------------------------+----------------+----------------------------+" + System.lineSeparator() + "Received a total of 8 rows" + 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 LocalExecutorITCase method executeStreamQueryTable.
private void executeStreamQueryTable(Map<String, String> replaceVars, Map<String, String> configMap, String query, List<String> expectedResults) throws Exception {
final LocalExecutor executor = createLocalExecutor(Collections.singletonList(udfDependency), Configuration.fromMap(configMap));
String sessionId = executor.openSession("test-session");
assertEquals("test-session", sessionId);
initSession(executor, sessionId, replaceVars);
try {
// start job and retrieval
final ResultDescriptor desc = executeQuery(executor, sessionId, query);
assertTrue(desc.isMaterialized());
final List<String> actualResults = retrieveTableResult(executor, sessionId, desc.getResultId(), desc.getRowDataStringConverter());
TestBaseUtils.compareResultCollections(expectedResults, actualResults, Comparator.naturalOrder());
} finally {
executor.closeSession(sessionId);
}
}
use of org.apache.flink.table.client.gateway.ResultDescriptor in project flink by apache.
the class LocalExecutorITCase method testStreamQueryExecutionChangelogMultipleTimes.
@Test(timeout = 90_000L)
public void testStreamQueryExecutionChangelogMultipleTimes() throws Exception {
final URL url = getClass().getClassLoader().getResource("test-data.csv");
Objects.requireNonNull(url);
final Map<String, String> replaceVars = new HashMap<>();
replaceVars.put("$VAR_SOURCE_PATH1", url.getPath());
Configuration configuration = Configuration.fromMap(getDefaultSessionConfigMap());
final LocalExecutor executor = createLocalExecutor(Collections.singletonList(udfDependency), configuration);
String sessionId = executor.openSession("test-session");
assertEquals("test-session", sessionId);
final List<String> expectedResults = new ArrayList<>();
expectedResults.add("[47, Hello World]");
expectedResults.add("[27, Hello World]");
expectedResults.add("[37, Hello World]");
expectedResults.add("[37, Hello World]");
expectedResults.add("[47, Hello World]");
expectedResults.add("[57, Hello World!!!!]");
initSession(executor, sessionId, replaceVars);
try {
for (int i = 0; i < 3; i++) {
// start job and retrieval
final ResultDescriptor desc = executeQuery(executor, sessionId, "SELECT scalarUDF(IntegerField1, 5), StringField1 FROM TableNumber1");
assertFalse(desc.isMaterialized());
final List<String> actualResults = retrieveChangelogResult(executor, sessionId, desc.getResultId(), desc.getRowDataStringConverter());
TestBaseUtils.compareResultCollections(expectedResults, actualResults, Comparator.naturalOrder());
}
} finally {
executor.closeSession(sessionId);
}
}
use of org.apache.flink.table.client.gateway.ResultDescriptor in project flink by apache.
the class LocalExecutorITCase method testBatchQueryExecution.
@Test(timeout = 90_000L)
public void testBatchQueryExecution() throws Exception {
final URL url = getClass().getClassLoader().getResource("test-data.csv");
Objects.requireNonNull(url);
final Map<String, String> replaceVars = new HashMap<>();
replaceVars.put("$VAR_SOURCE_PATH1", url.getPath());
final Map<String, String> configMap = new HashMap<>();
configMap.put(EXECUTION_RESULT_MODE.key(), ResultMode.TABLE.name());
configMap.put(RUNTIME_MODE.key(), RuntimeExecutionMode.BATCH.name());
final Executor executor = createLocalExecutor(Collections.singletonList(udfDependency), Configuration.fromMap(configMap));
String sessionId = executor.openSession("test-session");
assertEquals("test-session", sessionId);
initSession(executor, sessionId, replaceVars);
try {
final ResultDescriptor desc = executeQuery(executor, sessionId, "SELECT *, 'ABC' FROM TestView1");
assertTrue(desc.isMaterialized());
final List<String> actualResults = retrieveTableResult(executor, sessionId, desc.getResultId(), desc.getRowDataStringConverter());
final List<String> expectedResults = new ArrayList<>();
expectedResults.add("[47, ABC]");
expectedResults.add("[27, ABC]");
expectedResults.add("[37, ABC]");
expectedResults.add("[37, ABC]");
expectedResults.add("[47, ABC]");
expectedResults.add("[57, ABC]");
TestBaseUtils.compareResultCollections(expectedResults, actualResults, Comparator.naturalOrder());
} finally {
executor.closeSession(sessionId);
}
}
Aggregations