技术标签: 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
本题有两种解决方法:假设法和选择排序法1.假设法找最值#include <stdio.h>int main(){ int a[10], i, max, mini; for (i = 0; i < 10; i++) scanf_s("%d", &a[i]); max = a[0]; //首先假设a[0]为最大值 mini = a[0]; //首先假设a[0]为最小值 for (i = 1; i < 10; i
在wxml页面设置后台js中data中的值,可以用到data-*的方法:例子:wxml中代码:js中代码:通过event参数来获取前端data-*中的值在控制台输出:data中的值在event.target.dataset中...
如 对设备的使用 DEVICE_ATTR ,对总线使用 BUS_ATTR ,对驱动使用 DRIVER_ATTR ,对类 别 (class) 使用 CLASS_ATTR, 这四个高级的宏来自于函数宏DEVICE_ATTR内封装的是__ATTR(_name,_mode,_show,_stroe)方法,_show表示的是读方法,_stroe表示的是写方法。如果你完成了DEVICE_ATTR函数宏的填充,下面就需要创建接口了。
实验过程中用到的SDK中函数fds
CBO主要的输入有3种:统计信息、环境变量和SQL语句。上面任何一种发生变化,执行计划都有可能发生变化。1. 统计信息的变化在10g和11g中,在默认情况下都有一个在晚上运行的后台job收集新的统计信息,如果...
最近,想自己学习下hadoop,但又缺少点文本数据,所以需要爬取点数据~ 不会写py , 就直接找了个爬虫框架~ webmagic的原理图如下,很简单很好用: POM.xml <!-- mybatis start--> <dependency> <groupId>org.mybatis.spring.boot</groupId>
参考文章链接: https://www.jianshu.com/p/5537e5053dc1先在uni-app新建项目,然后在命令行管理中进入到该目录下,执行然后安装依赖将下载后的三个库从node_modules剪切到项目的根目录下。开始在项目中使用echarts。替换最新的 mpvue-echarts 组件echarts.vue 。源码地址:https://github.com/dcloudio/hello-uniapp/blob/master/components/mpvue-echarts/
github一直发邮件,如何屏蔽我也被烦了很长一段时间!在设置里面的notification -> participating/watching中把email改为web就好了。_1671465600
prepare、execute与deallocate都是mysql中的预处理语句,本文主要介绍了MySQL中预处理语句prepare、execute与deallocate的使用教程,文中通过示例代码介绍的非常详细,对大家学习或者使用mysql具有一定的参考学习价值,需要的朋友们下面跟着小编一起来学习学习吧。相关mysql视频教程推荐:《mysql教程》前言MySQL官方将prepare、execu...
我有一个加密/ php问题,我希望有人可以帮助我.我的问题是我有一个签名的PKCS7块,我试图在PHP中验证.但是,当我运行以下PHP命令时:openssl_pkcs7_verify($myfile, PKCS7_BINARY | PKCS7_NOVERIFY, $signers_file);我收到以下错误:PKCS7 routines:SMIME_read_PKCS7:no content ty...
背景测试同事通过更新某个表的数据进行功能测试,突然说锁表了,也不知道原因为何,一直用的Navicat,然后用show OPEN TABLES where In_use > 0;命令也查询不到具体的进程ID常规解决办法查询是否锁表show OPEN TABLES where In_use > 0;查询进程show processlist;查询到相对应的进程,然后..._1671465600
Svelte是一个新兴的热门前端框架,作者是RichHarris,被称为前端界的【轮子哥】,有Ractive、Rollup和Buble开源作品。在官方的介绍中,Svelte即是一个前端UI框架,同时也是一个编译器。在《StateofJSsurveyof2020》报告中,它被预测为未来十年可能取代React和Vue等其他框架的新兴技术。在开源托管网站Github上,Svelte也获得了超过61k的关注,这仅次于明星框架React和Vue。...