Search in sources :

Example 11 with ResultDescriptor

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

Example 12 with ResultDescriptor

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

Example 13 with ResultDescriptor

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

Example 14 with ResultDescriptor

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

Example 15 with ResultDescriptor

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