use of org.apache.flink.table.api.java.StreamTableEnvironment in project flink by apache.
the class SqlITCase method testFilter.
@Test
public void testFilter() throws Exception {
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
StreamTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env);
StreamITCase.clear();
DataStream<Tuple5<Integer, Long, Integer, String, Long>> ds = StreamTestData.get5TupleDataStream(env);
tableEnv.registerDataStream("MyTable", ds, "a, b, c, d, e");
String sqlQuery = "SELECT a, b, e FROM MyTable WHERE c < 4";
Table result = tableEnv.sql(sqlQuery);
DataStream<Row> resultSet = tableEnv.toDataStream(result, Row.class);
resultSet.addSink(new StreamITCase.StringSink());
env.execute();
List<String> expected = new ArrayList<>();
expected.add("1,1,1");
expected.add("2,2,2");
expected.add("2,3,1");
expected.add("3,4,2");
StreamITCase.compareWithList(expected);
}
use of org.apache.flink.table.api.java.StreamTableEnvironment in project flink by apache.
the class SqlITCase method testUnion.
@Test
public void testUnion() throws Exception {
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
StreamTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env);
StreamITCase.clear();
DataStream<Tuple3<Integer, Long, String>> ds1 = StreamTestData.getSmall3TupleDataSet(env);
Table t1 = tableEnv.fromDataStream(ds1, "a,b,c");
tableEnv.registerTable("T1", t1);
DataStream<Tuple5<Integer, Long, Integer, String, Long>> ds2 = StreamTestData.get5TupleDataStream(env);
tableEnv.registerDataStream("T2", ds2, "a, b, d, c, e");
String sqlQuery = "SELECT * FROM T1 " + "UNION ALL " + "(SELECT a, b, c FROM T2 WHERE a < 3)";
Table result = tableEnv.sql(sqlQuery);
DataStream<Row> resultSet = tableEnv.toDataStream(result, Row.class);
resultSet.addSink(new StreamITCase.StringSink());
env.execute();
List<String> expected = new ArrayList<>();
expected.add("1,1,Hi");
expected.add("2,2,Hello");
expected.add("3,2,Hello world");
expected.add("1,1,Hallo");
expected.add("2,2,Hallo Welt");
expected.add("2,3,Hallo Welt wie");
StreamITCase.compareWithList(expected);
}
use of org.apache.flink.table.api.java.StreamTableEnvironment in project flink by apache.
the class SqlITCase method testSelect.
@Test
public void testSelect() throws Exception {
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
StreamTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env);
StreamITCase.clear();
DataStream<Tuple3<Integer, Long, String>> ds = StreamTestData.getSmall3TupleDataSet(env);
Table in = tableEnv.fromDataStream(ds, "a,b,c");
tableEnv.registerTable("MyTable", in);
String sqlQuery = "SELECT * FROM MyTable";
Table result = tableEnv.sql(sqlQuery);
DataStream<Row> resultSet = tableEnv.toDataStream(result, Row.class);
resultSet.addSink(new StreamITCase.StringSink());
env.execute();
List<String> expected = new ArrayList<>();
expected.add("1,1,Hi");
expected.add("2,2,Hello");
expected.add("3,2,Hello world");
StreamITCase.compareWithList(expected);
}
Aggregations