在将RDD用于强制时会收到警告,但我不确定这是我做错了什么。如果我这样做:
val sc = new SparkContext(...)
val anRDD = sc.parallelize(List(
("a", List(1, 2, 3)),
("b", List(4),
("c", List(5, 6))
)
for {
(someString, listOfInts) <- anRDD
someInt <- listOfInts
} yield (someString, someInt)
然后我得到以下输出:
warning: `withFilter' method does not yet exist on org.apache.spark.rdd.RDD[(String, List[Int])], using `filter' method instead
(s, li) <- rl
但是它仍然可以成功返回FlatMappedRDD [(String,Int)]。难道我做错了什么?还是忽略此警告是否安全?
更新:我也可以接受理解如何将这些操作转换为map/flatMap/filter调用,因为我认为不需要任何filter或withFilter调用。我认为这将类似于以下内容:
anRDD.flatMap(tuple => tuple.map(someInt => (tuple._1, someInt)))
但这不包括任何filter或withFilter调用,这似乎是警告的来源。
哦,我使用的是Spark 1.2.0,Scala 2.10.4,而这一切都在REPL内。
最佳答案
首先,我不是专家,但是做了一些挖掘,这就是我所发现的:
我使用-print
编译了代码(因为JavaDecompiler由于某种原因失败了),它将打印出该程序,并删除了所有Scala特定的功能。在那里,我看到了:
test.this.anRDD().filter({
(new anonymous class anonfun$1(): Function1)
}).flatMap({
(new anonymous class anonfun$2(): Function1)
}, ClassTag.apply(classOf[scala.Tuple2]));
您会注意到
filter
...所以,我检查了anonfun$1
:public final boolean apply(Tuple2<String, List<Object>> check$ifrefutable$1)
{
Tuple2 localTuple2 = check$ifrefutable$1;
boolean bool;
if (localTuple2 != null) {
bool = true;
} else {
bool = false;
}
return bool;
}
因此,如果将所有这些放在一起,似乎
filter
正在理解中,因为它正在过滤掉不是Tuple2
的所有内容。而且,首选项是使用
withFilter
而不是filter
(不确定为什么使用atm)。您可以通过反编译常规列表而不是RDD
来看到object test {
val regList = List(
("a", List(1, 2, 3)),
("b", List(4)),
("c", List(5, 6))
)
val foo = for {
(someString, listOfInts) <- regList
someInt <- listOfInts
} yield (someString, someInt)
}
哪个反编译为:
test.this.regList().withFilter({
(new anonymous class anonfun$1(): Function1)
}).flatMap({
(new anonymous class anonfun$2(): Function1)
}, immutable.this.List.canBuildFrom()).$asInstanceOf[List]();
因此,这是同一件事,除了它在可以使用的地方使用
withFilter
关于scala - 在使用RDD进行理解时发出警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28048586/