当前位置:网站首页>Countwindowall of Flink

Countwindowall of Flink

2022-06-10 05:45:00 Dragon man who can't fly

countWindowAll Number window ( No partition number scrolling window 【 The difference between scrolling windows and sliding windows , The reason is that the data elements may overlap in the sliding window , There is no element overlap in the scrolling window 】)

Sample environment

java.version: 1.8.x
flink.version: 1.11.1

Sample data source  ( Project code cloud download )

Flink System examples And Build development environment and data

CountWindowAll.java

import com.flink.examples.DataSource;
import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.api.common.typeinfo.Types;
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  No partition number scrolling window 
 */
public class CountWindowAll {
    /*
     When the window processes stream data , The convection is usually partitioned ;
     The data stream is divided into :
    keyed( according to key Divide different data flow areas )
    non-keyed( I didn't press key Divided data flow area , All raw data streams )
    */
    /**
     *  Ergodic set , Scroll by number window , Returns the sum of ages in the window 
     * @param args
     * @throws Exception
     */
    public static void main(String[] args) throws Exception {
        final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        List<Tuple3<String, String, Integer>> tuple3List = DataSource.getTuple3ToList();
        DataStream<Integer> dataStream = env.fromCollection(tuple3List)
                .map(new MapFunction<Tuple3<String, String, Integer>, Integer>() {
                    @Override
                    public Integer map(Tuple3<String, String, Integer> tuple3) throws Exception {
                        return tuple3.f2;
                    }
                })
                .returns(Types.INT)
                // Scroll by number window , Every time 3 Input streams , Calculate once 
                .countWindowAll(3)
                .sum(0);
        dataStream.print();
        env.execute("flink CountWindowAll job");
    }
}

Print the results

1> 70
2> 83
原网站

版权声明
本文为[Dragon man who can't fly]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/161/202206100538394996.html