Java Code Examples for org.apache.flink.table.runtime.utils.StreamITCase#clear()
The following examples show how to use
org.apache.flink.table.runtime.utils.StreamITCase#clear() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JavaSqlITCase.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Test public void testSelect() throws Exception { StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); StreamTableEnvironment tableEnv = StreamTableEnvironment.create(env); StreamITCase.clear(); DataStream<Tuple3<Integer, Long, String>> ds = JavaStreamTestData.getSmall3TupleDataSet(env); Table in = tableEnv.fromDataStream(ds, "a,b,c"); tableEnv.registerTable("MyTable", in); String sqlQuery = "SELECT * FROM MyTable"; Table result = tableEnv.sqlQuery(sqlQuery); DataStream<Row> resultSet = tableEnv.toAppendStream(result, Row.class); resultSet.addSink(new StreamITCase.StringSink<Row>()); 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); }
Example 2
Source File: JavaSqlITCase.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Test public void testFilter() throws Exception { StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); StreamTableEnvironment tableEnv = StreamTableEnvironment.create(env); StreamITCase.clear(); DataStream<Tuple5<Integer, Long, Integer, String, Long>> ds = JavaStreamTestData.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.sqlQuery(sqlQuery); DataStream<Row> resultSet = tableEnv.toAppendStream(result, Row.class); resultSet.addSink(new StreamITCase.StringSink<Row>()); 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); }
Example 3
Source File: JavaSqlITCase.java From flink with Apache License 2.0 | 6 votes |
@Test public void testSelect() throws Exception { StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); StreamTableEnvironment tableEnv = StreamTableEnvironment.create(env); StreamITCase.clear(); DataStream<Tuple3<Integer, Long, String>> ds = JavaStreamTestData.getSmall3TupleDataSet(env); Table in = tableEnv.fromDataStream(ds, "a,b,c"); tableEnv.registerTable("MyTable", in); String sqlQuery = "SELECT * FROM MyTable"; Table result = tableEnv.sqlQuery(sqlQuery); DataStream<Row> resultSet = tableEnv.toAppendStream(result, Row.class); resultSet.addSink(new StreamITCase.StringSink<Row>()); 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); }
Example 4
Source File: JavaSqlITCase.java From flink with Apache License 2.0 | 6 votes |
@Test public void testFilter() throws Exception { StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); StreamTableEnvironment tableEnv = StreamTableEnvironment.create(env); StreamITCase.clear(); DataStream<Tuple5<Integer, Long, Integer, String, Long>> ds = JavaStreamTestData.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.sqlQuery(sqlQuery); DataStream<Row> resultSet = tableEnv.toAppendStream(result, Row.class); resultSet.addSink(new StreamITCase.StringSink<Row>()); 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); }
Example 5
Source File: JavaSqlITCase.java From flink with Apache License 2.0 | 6 votes |
@Test public void testSelect() throws Exception { StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); EnvironmentSettings settings = EnvironmentSettings.newInstance().useOldPlanner().build(); StreamTableEnvironment tableEnv = StreamTableEnvironment.create(env, settings); StreamITCase.clear(); DataStream<Tuple3<Integer, Long, String>> ds = JavaStreamTestData.getSmall3TupleDataSet(env); Table in = tableEnv.fromDataStream(ds, $("a"), $("b"), $("c")); tableEnv.registerTable("MyTable", in); String sqlQuery = "SELECT * FROM MyTable"; Table result = tableEnv.sqlQuery(sqlQuery); DataStream<Row> resultSet = tableEnv.toAppendStream(result, Row.class); resultSet.addSink(new StreamITCase.StringSink<Row>()); 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); }
Example 6
Source File: JavaSqlITCase.java From flink with Apache License 2.0 | 6 votes |
@Test public void testFilter() throws Exception { StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); EnvironmentSettings settings = EnvironmentSettings.newInstance().useOldPlanner().build(); StreamTableEnvironment tableEnv = StreamTableEnvironment.create(env, settings); StreamITCase.clear(); DataStream<Tuple5<Integer, Long, Integer, String, Long>> ds = JavaStreamTestData.get5TupleDataStream(env); tableEnv.createTemporaryView("MyTable", ds, $("a"), $("b"), $("c"), $("d"), $("e")); String sqlQuery = "SELECT a, b, e FROM MyTable WHERE c < 4"; Table result = tableEnv.sqlQuery(sqlQuery); DataStream<Row> resultSet = tableEnv.toAppendStream(result, Row.class); resultSet.addSink(new StreamITCase.StringSink<Row>()); 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); }
Example 7
Source File: JavaSqlITCase.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test public void testRowRegisterRowWithNames() throws Exception { StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); StreamTableEnvironment tableEnv = StreamTableEnvironment.create(env); StreamITCase.clear(); List<Row> data = new ArrayList<>(); data.add(Row.of(1, 1L, "Hi")); data.add(Row.of(2, 2L, "Hello")); data.add(Row.of(3, 2L, "Hello world")); TypeInformation<?>[] types = { BasicTypeInfo.INT_TYPE_INFO, BasicTypeInfo.LONG_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO}; String[] names = {"a", "b", "c"}; RowTypeInfo typeInfo = new RowTypeInfo(types, names); DataStream<Row> ds = env.fromCollection(data).returns(typeInfo); Table in = tableEnv.fromDataStream(ds, "a,b,c"); tableEnv.registerTable("MyTableRow", in); String sqlQuery = "SELECT a,c FROM MyTableRow"; Table result = tableEnv.sqlQuery(sqlQuery); DataStream<Row> resultSet = tableEnv.toAppendStream(result, Row.class); resultSet.addSink(new StreamITCase.StringSink<Row>()); env.execute(); List<String> expected = new ArrayList<>(); expected.add("1,Hi"); expected.add("2,Hello"); expected.add("3,Hello world"); StreamITCase.compareWithList(expected); }
Example 8
Source File: JavaSqlITCase.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test public void testUnion() throws Exception { StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); StreamTableEnvironment tableEnv = StreamTableEnvironment.create(env); StreamITCase.clear(); DataStream<Tuple3<Integer, Long, String>> ds1 = JavaStreamTestData.getSmall3TupleDataSet(env); Table t1 = tableEnv.fromDataStream(ds1, "a,b,c"); tableEnv.registerTable("T1", t1); DataStream<Tuple5<Integer, Long, Integer, String, Long>> ds2 = JavaStreamTestData.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.sqlQuery(sqlQuery); DataStream<Row> resultSet = tableEnv.toAppendStream(result, Row.class); resultSet.addSink(new StreamITCase.StringSink<Row>()); 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); }
Example 9
Source File: HBaseConnectorITCase.java From flink with Apache License 2.0 | 5 votes |
@Test public void testHBaseLookupFunction() throws Exception { StreamExecutionEnvironment streamEnv = StreamExecutionEnvironment.getExecutionEnvironment(); StreamTableEnvironment streamTableEnv = StreamTableEnvironment.create(streamEnv, streamSettings); StreamITCase.clear(); // prepare a source table DataStream<Row> ds = streamEnv.fromCollection(testData2).returns(testTypeInfo2); Table in = streamTableEnv.fromDataStream(ds, "a, b, c"); streamTableEnv.registerTable("src", in); Map<String, String> tableProperties = hbaseTableProperties(); TableSource source = TableFactoryService .find(HBaseTableFactory.class, tableProperties) .createTableSource(tableProperties); streamTableEnv.registerFunction("hbaseLookup", ((HBaseTableSource) source).getLookupFunction(new String[]{ROWKEY})); // perform a temporal table join query String sqlQuery = "SELECT a,family1.col1, family3.col3 FROM src, LATERAL TABLE(hbaseLookup(a))"; Table result = streamTableEnv.sqlQuery(sqlQuery); DataStream<Row> resultSet = streamTableEnv.toAppendStream(result, Row.class); resultSet.addSink(new StreamITCase.StringSink<>()); streamEnv.execute(); List<String> expected = new ArrayList<>(); expected.add("1,10,Welt-1"); expected.add("2,20,Welt-2"); expected.add("3,30,Welt-3"); expected.add("3,30,Welt-3"); StreamITCase.compareWithList(expected); }
Example 10
Source File: HBaseConnectorITCase.java From flink with Apache License 2.0 | 5 votes |
@Test public void testHBaseLookupTableSource() throws Exception { if (OLD_PLANNER.equals(planner)) { // lookup table source is only supported in blink planner, skip for old planner return; } StreamExecutionEnvironment streamEnv = StreamExecutionEnvironment.getExecutionEnvironment(); StreamTableEnvironment streamTableEnv = StreamTableEnvironment.create(streamEnv, streamSettings); StreamITCase.clear(); // prepare a source table String srcTableName = "src"; DataStream<Row> ds = streamEnv.fromCollection(testData2).returns(testTypeInfo2); Table in = streamTableEnv.fromDataStream(ds, "a, b, c, proc.proctime"); streamTableEnv.registerTable(srcTableName, in); Map<String, String> tableProperties = hbaseTableProperties(); TableSource source = TableFactoryService .find(HBaseTableFactory.class, tableProperties) .createTableSource(tableProperties); streamTableEnv.registerTableSource("hbaseLookup", source); // perform a temporal table join query String query = "SELECT a,family1.col1, family3.col3 FROM src " + "JOIN hbaseLookup FOR SYSTEM_TIME AS OF src.proc as h ON src.a = h.rk"; Table result = streamTableEnv.sqlQuery(query); DataStream<Row> resultSet = streamTableEnv.toAppendStream(result, Row.class); resultSet.addSink(new StreamITCase.StringSink<>()); streamEnv.execute(); List<String> expected = new ArrayList<>(); expected.add("1,10,Welt-1"); expected.add("2,20,Welt-2"); expected.add("3,30,Welt-3"); expected.add("3,30,Welt-3"); StreamITCase.compareWithList(expected); }
Example 11
Source File: JavaSqlITCase.java From flink with Apache License 2.0 | 5 votes |
@Test public void testRowRegisterRowWithNames() throws Exception { StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); StreamTableEnvironment tableEnv = StreamTableEnvironment.create(env); StreamITCase.clear(); List<Row> data = new ArrayList<>(); data.add(Row.of(1, 1L, "Hi")); data.add(Row.of(2, 2L, "Hello")); data.add(Row.of(3, 2L, "Hello world")); TypeInformation<?>[] types = { BasicTypeInfo.INT_TYPE_INFO, BasicTypeInfo.LONG_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO}; String[] names = {"a", "b", "c"}; RowTypeInfo typeInfo = new RowTypeInfo(types, names); DataStream<Row> ds = env.fromCollection(data).returns(typeInfo); Table in = tableEnv.fromDataStream(ds, "a,b,c"); tableEnv.registerTable("MyTableRow", in); String sqlQuery = "SELECT a,c FROM MyTableRow"; Table result = tableEnv.sqlQuery(sqlQuery); DataStream<Row> resultSet = tableEnv.toAppendStream(result, Row.class); resultSet.addSink(new StreamITCase.StringSink<Row>()); env.execute(); List<String> expected = new ArrayList<>(); expected.add("1,Hi"); expected.add("2,Hello"); expected.add("3,Hello world"); StreamITCase.compareWithList(expected); }
Example 12
Source File: JavaSqlITCase.java From flink with Apache License 2.0 | 5 votes |
@Test public void testUnion() throws Exception { StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); StreamTableEnvironment tableEnv = StreamTableEnvironment.create(env); StreamITCase.clear(); DataStream<Tuple3<Integer, Long, String>> ds1 = JavaStreamTestData.getSmall3TupleDataSet(env); Table t1 = tableEnv.fromDataStream(ds1, "a,b,c"); tableEnv.registerTable("T1", t1); DataStream<Tuple5<Integer, Long, Integer, String, Long>> ds2 = JavaStreamTestData.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.sqlQuery(sqlQuery); DataStream<Row> resultSet = tableEnv.toAppendStream(result, Row.class); resultSet.addSink(new StreamITCase.StringSink<Row>()); 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); }
Example 13
Source File: JavaSqlITCase.java From flink with Apache License 2.0 | 5 votes |
@Test public void testRowRegisterRowWithNames() throws Exception { StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); EnvironmentSettings settings = EnvironmentSettings.newInstance().useOldPlanner().build(); StreamTableEnvironment tableEnv = StreamTableEnvironment.create(env, settings); StreamITCase.clear(); List<Row> data = new ArrayList<>(); data.add(Row.of(1, 1L, "Hi")); data.add(Row.of(2, 2L, "Hello")); data.add(Row.of(3, 2L, "Hello world")); TypeInformation<?>[] types = { BasicTypeInfo.INT_TYPE_INFO, BasicTypeInfo.LONG_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO}; String[] names = {"a", "b", "c"}; RowTypeInfo typeInfo = new RowTypeInfo(types, names); DataStream<Row> ds = env.fromCollection(data).returns(typeInfo); Table in = tableEnv.fromDataStream(ds, $("a"), $("b"), $("c")); tableEnv.registerTable("MyTableRow", in); String sqlQuery = "SELECT a,c FROM MyTableRow"; Table result = tableEnv.sqlQuery(sqlQuery); DataStream<Row> resultSet = tableEnv.toAppendStream(result, Row.class); resultSet.addSink(new StreamITCase.StringSink<Row>()); env.execute(); List<String> expected = new ArrayList<>(); expected.add("1,Hi"); expected.add("2,Hello"); expected.add("3,Hello world"); StreamITCase.compareWithList(expected); }
Example 14
Source File: JavaSqlITCase.java From flink with Apache License 2.0 | 5 votes |
@Test public void testUnion() throws Exception { StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); EnvironmentSettings settings = EnvironmentSettings.newInstance().useOldPlanner().build(); StreamTableEnvironment tableEnv = StreamTableEnvironment.create(env, settings); StreamITCase.clear(); DataStream<Tuple3<Integer, Long, String>> ds1 = JavaStreamTestData.getSmall3TupleDataSet(env); Table t1 = tableEnv.fromDataStream(ds1, $("a"), $("b"), $("c")); tableEnv.registerTable("T1", t1); DataStream<Tuple5<Integer, Long, Integer, String, Long>> ds2 = JavaStreamTestData.get5TupleDataStream(env); tableEnv.createTemporaryView("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.sqlQuery(sqlQuery); DataStream<Row> resultSet = tableEnv.toAppendStream(result, Row.class); resultSet.addSink(new StreamITCase.StringSink<Row>()); 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); }
Example 15
Source File: JDBCLookupFunctionITCase.java From flink with Apache License 2.0 | 4 votes |
@Test public void test() throws Exception { StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); StreamTableEnvironment tEnv = StreamTableEnvironment.create(env); StreamITCase.clear(); Table t = tEnv.fromDataStream(env.fromCollection(Arrays.asList( new Tuple2<>(1, 1), new Tuple2<>(1, 1), new Tuple2<>(2, 3), new Tuple2<>(2, 5), new Tuple2<>(3, 5), new Tuple2<>(3, 8) )), "id1, id2"); tEnv.registerTable("T", t); JDBCTableSource.Builder builder = JDBCTableSource.builder() .setOptions(JDBCOptions.builder() .setDBUrl(DB_URL) .setTableName(LOOKUP_TABLE) .build()) .setSchema(TableSchema.builder().fields( new String[]{"id1", "id2", "comment1", "comment2"}, new DataType[]{DataTypes.INT(), DataTypes.INT(), DataTypes.STRING(), DataTypes.STRING()}) .build()); if (useCache) { builder.setLookupOptions(JDBCLookupOptions.builder() .setCacheMaxSize(1000).setCacheExpireMs(1000 * 1000).build()); } tEnv.registerFunction("jdbcLookup", builder.build().getLookupFunction(t.getSchema().getFieldNames())); String sqlQuery = "SELECT id1, id2, comment1, comment2 FROM T, " + "LATERAL TABLE(jdbcLookup(id1, id2)) AS S(l_id1, l_id2, comment1, comment2)"; Table result = tEnv.sqlQuery(sqlQuery); DataStream<Row> resultSet = tEnv.toAppendStream(result, Row.class); resultSet.addSink(new StreamITCase.StringSink<>()); env.execute(); List<String> expected = new ArrayList<>(); expected.add("1,1,11-c1-v1,11-c2-v1"); expected.add("1,1,11-c1-v1,11-c2-v1"); expected.add("1,1,11-c1-v2,11-c2-v2"); expected.add("1,1,11-c1-v2,11-c2-v2"); expected.add("2,3,null,23-c2"); expected.add("2,5,25-c1,25-c2"); expected.add("3,8,38-c1,38-c2"); StreamITCase.compareWithList(expected); }
Example 16
Source File: ValuesITCase.java From flink with Apache License 2.0 | 4 votes |
@Test public void testTypeConversions() throws Exception { List<Row> data = Arrays.asList( Row.of(1, "ABC", java.sql.Timestamp.valueOf("2000-12-12 12:30:57.12"), Row.of(1, "ABC", Arrays.asList(1, 2, 3))), Row.of(Math.PI, "ABC", LocalDateTime.parse("2000-12-12T12:30:57.123456"), Row.of(Math.PI, "ABC", Arrays.asList(1L, 2L, 3L))), Row.of(3.1f, "DEF", LocalDateTime.parse("2000-12-12T12:30:57.1234567"), Row.of(3.1f, "DEF", Arrays.asList(1D, 2D, 3D))), Row.of(99L, "DEFG", LocalDateTime.parse("2000-12-12T12:30:57.12345678"), Row.of(99L, "DEFG", Arrays.asList(1f, 2f, 3f))), Row.of(0d, "D", LocalDateTime.parse("2000-12-12T12:30:57.123"), Row.of(0d, "D", Arrays.asList(1, 2, 3))) ); DataType rowType = DataTypes.ROW( DataTypes.FIELD("a", TypeConversions.fromLegacyInfoToDataType(Types.BIG_DEC)), DataTypes.FIELD("b", TypeConversions.fromLegacyInfoToDataType(Types.STRING)), DataTypes.FIELD("c", TypeConversions.fromLegacyInfoToDataType(Types.SQL_TIMESTAMP)), DataTypes.FIELD( "row", DataTypes.ROW( DataTypes.FIELD("a", TypeConversions.fromLegacyInfoToDataType(Types.BIG_DEC)), DataTypes.FIELD("c", TypeConversions.fromLegacyInfoToDataType(Types.STRING)), DataTypes.FIELD("d", TypeConversions.fromLegacyInfoToDataType(Types.OBJECT_ARRAY(Types.BIG_DEC)))) ) ); StreamExecutionEnvironment streamExecEnvironment = StreamExecutionEnvironment.getExecutionEnvironment(); EnvironmentSettings settings = EnvironmentSettings.newInstance().useOldPlanner().build(); StreamTableEnvironment tableEnvironment = StreamTableEnvironment.create( streamExecEnvironment, settings); Table t = tableEnvironment.fromValues( rowType, data ); DataStream<Row> rowDataStream = tableEnvironment.toAppendStream(t, Row.class); StreamITCase.clear(); rowDataStream.addSink(new StreamITCase.StringSink<>()); streamExecEnvironment.execute(); List<String> expected = Arrays.asList( "0,D,2000-12-12 12:30:57.123,0,D,[1, 2, 3]", "1,ABC,2000-12-12 12:30:57.12,1,ABC,[1, 2, 3]", "3.0999999046325684,DEF,2000-12-12 12:30:57.123,3.0999999046325684,DEF,[1.0, 2.0, 3.0]", "3.141592653589793,ABC,2000-12-12 12:30:57.123,3.141592653589793,ABC,[1, 2, 3]", "99,DEFG,2000-12-12 12:30:57.123,99,DEFG,[1.0, 2.0, 3.0]" ); StreamITCase.compareWithList(expected); }