如何通过不在元组中的元素过滤Scala中的RDD映射

时间:2020-02-03 19:28:01

标签: scala apache-spark filter

我有一个字数示例。如果我想过滤出一个常见的单词,我可以这样做,其中wordList是一个元组:

val filterWords = wordList.filter(x => x != "to")

但是创建要过滤的单词列表更有用:

val filterWords = ("a", "to", "the", "of", "I", "you")

如何在上面的过滤器中使用它?或者,我该怎么做呢(用SQL完成)?

where wordList not in ("a", "to", "the", "of", "I", "you")

2 个答案:

答案 0 :(得分:2)

CombinedEventDirective

val filterWords = Set("a", "to", "the", "of", "I", "you") wordList.filterNot(filterWords.contains(_)) 将仅在考虑中的filterWords.contains元素在wordList中时返回true。 filterWords将通过filterNot调用为其返回false的元素。

答案 1 :(得分:0)

您创建的是元组而不是列表。

MacBook-Pro:CommandLineTools myname$ ls
Library SDKs    usr

然后您就可以使用

val filterWords = List("a", "to", "the", "of", "I", "you")

还可以查看完整的api of List

相关问题