Search in sources :

Example 1 with StreamTableEnvironment

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);
}
Also used : Tuple5(org.apache.flink.api.java.tuple.Tuple5) Table(org.apache.flink.table.api.Table) StreamITCase(org.apache.flink.table.api.scala.stream.utils.StreamITCase) ArrayList(java.util.ArrayList) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) StreamTableEnvironment(org.apache.flink.table.api.java.StreamTableEnvironment) Row(org.apache.flink.types.Row) Test(org.junit.Test)

Example 2 with StreamTableEnvironment

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);
}
Also used : Table(org.apache.flink.table.api.Table) StreamITCase(org.apache.flink.table.api.scala.stream.utils.StreamITCase) ArrayList(java.util.ArrayList) Tuple5(org.apache.flink.api.java.tuple.Tuple5) Tuple3(org.apache.flink.api.java.tuple.Tuple3) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) StreamTableEnvironment(org.apache.flink.table.api.java.StreamTableEnvironment) Row(org.apache.flink.types.Row) Test(org.junit.Test)

Example 3 with StreamTableEnvironment

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);
}
Also used : Table(org.apache.flink.table.api.Table) StreamITCase(org.apache.flink.table.api.scala.stream.utils.StreamITCase) Tuple3(org.apache.flink.api.java.tuple.Tuple3) ArrayList(java.util.ArrayList) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) StreamTableEnvironment(org.apache.flink.table.api.java.StreamTableEnvironment) Row(org.apache.flink.types.Row) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)3 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)3 Table (org.apache.flink.table.api.Table)3 StreamTableEnvironment (org.apache.flink.table.api.java.StreamTableEnvironment)3 StreamITCase (org.apache.flink.table.api.scala.stream.utils.StreamITCase)3 Row (org.apache.flink.types.Row)3 Test (org.junit.Test)3 Tuple3 (org.apache.flink.api.java.tuple.Tuple3)2 Tuple5 (org.apache.flink.api.java.tuple.Tuple5)2