Union算子:将多个数据流合并成一个新的数据流(数据类型必需一致)
java.version: 1.8.x flink.version: 1.11.1
示例数据源 (项目码云下载)
Flink 系例 之 搭建开发环境与数据
Union.java
import com.flink.examples.DataSource; import org.apache.flink.api.java.tuple.Tuple3; import org.apache.flink.streaming.api.datastream.DataStream; import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; import java.util.List; public class Union { public static void main(String[] args) throws Exception { final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); List> tuple3List = DataSource.getTuple3ToList(); //Datastream 1 DataStream > dataStream1 = env.fromCollection(tuple3List); //Datastream 2 DataStream > dataStream2 = env.fromCollection(tuple3List); //Datastream 3 DataStream > dataStream = dataStream1.union(dataStream2); dataStream.print(); env.execute("flink Union job"); } }
打印结果
3> (王五,man,29) 2> (李四,girl,24) 3> (王五,man,29) 1> (张三,man,20) 1> (张三,man,20) 1> (伍七,girl,18) 1> (伍七,girl,18) 2> (吴八,man,30) 2> (李四,girl,24) 2> (吴八,man,30) 4> (刘六,girl,32) 4> (刘六,girl,32)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)