很多用户都是用 CASE WHEN 来实现这种多维度统计的功能,但是建议使用更标准的 agg with filter 语法,因为 blink 目前的 SQL 优化器能分析出 filter 参数,从而同一个字段上计算不同条件下的 count distinct 能共享 state,减少对 state 的读写操作。性能测试中有一倍的性能提升。 适用场景 我们建议用户将 agg with...
AGG WITH CASE WHEN改写为AGG WITH FILTER语法(提升大量COUNT DISTINCT场景性能) 统计作业需要计算各种维度的UV,例如全网UV、来自手机客户端的UV、来自PC的UV等等。建议使用标准的AGG WITH FILTER语法来代替CASE WHEN实现多维度统计的功能。实时计算目前的SQL优化器能分析出Filter参数,从而同一个字段上计算不同条件下的...
在进行多维度统计,如计算全网UV、手机客户端UV、PC端UV等时,推荐使用AGG WITH FILTER语法替代传统的CASE WHEN语法。这样做的好处是,SQL优化器能够识别Filter参数,使得在同一个字段上根据不同条件计算COUNT DISTINCT时能够共享状态信息,减少状态的读写次数。根据性能测试结果,采用AGG WITH FILTER语法相比CASE WHEN可以提...
从Flink 1.9.0版本开始,提供了 count distinct自动打散功能。 d.改写 agg with filter语法(提升大量 count distinct场景性能) 在某些场景下,可能需要从不同维度来统计uv,可能会用到case when语法。 select day,count(distinct user_id) as total_uv, count(distinct case when flag in ('a','b') then user...
withGap:会话时间间隔 on:用来分组(按时间间隔)或者排序(按行数)的时间字段 as:别名,必须出现在后面的groupBy中 代码如下: 代码语言:javascript 代码运行次数:0 运行 AI代码解释 // Session Event-time Window.window(Session withGap10.minutes on $"rowtime"as$"w")// Session Processing-time Window.window(...
通过几个参数的分析不难发现,ProcessFunction可以轻松实现flatMap这样的基本转换功能(当然map、filter更不在话下);而通过富函数提供的获取上下文方法.getRuntimeContext(),也可以自定义状态(state)进行处理,这也就能实现聚合操作的功能了。 复制 2. 非抽象方法.onTimer() ...
firstAgg .map(newMapFunction<Tuple3<String,Long,Long>, Tuple3<String,Long,Long>>() { @Override publicTuple3<String, Long, Long> map(Tuple3<String, Long, Long> value)throwsException { String originKey = value.f0.split("-")[0]; ...
This way, Realtime Compute for Apache Flink can execute the COUNT DISTINCT function on the same field in different filter conditions by sharing the state data. This reduces the read and write operations on the state data. In the performance test, the AGG WITH FILTER syntax outperforms the ...
flink sql官方调优文档里面提到, UseFILTER Modifieron Distinct Aggregates 可以使用共享状态, 以减少状态的大小。 我一直挺困惑,里面究竟是怎么做到的?官方文档也没有说的很明白,今天特意翻了下源代码看下。 SELECT day, COUNT(DISTINCT user_id) AS total_uv, ...
resultSqlTable.toRetractStream[Row].print("agg temp sql") 5.5 表聚合函数(Table Aggregate Functions) 用户定义的表聚合函数(User-Defined Table Aggregate Functions,UDTAGGs),可以把一个表中数据,聚合为具有多行和多列的结果表。这跟AggregateFunction非常类似,只是之前聚合结果是一个标量值,现在变成了一张表。