【发布时间】:2020-10-07 20:10:21
【问题描述】:
我正在尝试在 Spark 数据帧中使用雪花列(具有 IFFNULL 和 IFF 等功能)。我试过合并,但它不起作用。在 Spark 数据帧中是否有任何等效的功能或逻辑?
雪花 SQL:
SELECT P.Product_ID,
IFNULL(IFF(p1.ProductDesc='',NULL,p1.ProductDesc),
IFNULL(IFF(p2.PrdDesc='',NULL,p2.PrdDesc),IFF(p3.Product_Desc='',NULL,p3.Product_Desc))
) AS Product_Description
FROM Product p
LEFT JOIN Product_table_1 p1 ON p1.Product_ID = p.Product_ID
LEFT JOIN Product_table_2 p2 ON p2.Product_ID = p.Product_ID
LEFT JOIN Product_table_3 p3 ON p3.Product_ID = p.Product_ID
我试过了:coalesce(p1.ProductDesc, p2.PrdDesc, p3.Product_Desc) 但它不起作用
【问题讨论】:
-
尝试将
case when...作为此类功能的通用和标准替代品。 spark.apache.org/docs/2.3.1/api/sql/#when -
为什么
COALESCE()不起作用?这似乎是正确的代码。
标签: sql dataframe apache-spark apache-spark-sql