我正在将 spark sql 迁移到 snowsql。有一次我遇到了一个场景,我在 spark sql 中使用了嵌套窗口函数。我想将该sql查询迁移到雪花中。但是雪花不支持嵌套窗口函数。
火花 sql 查询 -
SELECT
*,
(case when (
(
lead(timestamp -lag(timestamp)
over (partition by session_id order by timestamp))
over (partition by session_id order by timestamp)
) is not null)
then
(
lead(timestamp -lag(timestamp)
over (partition by session_id order by timestamp))
over (partition by session_id order by timestamp)
)
else 0 end)/1000 as pg_to_pg
FROM dwell_time_step2
转换后的 Snowsql -
with lagsession as (
SELECT
a.*,
lag(timestamp) over (partition BY session_id order by timestamp asc) lagsession
FROM mktg_web_wi.dwell_time_step2 a
)
select
a.,
nvl(lead(a.timestamp - b.lagsession) over (partition BY a.session_id order by a.timestamp),0)/1000 pg_to_pg
FROM mktg_web_wi.dwell_time_step2 a,
lagsession b
WHERE a.key=b.key
order by timestamp;
输出 -
在这里,问题出在 Snow-sql 输出中。Dwelltime 值被分配给不同的 url。
期望是使 spark-sql 查询在 snowsql 上工作,并且两种情况下的输出应该相同。
如果有人知道如何解决这个问题,请告诉我。
谢谢 !!