当前位置:网站首页>Flink window table valued function

Flink window table valued function

2022-06-11 12:11:00 But don't ask about your future

Preface

   from 1.13 Version start ,Flink Start using window table valued functions (Windowing table-valued functions,Windowing TVFs) To define the window . The window table valued function is Flink Defined polymorphic table functions (PTF), You can expand the table and return

Scroll the window (Tumbling Windows)
The sliding window (Hop Windows, Jump window )
Accumulation window (Cumulate Windows)
Session window (Session Windows, At present, it has not fully supported )

   At the window TVF In the return value of , Remove all columns from the original table , Additional to describe the window has also been added 3 Columns : Window start point (window_start)、 Window end point (window_end)、 Window time (window_time). Window time refers to the time attribute in the window , Its value is equal to window_end - 1ms, So it is equivalent to the maximum timestamp of the data contained in the window


1. Scroll the window (TUMBLE)

   stay SQL By calling TUMBLE() Function to declare a scrolling window , Only one core parameter is window size (size). stay SQL The counting window is not considered in , So a scrolling window is a scrolling time window , The current time attribute field needs to be passed into the parameter ; in addition , window TVF It's essentially a table function , The table can be extended , Therefore, the table of the current query should also be passed in as a whole

TUMBLE(TABLE EventTable, DESCRIPTOR(ts), INTERVAL '1' HOUR)

2. The sliding window (HOP)

   The use of sliding windows is similar to scrolling windows , The frequency of statistical output can be controlled by setting the sliding step . stay SQL By calling HOP() To declare a sliding window ; In addition to passing in the table name 、 Outside of time attribute , You also need to pass in the window size (size) And sliding step size (slide) Two parameters

HOP(TABLE EventTable, DESCRIPTOR(ts), INTERVAL '5' MINUTES, INTERVAL '1' HOURS));

   Time based attribute ts, In the table EventTable Created on with size 1 Hours of sliding window , Every time 5 Slide once in minutes . The third parameter after the time attribute field is the step size (slide), The fourth parameter is the window size (size)


3. Accumulation window (CUMULATE)

   The cumulative window is the window TVF New window function in , It will carry out cumulative calculation in a certain statistical period . There are two core parameters in the accumulation window : Maximum window length (max window size) And cumulative step size (step). The so-called maximum window length is the statistical period , The ultimate goal is to count the data during this period
 Insert picture description here

CUMULATE(TABLE EventTable, DESCRIPTOR(ts), INTERVAL '1' HOURS, INTERVAL '1' DAYS))

   Time based attribute ts, In the table EventTable A statistical period is defined as 1 God 、 The cumulative step is 1 Cumulative window of hours . Note that the third parameter is the step size step, The fourth parameter is the maximum window length


原网站

版权声明
本文为[But don't ask about your future]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206111206047562.html