flink-user-zh mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Benchao Li <libenc...@gmail.com>
Subject Re: Flink SQL 1.10中ROW_NUMBER的使用
Date Tue, 07 Apr 2020 05:45:37 GMT
这个是因为你的over window的 order by字段不是具有时间属性的字段。
而之所以两个query串起来执行不成功,是因为第一个hop window之后,时间属性就丢掉了。
关于如何保持时间属性,可以参考文档[1],具体到你这里,就是用HOP_ROWTIME或者HOP_PROCTIME,
具体用哪个取决于你的ts的类型。

[1]
https://ci.apache.org/projects/flink/flink-docs-master/dev/table/sql/queries.html#time-attributes

111 <xinghalo@163.com> 于2020年4月7日周二 下午1:07写道:

> HI,
> 我这边想要在滑动窗口之后做一个topN,于是就有下面的SQL:
> -- 窗口聚合
> create view window_v as
> select
>         member_id,
>         category_id,
>  HOP_END(ts, INTERVAL '10' SECOND, INTERVAL '30' MINUTE) as `time`,
>         count(1) as c
> from stream_t
> group by member_id, category_id,
> HOP(ts, INTERVAL '10' SECOND, INTERVAL '30' MINUTE);
>
>
> -- 排序取top 20
> SELECT
> member_id,
>         category_id,
>         c,
>         row_number() over (PARTITION BY member_id ORDER BY c) AS rn
> FROM window_v;
>
>
> 但是执行异常:
> Caused by: org.apache.flink.table.api.TableException: OVER windows'
> ordering in stream mode must be defined on a time attribute. at
> org.apache.flink.table.planner.plan.nodes.physical.stream.StreamExecOverAggregate.translateToPlanInternal(StreamExecOverAggregate.scala:195)
> at
> org.apache.flink.table.planner.plan.nodes.physical.stream.StreamExecOverAggregate.translateToPlanInternal(StreamExecOverAggregate.scala:56)
> at
> org.apache.flink.table.planner.plan.nodes.exec.ExecNode$class.translateToPlan(ExecNode.scala:58)
> 我看官网的TOPN例子中,order by 后面也可以是long型。难道row_number不能作用在窗口结果上?
> Best,Xinghalo



-- 

Benchao Li
School of Electronics Engineering and Computer Science, Peking University
Tel:+86-15650713730
Email: libenchao@gmail.com; libenchao@pku.edu.cn
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message