【问题标题】:Pivot in SPARK SQLSPARK SQL 中的枢轴
【发布时间】: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


【解决方案1】:

在 Spark 2.4 之前,使用 SQL API 在 Spark 中没有 PIVOT

在 Spark 2.4 之后,SQL 中的 PIVOT 功能按照您的描述工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-12-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-14
    • 1970-01-01
    • 2016-12-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多