请教 table /sql API, 窗口frist/last value

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

请教 table /sql API, 窗口frist/last value

marble.zhong@coinflex.com.INVALID
你好,
我有一个sql,
select marketCode as market_code,
       CURRENT_TIMESTAMP as process_time,
       sum((CASE
               WHEN msgType = 'FUTURE' THEN matchedPrice
               WHEN msgType = 'SPOT' THEN matchedPrice
               ELSE 0.5 * (leg1Price + leg2Price)
           END) * matchedQty) as volume,
       sum(matchedQty) as currency_volume,
       first_value(matchedPrice) over (partition by marketCode ORDER BY
transTime) as vopen,
       max(matchedPrice) as vhigh,
       min(matchedPrice) as vlow,
       last_value(matchedPrice) over (partition by marketCode ORDER BY
transTime) as vclose
  from TickData
 where action = 'OrderMatched' and side = 'BUY'
 group by marketCode, HOP(transTime, INTERVAL '1' SECOND, INTERVAL '24'
hour)

执行的时候报, matchedPrice not being grouped, 我的理解matchedPrice也是group function里的,
为什么还要在group里, 如果加了这个group column,我的结果会不对。

还是说我用的first/last 聚合函数错了?  我想要的是这个窗口的最早和最晚的那个值。
谢谢!



--
Sent from: http://apache-flink.147419.n8.nabble.com/
Reply | Threaded
Open this post in threaded view
|

Re: 请教 table /sql API, 窗口frist/last value

marble.zhong@coinflex.com.INVALID
up一下, 有给些建议的吗?



--
Sent from: http://apache-flink.147419.n8.nabble.com/
Reply | Threaded
Open this post in threaded view
|

Re: 请教 table /sql API, 窗口frist/last value

359502980@qq.com
你的transTime这个字段指定成rowtime或者proctime属性了吗?

发自我的iPhone

> 在 2020年10月22日,上午10:12,[hidden email] 写道:
>
> up一下, 有给些建议的吗?
>
>
>
> --
> Sent from: http://apache-flink.147419.n8.nabble.com/
>

Reply | Threaded
Open this post in threaded view
|

Re: 请教 table /sql API, 窗口frist/last value

Leonard Xu
In reply to this post by marble.zhong@coinflex.com.INVALID
Hi

> 在 2020年10月21日,16:27,[hidden email] <[hidden email]> 写道:
>
> select marketCode as market_code,
>      first_value(matchedPrice) over (partition by marketCode ORDER BY transTime) as vopen
>  from TickData
>      where action = 'OrderMatched' and side = 'BUY'
> group by marketCode, HOP(transTime, INTERVAL '1' SECOND, INTERVAL ’24' hour)


这个query里 first_value(matchedPrice) over (partition..)是作用在紧跟后面的over 聚合上,over聚合的输入也就是
最外层groupBy 聚合的输出中, matchedPrice 是没有分组的,所以会有这个报错。

祝好,
Leonard