Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use MinBy of Flink

Shulou Source: shulou.com Published: 2022-06-01 06:17:13 09月27日 Update

This article mainly explains "how to use Flink's MinBy". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use Flink's MinBy.

MaxBy aggregation: gets the smallest record row in a set of data flow operators (unlike min, min is the minimum value that returns a calculated field)

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

MinBy.java

Import com.flink.examples.DataSource;import org.apache.flink.api.common.typeinfo.Types;import org.apache.flink.api.java.functions.KeySelector;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 maxBy aggregation: gets the smallest row of records in a set of data flow operators (unlike min, min returns the minimum value of a calculated field) * / public class MinBy {/ * * traversal collection Return the minimum age data record * @ param args * @ throws Exception * / public static void main (String [] args) throws Exception {final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment () List tuple3List = DataSource.getTuple3ToList () DataStream dataStream = env.fromCollection (tuple3List) .returns (Types.TUPLE (Types.STRING, Types.STRING,Types.INT)) .keyby ((KeySelector) k-> k.f1) / / scroll by quantity window, every 3 input data streams Calculate once. CountWindow (3) / / Note: the calculation variable is f2.minBy (2) DataStream.print (); env.execute ("flink MinBy job");}}

Print the result

4 > (Wu Qi, girl,18) 2 > (Zhang San, man,20) at this point, I believe you have a deeper understanding of "how to use Flink's MinBy". You might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Data minimum data flow content fields environment examples operators learning practical deeper interest variables practicality actual age gender easy to operate data source quantity Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi vpn Microsoft Shulou Information Xiaomi