Bam*_*mqf 22 scala apache-spark apache-spark-sql
作为简化示例,我尝试使用以下代码过滤Spark DataFrame:
val xdf = sqlContext.createDataFrame(Seq(
("A", 1), ("B", 2), ("C", 3)
)).toDF("name", "cnt")
xdf.filter($"cnt" >1 || $"name" isin ("A","B")).show()
Run Code Online (Sandbox Code Playgroud)
然后它错误:
org.apache.spark.sql.AnalysisException: cannot resolve '((cnt > 1) || name)' due to data type mismatch: differing types in '((cnt > 1) || name)' (boolean and string).;
Run Code Online (Sandbox Code Playgroud)
什么是正确的方法呢?在我看来,它在name列之后停止阅读.它是解析器中的错误吗?我正在使用Spark 1.5.1
小智 39
希望这会对你有所帮助:
val list = List("x","y","t")
xdf.filter($"column".isin(list:_*))
Run Code Online (Sandbox Code Playgroud)
zer*_*323 29
你必须用括号表示个别表达式:
xdf.filter(($"cnt" > 1) || ($"name" isin ("A","B"))).show()
Run Code Online (Sandbox Code Playgroud)