Reputation: 10217
I am trying to use mapPartitions and then save the results to HDFS by the following:
val x = sc.parallelize(List(1, 2, 3, 4, 5, 6, 7, 8, 9,10), 3)
x.mapPartitions(p => p.map( r => r+5 ) ).collect().saveAsTextFile("/path/to/folder")
:29: error: value saveAsTextFile is not a member of Array[Int] x.mapPartitions(p => p.map( r => r+5 ) ).collect().saveAsTextFile("/path/to/folder")
It seems something is wrong but I failed to figure out what is the correct way.
THanks
Upvotes: 2
Views: 278
Reputation: 46
Don't use collect
:
x.mapPartitions(p => p.map( r => r+5 ) ).saveAsTextFile("/path/to/folder")
It collects data to the driver as an Array
.
Upvotes: 3