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");
}
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");
}
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);
}
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());
}
}
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);
}
Aggregations