Search in sources :

Example 1 with ResultDescriptor

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));
}
Also used : Configuration(org.apache.flink.configuration.Configuration) ResultDescriptor(org.apache.flink.table.client.gateway.ResultDescriptor) Test(org.junit.Test)

Example 2 with ResultDescriptor

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));
}
Also used : Configuration(org.apache.flink.configuration.Configuration) ResultDescriptor(org.apache.flink.table.client.gateway.ResultDescriptor) Test(org.junit.Test)

Example 3 with ResultDescriptor

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);
    }
}
Also used : ResultDescriptor(org.apache.flink.table.client.gateway.ResultDescriptor)

Example 4 with ResultDescriptor

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);
    }
}
Also used : MiniClusterResourceConfiguration(org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration) Configuration(org.apache.flink.configuration.Configuration) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ResultDescriptor(org.apache.flink.table.client.gateway.ResultDescriptor) URL(java.net.URL) Test(org.junit.Test)

Example 5 with ResultDescriptor

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);
    }
}
Also used : Executor(org.apache.flink.table.client.gateway.Executor) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ResultDescriptor(org.apache.flink.table.client.gateway.ResultDescriptor) URL(java.net.URL) Test(org.junit.Test)

Aggregations

ResultDescriptor (org.apache.flink.table.client.gateway.ResultDescriptor)16 Test (org.junit.Test)12 Configuration (org.apache.flink.configuration.Configuration)11 URL (java.net.URL)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 SqlExecutionException (org.apache.flink.table.client.gateway.SqlExecutionException)3 ExecutorService (java.util.concurrent.ExecutorService)2 MiniClusterResourceConfiguration (org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration)2 Executor (org.apache.flink.table.client.gateway.Executor)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 ReadableConfig (org.apache.flink.configuration.ReadableConfig)1 TableResultInternal (org.apache.flink.table.api.internal.TableResultInternal)1 ResolvedSchema (org.apache.flink.table.catalog.ResolvedSchema)1 TypedResult (org.apache.flink.table.client.gateway.TypedResult)1 SessionContext (org.apache.flink.table.client.gateway.context.SessionContext)1 DynamicResult (org.apache.flink.table.client.gateway.local.result.DynamicResult)1 RowDataToStringConverterImpl (org.apache.flink.table.planner.functions.casting.RowDataToStringConverterImpl)1 AttributedString (org.jline.utils.AttributedString)1