Scala Spark 包含与不包含

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40439095/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 08:49:48  来源:igfitidea点击:

Scala Spark contains vs. does not contain

scalaapache-spark

提问by thebluephantom

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

我可以在 RDD 中使用“包含”过滤 - 如下所示 - 元组。但是如何使用“不包含”过滤 RDD 呢?

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.

我找不到这个语法。假设这是可能的,而且我没有使用DataFrames。我看不出如何使用正则表达式和/或过滤器示例。

回答by eliasah

It's just the negationof the containsfilter predicate :

这只是否定了的contains过滤谓词:

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