映射分区迭代器返回

时间:2017-08-12 09:55:47

标签: scala apache-spark

任何人都可以帮助接受返回的Iterator listWords()方法到mapPartitions。

object MapPartitionExample {

  def main(args: Array[String]): Unit = {

    val conf= new SparkConf().setAppName("MapPartitionExample").setMaster("local[*]")
    val sc= new SparkContext(conf)

    val input:RDD[String] = sc.parallelize(List("ABC","DEF","GHU","YHG"))

    val x= input.mapPartitions(word => listWords(word))


  }

  def listWords(words: Iterator[String]) : util.Iterator[String] = {

    val arrList = new util.ArrayList[String]()
    while( words.hasNext ) {
      arrList.add( words.next())
    }
    return arrList.iterator()
  }

}

0 个答案:

没有答案