【发布时间】:2020-04-15 22:12:26
【问题描述】:
有人可以帮助我如何在 spark sql 中进行数据透视吗?我一直在努力让这个查询运行。
这是我的要求:
country date customer attribute_name attribute_value attribute_creation
US 23-Apr-17 Vasan price_start_time 4/6/18 1:23 4/6/18 1:23
US 23-Apr-17 Vasan price_end_time 4/7/18 1:23 4/6/18 1:23
US 23-Apr-17 Vasan price_status MATCH 4/6/18 1:23
US 23-Apr-17 Vasan price_type Deal 4/6/18 1:23
US 23-Apr-17 Gaesh price_start_time 5/6/18 1:23 5/6/18 1:23
US 23-Apr-17 Gaesh price_end_time 5/7/18 1:23 5/6/18 1:23
US 23-Apr-17 Gaesh price_status MATCH 5/6/18 1:23
US 23-Apr-17 Gaesh price_type Deal 5/6/18 1:23
对于 SQL (oracle),我会这样写我的查询,
(select asin,PPST,PPET,PS,PPT from (select * from meta_data where country='US' and date=to_date('{RUN_DATE_YYYY/MM/DD}','YYYY/MM/DD'))
pivot (
max(ATTRIBUTE_VALUE) for ATTRIBUTE_NAME in ('price_start_time' PPST,'price_end_time' PPET,'price_status' PS,'price_type' PPT)
))
但是对于 spark sql,我不确定是否有 PIVOT 选项。任何参考或指导或查询都非常感谢。
【问题讨论】:
标签: apache-spark-sql