下面的RDD3语句不使用collect,但不使用collect。我在想,为什么当你读到collect的作用时,你会感到很困惑。这些例子是人为的,所以不要担心。
val rdd = sc.parallelize(List((" aaa", "x"), ("bbbb ", "y"), (" cc ", "z"), ("gggg ", " a"), (" ", "b")))
val rdd2 = rdd.map{ case (field1, field2) => ( field1.replaceAll(" ", ""), field1.trim, field1, field2) }.collect
val rdd3 = rdd2.map{ case (field1, field2, field3, field4) => (field1.replaceAll(" ", ""), if (field1.trim == "") " " else field1 , field3, field4) }
问题:
val rdd3 = rdd2.map{ case (field1, field2, field3, field4) => (field1.replaceAll(" ", ""), if (field1.trim == "") " " else field1 , field3, field4) }.collect
notebook:7: error: missing argument list for method collect in trait TraversableLike
Unapplied methods are only converted to functions when a function type is expected.
You can make this conversion explicit by writing `collect _` or `collect(_)(_)` instead of `collect`.
val rdd3 = rdd2.map{ case (field1, field2, field3, field4) => (field1.replaceAll(" ", ""), if (field1.trim == "") " " else field1 , field3, field4) }.collect
新手很难跟上。如果看到错误消息,我将如何绕过这个问题?