我试图在sparkDataframe中使用一个雪花列(它有iffnull和iff这样的函数)。我试过合并,但不起作用。在sparkDataframe中是否有等效的函数或逻辑?
雪花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)
但它不起作用
1条答案
按热度按时间e5nszbig1#
iiuc,您可以尝试coalesce+nullif:
nullif(expr1,expr2)-如果expr1等于expr2,则返回null,否则返回expr1。
例如(使用pyspark):
因此,对于您的任务,请使用以下命令:
顺便说一句,你也可以改变一切
IFF
在原始sql中IF
.