Scala Spark contains vs. does not contain

2020-06-12 05:54发布

问题:

I can filter - as per below - tuples in an RDD using "contains". But what about filtering an RDD using "does not contain" ?

val rdd2 = rdd1.filter(x => x._1 contains ".")

I cannot find the syntax for this. Assuming it is possible and that I'm not using DataFrames. I cannot see from how to do it with regex and/or filter examples.

回答1:

It's just the negation of the contains filter predicate :

val rdd2 = rdd1.filter(x => !(x._1 contains "."))