use of org.apache.flink.table.api.DataTypes.MAP in project flink by apache.
the class DataStreamJavaITCase method testTableStreamConversionBatch.
@Test
public void testTableStreamConversionBatch() throws Exception {
env.setRuntimeMode(RuntimeExecutionMode.BATCH);
DataStreamSource<Row> streamSource = env.fromElements(Row.of("Alice"), Row.of("alice"), Row.of("lily"), Row.of("Bob"), Row.of("lily"), Row.of("lily"));
StreamTableEnvironment tableEnvironment = StreamTableEnvironment.create(env);
Table sourceTable = tableEnvironment.fromDataStream(streamSource).as("word");
tableEnvironment.createTemporaryView("tmp_table", sourceTable);
Table resultTable = tableEnvironment.sqlQuery("select UPPER(word) as word from tmp_table");
SingleOutputStreamOperator<Tuple2<String, Integer>> resultStream = tableEnvironment.toDataStream(resultTable).map(row -> (String) row.getField("word")).returns(TypeInformation.of(String.class)).map(s -> new Tuple2<>(s, 1)).returns(TypeInformation.of(new TypeHint<Tuple2<String, Integer>>() {
})).keyBy(tuple -> tuple.f0).sum(1);
testResult(resultStream, new Tuple2<>("ALICE", 2), new Tuple2<>("BOB", 1), new Tuple2<>("LILY", 3));
}
Aggregations