技术标签: flink big data Flink 大数据
stream
.keyBy(...) <- keyed versus non-keyed windows
.window(...) <- required: "assigner"
[.trigger(...)] <- optional: "trigger" (else default trigger)
[.evictor(...)] <- optional: "evictor" (else no evictor)
[.allowedLateness(...)] <- optional: "lateness" (else zero)
[.sideOutputLateData(...)] <- optional: "output tag" (else no side output for late data)
.reduce/aggregate/apply() <- required: "function"
[.getSideOutput(...)] <- optional: "output tag"
2)Non-Keyed Windows
stream
.windowAll(...) <- required: "assigner"
[.trigger(...)] <- optional: "trigger" (else default trigger)
[.evictor(...)] <- optional: "evictor" (else no evictor)
[.allowedLateness(...)] <- optional: "lateness" (else zero)
[.sideOutputLateData(...)] <- optional: "output tag" (else no side output for late data)
.reduce/aggregate/apply() <- required: "function"
[.getSideOutput(...)] <- optional: "output tag"
input
.keyBy(<key selector>)
.window(TumblingEventTimeWindows.of(Time.seconds(5)))
.<windowed transformation>(<window function>);
2)Sliding Windows(滑动窗口)
input
.keyBy(<key selector>)
.window(SlidingEventTimeWindows.of(Time.seconds(10), Time.seconds(5)))
.<windowed transformation>(<window function>);
3)Session Windows(会话窗口)
input
.keyBy(<key selector>)
.window(EventTimeSessionWindows.withGap(Time.minutes(10)))
.<windowed transformation>(<window function>);
4)Global Windows(全局窗口)
input
.keyBy(<key selector>)
.window(GlobalWindows.create())
.<windowed transformation>(<window function>);
①ReduceFunction
input
.keyBy(<key selector>)
.window(<window assigner>)
.reduce(new ReduceFunction<Tuple2<String, Long>>() {
public Tuple2<String, Long> reduce(Tuple2<String, Long> v1, Tuple2<String, Long> v2) {
return new Tuple2<>(v1.f0, v1.f1 + v2.f1);
}
});
②AggregateFunction
可以统计窗口内数据的个数,进行求平均值等等。(局部计算,全局和并。)
/**
* The accumulator is used to keep a running sum and a count. The {@code getResult} method
* computes the average.
*/
private static class AverageAggregate
implements AggregateFunction<Tuple2<String, Long>, Tuple2<Long, Long>, Double> {
@Override
public Tuple2<Long, Long> createAccumulator() {
return new Tuple2<>(0L, 0L);
}
@Override
public Tuple2<Long, Long> add(Tuple2<String, Long> value, Tuple2<Long, Long> accumulator) {
return new Tuple2<>(accumulator.f0 + value.f1, accumulator.f1 + 1L);
}
@Override
public Double getResult(Tuple2<Long, Long> accumulator) {
return ((double) accumulator.f0) / accumulator.f1;
}
@Override
public Tuple2<Long, Long> merge(Tuple2<Long, Long> a, Tuple2<Long, Long> b) {
return new Tuple2<>(a.f0 + b.f0, a.f1 + b.f1);
}
}
DataStream<Tuple2<String, Long>> input = ...;
input
.keyBy(<key selector>)
.window(<window assigner>)
.aggregate(new AverageAggregate());
2)全量窗口函数
ProcessWindowFunction
这个函数更加灵活,但是延迟性更高,且牺牲一定存储空间。
public abstract class ProcessWindowFunction<IN, OUT, KEY, W extends Window> implements Function {
/**
* Evaluates the window and outputs none or several elements.
*
* @param key The key for which this window is evaluated.
* @param context The context in which the window is being evaluated.
* @param elements The elements in the window being evaluated.
* @param out A collector for emitting elements.
*
* @throws Exception The function may throw exceptions to fail the program and trigger recovery.
*/
public abstract void process(
KEY key,
Context context,
Iterable<IN> elements,
Collector<OUT> out) throws Exception;
/**
* The context holding window metadata.
*/
public abstract class Context implements java.io.Serializable {
/**
* Returns the window that is being evaluated.
*/
public abstract W window();
/** Returns the current processing time. */
public abstract long currentProcessingTime();
/** Returns the current event-time watermark. */
public abstract long currentWatermark();
/**
* State accessor for per-key and per-window state.
*
* <p><b>NOTE:</b>If you use per-window state you have to ensure that you clean it up
* by implementing {@link ProcessWindowFunction#clear(Context)}.
*/
public abstract KeyedStateStore windowState();
/**
* State accessor for per-key global state.
*/
public abstract KeyedStateStore globalState();
}
}
3)增量和全量窗口函数混合使用
兼顾两者优点
ReduceFunction+ProcessWindowFunction
或
AggregateFunction+ProcessWindowFunction
文章浏览阅读797次。首先来看一下物理设备上的数据如何是通过Linux网络协议栈送到用户态程序的,如图:物理网卡收到数据后送到网络协议栈,进程通过socket创建特殊套接字,从网络协议栈读取数据。在网络协议栈看来,tun/tap这类虚拟网络设备和物理网卡并无区别。tun/tap设备就是利用Linux的设备文件实现内核态和用户态的数据交互,如图:物理网卡通过网线收发数据,而tun/tap通过设备文件(/dev/tunX)收发数据。所有对/dev/tunX的写操作会通过tun设备转成数据包发送给内核网络协议栈;当内核发包给tu_linux tun mtu
文章浏览阅读1k次。3、内连接要求相等的分量,不一定是公共属性,自然连接要求相等的分量必须是公共属性;自然外连接分为自然左外连接和自然右外连接.匹配条件也是由系统自动指定.在MySQL中,可通过求左外连接与右外连接的合集来实现全外连接。自然内连接其实就是内连接,这里的匹配条件是由系统自动指定.2、内连接不把重复的属性除去,自然连接要把重复的属性除去;4、内连接不把重复的属性除去,自然连接要把重复的属性除去。–自然内连接 natural inner join。1、自然连接一定是内连接,内连接不一定是自然连接;_sql注入join连接
文章浏览阅读1w次,点赞7次,收藏37次。英文原文链接:https://www.pyimagesearch.com/2018/08/20/opencv-text-detection-east-text-detector/提醒:作者实现的python的文本检测基于OpenCV的官方C ++示例;在将其转换为Python时遇到了一些麻烦。首先,Python中没有Point2f 和RotatedRect函数,因此,无法100..._python east
文章浏览阅读211次。<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>表格</title> <style> table{/*为页面中所有table标签添加样式*/ border: black 1px solid; width: 800px;/*设置表格宽度*/ margin: 0 auto;/*设置表格水平居中*/ bord_html中关于表格所有的标签
文章浏览阅读680次。Kerberos技术实践_kerberos_patch 1.0
文章浏览阅读515次。@Test public void testHighLightingQuery() throws SolrServerException, IOException{ // 初始化solrj服务 HttpSolrServer server = new HttpSolrServer("http://localhost:8080/solr/c..._sql query highlighting
文章浏览阅读224次。1.首先要有安装包,进行解压2.在普通用户下安装,执行./pycharm.sh脚本3.脚本运行后会出现以下界面4.接受协议,点击continue5.选择don’t send6.选择你喜欢的一种界面7.创建软连接,以后在启动pycharm只需在命令行输入charm启动即可8.创建一个新的工程9.创建路径10.安装必要的插件系统统默认是使用的python2版本..._python main.py --seed 123 怎么在命令行添加pycharm
文章浏览阅读2.1k次。FileReader:读取文件内容1.readAsText():读取文本文件(可以使用Txt打开的文件),返回文本字符串,默认编码是UTF-82.readAsBinaryString():读取任意类型的文件。返回二进制字符串。这个方法不是用来读取文件展示给用户看,而是存储文件。例如:读取文件的内容,获取二进制数据,传递给后台,后台接收了数据之后,再将数据存储3.readAsDataURL():读取文件获取一段以data开头的字符串,这段字符串的本质就是DataURL.DataURL是一种将文件(这个文_filereader读取文件内容
文章浏览阅读179次。UML关系关联关系即两个类互相包含,使用双向箭头表示 依赖关系即方法参数上的依赖,使用虚线箭头表示,其中箭头指向部分 聚合关系即部分与整体之间的关系,如类A中有属性值为B,使用 菱形空心箭头表示其中空心端为整体组合关系也是部分与整体之间的关系,与聚合关系的区别在于组合中部分单独存在没有意义,部分需要依赖于整体才能存在,使用菱形实心箭头表示其中实心端为整体 泛化关系即..._音乐网站排行uml图
文章浏览阅读3.9k次。今天要打开struts.xml文件时莫名其妙报错,试了几种方法都没用:后来用了一下方式打开:鼠标放在待打开xml文件,点击右键,然后选择open with。。。选择MyEclipse Struts2 configeditor即可!
文章浏览阅读547次。一直以为打印乘法口诀要用两个for循环,今天发现用一个for循环就能达到同样的效果,java代码如下://打印乘法口诀public class multiTable { //主函数 public static void main(String[] args) { // 一个for循环,两个参数实现了循环的嵌套效果 for (int i = 1, j = 1; j <= 9;_java从键盘输入一个1到之间的数,如若输入6则打印六六乘法表
文章浏览阅读2k次。本文转自:https://www.cnblogs.com/Jtianlin/p/4339931.htmlhttp://www.cnblogs.com/Rosanna/p/3446557.html使文件立刻生效命令:/sbin/sysctl -p/proc/sys目录下存放着大多数内核参数,并且可以在系统运行时进行更改,不过重新启动机器就会失效。/etc/sysctl.conf是一个允许..._大量time_wait,导致resin 请求进不