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

Pyspark Spark SQL PypSpark将表中的值更新为表中的另一个值,pyspark,spark-dataframe,pyspark-sql,Pyspark,Spark Dataframe,Pyspark Sql,我有一个可以用SQL查询的表。有两列,一列称为Actor1Type1,另一列称为Actor2Type1。如果列Actor1Type1中的单元格为“”,而Actor2Type1不是“”,则我想将该单元格的值更改为Actor2Type1的值。我不知道如何使用Spark SQL来实现这一点,因为我是新手 到目前为止我有 sqlContext.registerDataFrameAsTable(df, 'temp') new_df = sqlContext.sql("""SELECT CASE WHEN

我有一个可以用SQL查询的表。有两列,一列称为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==''和Actor2Type1!=''时将Actor2Type1的值分配给Actor1Type1

这是你怎么做的

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

如果我理解正确,您希望在
Actor1Type1==''和Actor2Type1!=''时将Actor2Type1的值分配给Actor1Type1

这是你怎么做的

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