问题原因:
问题报错提示:
Distinct window functions are not supported: count(distinct xx) windowspecdefinition(name#9, _w4#39, ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING);
问题报错原因:
查阅资料后发现sparksql中的窗口函数不支持COUNT(DISTINCT xxx)
问题解决:
使用size()函数配合collect_set() over()函数解决:
collect_set的作用:去重,对partition by后面的数据进行去重操作
size()的作用:使用size()函数返回字段的实现count()功能
报错修改前:
COUNT(DISTINCT totalprice)OVER(partition by name,substring(orderdate,1,7) ) totalorder
报错修改后:
SIZE(COLLECT_SET(totalprice)OVER(partition by name,substring(orderdate,1,7))) totalorder