mapPartitions

rdd.mapPartitions{ partition =>
if (!partition.isEmpty) {
// Some setup code here
partition.map(item => {
val output =yourfunction(item)
if (!partition.hasNext){
// Some cleanup code here
}
output
})
} else {
// return an empty Iterator of your return type
}
}

 

mapPartitions IO等资源管理

posted @ 2018-09-11 15:23  梅里之巅  阅读(593)  评论(0编辑  收藏  举报