我有一个可以用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""")
如果我理解正确,您想在以下情况下将Actor2Type1的值分配给Actor1Type1: Actor1Type1 == '' AND Actor2Type1 != ''
这是你的做法,
df2 = sqlContext.sql('select (case when Actor1Type1 == '' AND Actor2Type1 != '' then Actor2Type1 else Actor1Type1 end) as Actor1Type1,Actor2Type1 from temp')
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句