【发布时间】:2019-04-21 08:59:18
【问题描述】:
我在 SQL 中有以下 2 个 SQL 查询示例:
a) update DBTABLE1
set col1 = 'Yes'
where ID IN ( '100' ) and City = any(select City from DBTable2 where Country = 'USA');
b) update DBTABLE1
set col2 = 'No'
where ID NOT IN ( '100' ) and City = any(select City from DBTable2 where Country = 'USA');
How to write above 2 SQLs using Apache Spark Dataframes (Not Select subquery etc). A dataframe is already having these 2 columns - col1 and col2, I am changing their values using WITHCOLUMN and WHEN clause.
CitiDF 包含城市数量的数据集。
I tried below but giving compile errors:
c) This is for (a) above:
withcolumn(col("col1"),when(col("id") === lit("100")
and col("city").isin(CitiDF("city")), lit("yes")))
d) This is for (b) above:
withcolumn(col("col2"),when(col("id") === lit("100")
and ! (col("city").isin(CitiDF("city"))), lit("yes")))
【问题讨论】:
-
你能分享一下编译错误吗?
标签: sql scala apache-spark dataframe apache-spark-sql