Spark SQL Pyspark 将 table 中的值更新为 table 中的另一个值

Spark SQL Pyspark update value in table to another value in table

我有一个可以用 SQL 查询的 table。有两列,一列称为 Actor1Type1,另一列称为 Actor2Type1。如果 Actor1Type1 列中的单元格是“”而 Actor2Type1 不是“”,那么我想将该单元格的值更改为 Actor2Type1 的值。我不知道如何使用 Spark SQL 执行此操作,因为我是新手。

到目前为止我有

sqlContext.registerDataFrameAsTable(df, 'temp')
new_df = sqlContext.sql("""SELECT CASE WHEN temp.Actor1Type1Code == '' AND temp.Actor2Type1Code != ''
                    THEN temp.Actor1Type1Code""")

如果我没理解错的话,你想在Actor1Type1 == '' AND Actor2Type1 != ''

时将Actor2Type1的值赋给Actor1Type1

这是你的做法,

df2 = sqlContext.sql('select (case when Actor1Type1 == '' AND Actor2Type1 != '' then Actor2Type1 else Actor1Type1 end) as Actor1Type1,Actor2Type1 from temp')