且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Spark SQL 过滤多个字段

更新时间:2023-11-09 20:40:58

我想我明白问题出在哪里了.出于某种原因,spark 不允许在同一个过滤器中有两个 !='s.需要看看filter在Spark源代码中是如何定义的.

I think i see what the issue is. For some reason, spark does not allow two !='s in the same filter. Need to look at how filter is defined in Spark source code.

现在让你的代码工作,你可以用它来做过滤

Now for your code to work, you can use this to do the filter

df.filter(col("item").notEqual("") && col("group").notEqual("-1"))

或在同一语句中使用两个过滤器

or use two filters in same statement

df.filter($"item" !== "").filter($"group" !== "-1").select(....)

这个链接 此处 可以帮助您使用不同的 spark 方法.

This link here can help with different spark methods.