use of org.apache.flink.table.api.bridge.java.StreamTableEnvironment in project flink by apache.
the class DataStreamJavaITCase method testFromAndToChangelogStreamRetract.
@Test
public void testFromAndToChangelogStreamRetract() throws Exception {
final StreamTableEnvironment tableEnv = StreamTableEnvironment.create(env);
final List<Either<Row, Row>> inputOrOutput = Arrays.asList(input(RowKind.INSERT, "bob", 0), output(RowKind.INSERT, "bob", 0), // --
input(RowKind.UPDATE_BEFORE, "bob", 0), output(RowKind.DELETE, "bob", 0), // --
input(RowKind.UPDATE_AFTER, "bob", 1), output(RowKind.INSERT, "bob", 1), // --
input(RowKind.INSERT, "alice", 1), output(RowKind.INSERT, "alice", 1), // --
input(RowKind.INSERT, "alice", 1), output(RowKind.UPDATE_BEFORE, "alice", 1), output(RowKind.UPDATE_AFTER, "alice", 2), // --
input(RowKind.UPDATE_BEFORE, "alice", 1), output(RowKind.UPDATE_BEFORE, "alice", 2), output(RowKind.UPDATE_AFTER, "alice", 1), // --
input(RowKind.UPDATE_AFTER, "alice", 2), output(RowKind.UPDATE_BEFORE, "alice", 1), output(RowKind.UPDATE_AFTER, "alice", 3), // --
input(RowKind.UPDATE_BEFORE, "alice", 2), output(RowKind.UPDATE_BEFORE, "alice", 3), output(RowKind.UPDATE_AFTER, "alice", 1), // --
input(RowKind.UPDATE_AFTER, "alice", 100), output(RowKind.UPDATE_BEFORE, "alice", 1), output(RowKind.UPDATE_AFTER, "alice", 101));
final DataStream<Row> changelogStream = env.fromElements(getInput(inputOrOutput));
tableEnv.createTemporaryView("t", tableEnv.fromChangelogStream(changelogStream));
final Table result = tableEnv.sqlQuery("SELECT f0, SUM(f1) FROM t GROUP BY f0");
testResult(result.execute(), getOutput(inputOrOutput));
testResult(tableEnv.toChangelogStream(result), getOutput(inputOrOutput));
}
use of org.apache.flink.table.api.bridge.java.StreamTableEnvironment in project flink by apache.
the class DataStreamJavaITCase method testToDataStreamWithRow.
@Test
public void testToDataStreamWithRow() throws Exception {
final StreamTableEnvironment tableEnv = StreamTableEnvironment.create(env);
final Row[] rows = new Row[] { Row.of(12, Row.of(false, "hello"), Collections.singletonMap("world", 2.0)), Row.of(null, Row.of(false, null), Collections.singletonMap("world", 1.0)) };
final Table table = tableEnv.fromValues((Object[]) rows);
testResult(tableEnv.toDataStream(table), rows);
}
use of org.apache.flink.table.api.bridge.java.StreamTableEnvironment 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.bridge.java.StreamTableEnvironment 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.bridge.java.StreamTableEnvironment 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