Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How does Flink Union merge multiple data streams into a new data stream

Shulou Source: shulou.com Published: 2022-06-01 06:16:05 10月04日 Update

This article mainly explains "how Flink Union merges multiple data streams into a new data stream". The content in the article is simple and clear, and it is easy to learn and understand. please follow the editor's ideas to study and learn "how Flink Union merges multiple data streams into a new data stream".

Union operator: merges multiple data streams into a new data stream (data types must be consistent)

Sample environment,

Java.version: 1.8.xflink.version: 1.11.1

Sample data source (project code cloud download)

Building Development Environment and data of Flink system example

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 / * * @ Description Union operator: merge multiple data streams into a new data stream (data type must be consistent) * / public class Union {/ * traversal collection, merge multiple streams and print * @ param args * @ throws Exception * / 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");}}

Print the result

3 > (Wang Wu, man,29) 2 > (Li Si, girl,24) 3 > (Wang Wu, man,29) 1 > (Zhang San, man,20) 1 > (Zhang San, man,20) 1 > (Wu Qi, girl,18) 1 > (Wu Qi, girl,18) 2 > (Wu Ba, man,30) 2 > (Li Si, girl,24) 2 > (Wu Ba, man,30) 4 > (Liu Liu, girl,32) 4 > (Liu Liu, girl,32) Thank you for reading The above is the content of "how Flink Union merges multiple data streams into a new data stream". After the study of this article, I believe you have a deeper understanding of how Flink Union merges multiple data streams into a new data stream, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Data data flow multiple merging learning consistency content environment examples operators types Zhang San Li Si Wang Wu that is ideas situations data sources articles more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Xiaomi Docker vpn Microsoft