将SQL条件转换为Pyspark

wh6knrhe  于 2023-03-22  发布在  Spark
关注(0)|答案(1)|浏览(103)

如何在Pyspark中实现这个查询?
我需要将这个子句中使用exist的地方转换为另一个 Dataframe 。

SELECT 
  c.Id, c.Description, c.Code
FROM charlie as c                                                                              
Where (
            c.Status = 'ACTIVE' or
            exists (
                select 1 from beta as b                                                     
                    where c.Id = b.Id
            )
         )
fhity93d

fhity93d1#

from pyspark.sql.functions import col, exists

charlie_df.select("Id", "Description", "Code") \
.where((col("Status") == "ACTIVE") |
exists(charlie_df.select("*").join("beta", charlie_df.Id == "beta.Id")))

相关问题