我有一个查询,可以确定某些内容随时间变化的长度,当数据看似缺失时能够填补空白。
在Hive中,它看起来像这样:
floor(percentile(cast(book_length as BIGINT), 0.5)) over (partition by book order by read_timestamp ROWS BETWEEN 20 PRECEDING AND 20 FOLLOWING)
在bigquery(遗产)中,我想它看起来像这样:
NTH(50, QUANTILES(book_length, 101)) OVER (PARTITION BY book order by read_timestamp ROWS BETWEEN 20 PRECEDING AND 20 FOLLOWING)
然而我收到错误Unrecognized is not currently supported as an analytic function
。
有什么想法?我可能过于复杂了......原来的蜂巢解决方案是在深夜完成的:)
答案 0 :(得分:0)
窗口函数不支持NTH和QUANTILES聚合函数(在BigQuery Legacy SQL中)
下面的内容应该有效但不是你需要的
SELECT
book,
NTH(50, QUANTILES(book_length , 101)) as x
FROM yourTable
GROUP BY book
检查窗口/分析功能支持的其他功能
比如NTH_VALUE,NTILE ......
旧版SQL - Window functions
标准SQL - Analytic Functions