In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use TimeWindowAll in Flink, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
TimeWindowAll time scrolling window (unpartitioned time scrolling window [the difference between a sliding window and a scrolling window is that there is a possibility of data element overlap in a sliding window, while there is no element overlap in a scrolling window])
Sample environment
Java.version: 1.8.xflink.version: 1.11.1
Building Development Environment and data of Flink system example
TimeWindowAll.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 org.apache.flink.streaming.api.functions.source.RichSourceFunction;import org.apache.flink.streaming.api.windowing.time.Time;import java.util.List / * * @ Description unpartitioned time scrolling window * / public class TimeWindowAll {/ * the window usually partitions the stream when dealing with stream data The data flow is divided into: keyed (dividing different data flow regions according to key) non-keyed (data flow regions not divided by key, referring to all original data streams) * / / * * traversal set Returns the maximum age data record * @ param args * @ throws Exception * / public static void main (String [] args) throws Exception {final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment () / / env.setParallelism (1); DataStream inStream = env.addSource (new MyRichSourceFunction ()); DataStream dataStream = inStream / / scroll by the time window and calculate the input data stream in the first 6 seconds. TimeWindowAll (Time.seconds (6)) / / Note: the calculation variable is f2.maxBy (2). DataStream.print (); env.execute ("flink TimeWindow job");} / * continuous output of analog data * / public static class MyRichSourceFunction extends RichSourceFunction {@ Override public void run (SourceContext ctx) throws Exception {List tuple3List = DataSource.getTuple3ToList (); for (Tuple3 tuple3: tuple3List) {ctx.collect (tuple3) / / output a Thread.sleep (1 * 1000) in 1 second;}} @ Override public void cancel () {try {super.close ();} catch (Exception e) {e.printStackTrace ();}
Print the result
2 > (Wang Wu, man,29) Thank you for reading this article carefully. I hope the article "how to use TimeWindowAll in Flink" shared by the editor will be helpful to everyone. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.