Search in sources :

Example 16 with TableDescriptor

use of org.apache.flink.table.api.TableDescriptor in project flink by apache.

the class WrapJsonAggFunctionArgumentsRuleTest method testJsonArrayAggInGroupWindow.

@Test
public void testJsonArrayAggInGroupWindow() {
    final TableDescriptor sourceDescriptor = TableFactoryHarness.newBuilder().schema(Schema.newBuilder().column("f0", INT()).build()).unboundedScanSource().build();
    util.tableEnv().createTable("T", sourceDescriptor);
    util.verifyRelPlan("SELECT f0, JSON_ARRAYAGG(f0) FROM T GROUP BY f0");
}
Also used : TableDescriptor(org.apache.flink.table.api.TableDescriptor) Test(org.junit.Test)

Example 17 with TableDescriptor

use of org.apache.flink.table.api.TableDescriptor in project flink by apache.

the class PushFilterPastChangelogNormalizeRuleTest method testWithMultipleFilters.

@Test
public void testWithMultipleFilters() {
    final TableDescriptor sourceDescriptor = TableFactoryHarness.newBuilder().schema(Schema.newBuilder().column("f0", STRING()).column("f1", INT().notNull()).column("f2", STRING()).primaryKey("f1").build()).unboundedScanSource(ChangelogMode.upsert()).build();
    util.tableEnv().createTable("T", sourceDescriptor);
    // Only the first filter (f1 < 10) can be pushed
    util.verifyRelPlan("SELECT f1, SUM(f1) AS `sum` FROM T WHERE f1 < 10 AND (f1 > 3 OR f2 IS NULL) GROUP BY f1");
}
Also used : TableDescriptor(org.apache.flink.table.api.TableDescriptor) Test(org.junit.Test)

Example 18 with TableDescriptor

use of org.apache.flink.table.api.TableDescriptor in project flink by apache.

the class CommonExecSinkITCase method testStreamRecordTimestampInserterNotApplied.

@Test
public void testStreamRecordTimestampInserterNotApplied() {
    final StreamTableEnvironment tableEnv = StreamTableEnvironment.create(env);
    final SharedReference<List<Long>> timestamps = sharedObjects.add(new ArrayList<>());
    final List<Row> rows = Arrays.asList(Row.of(1, "foo", Instant.parse("2020-11-10T11:34:56.123Z")), Row.of(2, "foo", Instant.parse("2020-11-10T12:34:56.789Z")), Row.of(3, "foo", Instant.parse("2020-11-11T10:11:22.777Z")), Row.of(4, "foo", Instant.parse("2020-11-11T10:11:23.888Z")));
    final TableDescriptor sourceDescriptor = TableFactoryHarness.newBuilder().schema(schemaStreamRecordTimestampInserter(false)).source(new TestSource(rows)).sink(buildRuntimeSinkProvider(new TestTimestampWriter(timestamps))).build();
    tableEnv.createTable("T1", sourceDescriptor);
    assertPlan(tableEnv, "INSERT INTO T1 SELECT * FROM T1", false);
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) StreamTableEnvironment(org.apache.flink.table.api.bridge.java.StreamTableEnvironment) Row(org.apache.flink.types.Row) TableDescriptor(org.apache.flink.table.api.TableDescriptor) Test(org.junit.Test)

Example 19 with TableDescriptor

use of org.apache.flink.table.api.TableDescriptor in project flink by apache.

the class CommonExecSinkITCase method testFromValuesWatermarkPropagation.

@Test
public void testFromValuesWatermarkPropagation() throws Exception {
    final StreamTableEnvironment tableEnv = StreamTableEnvironment.create(env);
    final SharedReference<List<Long>> watermarks = sharedObjects.add(new ArrayList<>());
    final SinkFunction<RowData> sinkFunction = new SinkFunction<RowData>() {

        @Override
        public void writeWatermark(org.apache.flink.api.common.eventtime.Watermark watermark) {
            addElement(watermarks, watermark.getTimestamp());
        }
    };
    final TableDescriptor sinkDescriptor = TableFactoryHarness.newBuilder().sink(new TableFactoryHarness.SinkBase() {

        @Override
        public DataStreamSinkProvider getSinkRuntimeProvider(DynamicTableSink.Context context) {
            return (providerContext, dataStream) -> dataStream.addSink(sinkFunction);
        }
    }).build();
    final Table source = tableEnv.fromValues(DataTypes.ROW(DataTypes.FIELD("a", DataTypes.INT())), Row.of(1), Row.of(2), Row.of(3));
    source.executeInsert(sinkDescriptor).await();
    assertThat(watermarks.get().size()).isEqualTo(env.getParallelism());
    for (Long watermark : watermarks.get()) {
        assertThat(watermark).isEqualTo(Watermark.MAX_WATERMARK.getTimestamp());
    }
}
Also used : StreamTableEnvironment(org.apache.flink.table.api.bridge.java.StreamTableEnvironment) Arrays(java.util.Arrays) Schema(org.apache.flink.table.api.Schema) TableDescriptor(org.apache.flink.table.api.TableDescriptor) SinkV1Adapter(org.apache.flink.streaming.api.transformations.SinkV1Adapter) SharedObjects(org.apache.flink.testutils.junit.SharedObjects) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ExplainDetail(org.apache.flink.table.api.ExplainDetail) ExceptionUtils(org.apache.flink.util.ExceptionUtils) TestSink(org.apache.flink.streaming.runtime.operators.sink.TestSink) Parameterized(org.junit.runners.Parameterized) AbstractTestBase(org.apache.flink.test.util.AbstractTestBase) TableFactoryHarness(org.apache.flink.table.planner.factories.TableFactoryHarness) DynamicTableSource(org.apache.flink.table.connector.source.DynamicTableSource) SinkFunction(org.apache.flink.streaming.api.functions.sink.SinkFunction) DynamicTableSink(org.apache.flink.table.connector.sink.DynamicTableSink) Collection(java.util.Collection) Table(org.apache.flink.table.api.Table) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) List(java.util.List) DataStreamSinkProvider(org.apache.flink.table.connector.sink.DataStreamSinkProvider) ValidationException(org.apache.flink.table.api.ValidationException) TableResult(org.apache.flink.table.api.TableResult) Row(org.apache.flink.types.Row) NotNull(org.jetbrains.annotations.NotNull) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) Assert.assertThrows(org.junit.Assert.assertThrows) RunWith(org.junit.runner.RunWith) Watermark(org.apache.flink.streaming.api.watermark.Watermark) ScanTableSource(org.apache.flink.table.connector.source.ScanTableSource) ArrayList(java.util.ArrayList) SinkV2Provider(org.apache.flink.table.connector.sink.SinkV2Provider) TABLE_EXEC_SINK_TYPE_LENGTH_ENFORCER(org.apache.flink.table.api.config.ExecutionConfigOptions.TABLE_EXEC_SINK_TYPE_LENGTH_ENFORCER) SourceFunction(org.apache.flink.streaming.api.functions.source.SourceFunction) TABLE_EXEC_SINK_NOT_NULL_ENFORCER(org.apache.flink.table.api.config.ExecutionConfigOptions.TABLE_EXEC_SINK_NOT_NULL_ENFORCER) SourceFunctionProvider(org.apache.flink.table.connector.source.SourceFunctionProvider) SharedReference(org.apache.flink.testutils.junit.SharedReference) INT(org.apache.flink.table.api.DataTypes.INT) Before(org.junit.Before) RowData(org.apache.flink.table.data.RowData) DataTypes(org.apache.flink.table.api.DataTypes) SinkProvider(org.apache.flink.table.connector.sink.SinkProvider) Test(org.junit.Test) ExecutionException(java.util.concurrent.ExecutionException) Rule(org.junit.Rule) ExecutionConfigOptions(org.apache.flink.table.api.config.ExecutionConfigOptions) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Table(org.apache.flink.table.api.Table) TableDescriptor(org.apache.flink.table.api.TableDescriptor) RowData(org.apache.flink.table.data.RowData) SinkFunction(org.apache.flink.streaming.api.functions.sink.SinkFunction) List(java.util.List) ArrayList(java.util.ArrayList) StreamTableEnvironment(org.apache.flink.table.api.bridge.java.StreamTableEnvironment) Watermark(org.apache.flink.streaming.api.watermark.Watermark) Test(org.junit.Test)

Example 20 with TableDescriptor

use of org.apache.flink.table.api.TableDescriptor in project flink by apache.

the class CommonExecSinkITCase method testStreamRecordTimestampInserterDataStreamSinkProvider.

@Test
public void testStreamRecordTimestampInserterDataStreamSinkProvider() throws ExecutionException, InterruptedException {
    final StreamTableEnvironment tableEnv = StreamTableEnvironment.create(env);
    final SharedReference<List<Long>> timestamps = sharedObjects.add(new ArrayList<>());
    final List<Row> rows = Arrays.asList(Row.of(1, "foo", Instant.parse("2020-11-10T11:34:56.123Z")), Row.of(2, "foo", Instant.parse("2020-11-10T12:34:56.789Z")), Row.of(3, "foo", Instant.parse("2020-11-11T10:11:22.777Z")), Row.of(4, "foo", Instant.parse("2020-11-11T10:11:23.888Z")));
    final SinkFunction<RowData> sinkFunction = new SinkFunction<RowData>() {

        @Override
        public void invoke(RowData value, Context context) {
            addElement(timestamps, context.timestamp());
        }
    };
    final TableDescriptor sourceDescriptor = TableFactoryHarness.newBuilder().schema(schemaStreamRecordTimestampInserter(true)).source(new TestSource(rows)).sink(new TableFactoryHarness.SinkBase() {

        @Override
        public DataStreamSinkProvider getSinkRuntimeProvider(DynamicTableSink.Context context) {
            return (providerContext, dataStream) -> dataStream.addSink(sinkFunction);
        }
    }).build();
    tableEnv.createTable("T1", sourceDescriptor);
    final String sqlStmt = "INSERT INTO T1 SELECT * FROM T1";
    assertPlan(tableEnv, sqlStmt, true);
    tableEnv.executeSql(sqlStmt).await();
    Collections.sort(timestamps.get());
    assertTimestampResults(timestamps, rows);
}
Also used : StreamTableEnvironment(org.apache.flink.table.api.bridge.java.StreamTableEnvironment) Arrays(java.util.Arrays) Schema(org.apache.flink.table.api.Schema) TableDescriptor(org.apache.flink.table.api.TableDescriptor) SinkV1Adapter(org.apache.flink.streaming.api.transformations.SinkV1Adapter) SharedObjects(org.apache.flink.testutils.junit.SharedObjects) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ExplainDetail(org.apache.flink.table.api.ExplainDetail) ExceptionUtils(org.apache.flink.util.ExceptionUtils) TestSink(org.apache.flink.streaming.runtime.operators.sink.TestSink) Parameterized(org.junit.runners.Parameterized) AbstractTestBase(org.apache.flink.test.util.AbstractTestBase) TableFactoryHarness(org.apache.flink.table.planner.factories.TableFactoryHarness) DynamicTableSource(org.apache.flink.table.connector.source.DynamicTableSource) SinkFunction(org.apache.flink.streaming.api.functions.sink.SinkFunction) DynamicTableSink(org.apache.flink.table.connector.sink.DynamicTableSink) Collection(java.util.Collection) Table(org.apache.flink.table.api.Table) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) List(java.util.List) DataStreamSinkProvider(org.apache.flink.table.connector.sink.DataStreamSinkProvider) ValidationException(org.apache.flink.table.api.ValidationException) TableResult(org.apache.flink.table.api.TableResult) Row(org.apache.flink.types.Row) NotNull(org.jetbrains.annotations.NotNull) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) Assert.assertThrows(org.junit.Assert.assertThrows) RunWith(org.junit.runner.RunWith) Watermark(org.apache.flink.streaming.api.watermark.Watermark) ScanTableSource(org.apache.flink.table.connector.source.ScanTableSource) ArrayList(java.util.ArrayList) SinkV2Provider(org.apache.flink.table.connector.sink.SinkV2Provider) TABLE_EXEC_SINK_TYPE_LENGTH_ENFORCER(org.apache.flink.table.api.config.ExecutionConfigOptions.TABLE_EXEC_SINK_TYPE_LENGTH_ENFORCER) SourceFunction(org.apache.flink.streaming.api.functions.source.SourceFunction) TABLE_EXEC_SINK_NOT_NULL_ENFORCER(org.apache.flink.table.api.config.ExecutionConfigOptions.TABLE_EXEC_SINK_NOT_NULL_ENFORCER) SourceFunctionProvider(org.apache.flink.table.connector.source.SourceFunctionProvider) SharedReference(org.apache.flink.testutils.junit.SharedReference) INT(org.apache.flink.table.api.DataTypes.INT) Before(org.junit.Before) RowData(org.apache.flink.table.data.RowData) DataTypes(org.apache.flink.table.api.DataTypes) SinkProvider(org.apache.flink.table.connector.sink.SinkProvider) Test(org.junit.Test) ExecutionException(java.util.concurrent.ExecutionException) Rule(org.junit.Rule) ExecutionConfigOptions(org.apache.flink.table.api.config.ExecutionConfigOptions) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) TableDescriptor(org.apache.flink.table.api.TableDescriptor) RowData(org.apache.flink.table.data.RowData) SinkFunction(org.apache.flink.streaming.api.functions.sink.SinkFunction) List(java.util.List) ArrayList(java.util.ArrayList) StreamTableEnvironment(org.apache.flink.table.api.bridge.java.StreamTableEnvironment) Row(org.apache.flink.types.Row) Test(org.junit.Test)

Aggregations

TableDescriptor (org.apache.flink.table.api.TableDescriptor)22 Test (org.junit.Test)20 ArrayList (java.util.ArrayList)11 List (java.util.List)9 StreamTableEnvironment (org.apache.flink.table.api.bridge.java.StreamTableEnvironment)7 Row (org.apache.flink.types.Row)7 TableResult (org.apache.flink.table.api.TableResult)4 Instant (java.time.Instant)2 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 ExecutionException (java.util.concurrent.ExecutionException)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Collectors (java.util.stream.Collectors)2 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)2 SinkFunction (org.apache.flink.streaming.api.functions.sink.SinkFunction)2 SourceFunction (org.apache.flink.streaming.api.functions.source.SourceFunction)2 SinkV1Adapter (org.apache.flink.streaming.api.transformations.SinkV1Adapter)2 Watermark (org.apache.flink.streaming.api.watermark.Watermark)2 TestSink (org.apache.flink.streaming.runtime.operators.sink.TestSink)2