我在scala中有这个代码
object SimpleApp {
def myf(x: Iterator[(String, Int)]): Iterator[(String, Int)] = {
while (x.hasNext) {
println(x.next)
}
x
}
def main(args: Array[String]) {
val conf = new SparkConf().setAppName("Simple Application")
val sc = new SparkContext(conf)
val tx1 = sc.textFile("/home/paourissi/Desktop/MyProject/data/testfile1.txt")
val file1 = tx1.flatMap(line => line.split(" ")).map(word => (word, 1))
val s = file1.mapPartitions(x => myf(x))
}
}
我试图弄清楚为什么它不会在输出上打印任何内容。我在本地机器上而不是在集群上运行它。
最佳答案
你只有转换,没有actions .在调用 Action 之前,Spark 不会执行。添加此行以打印出前 10 个结果。
s.take(10).foreach(println)
关于scala - 为什么 mapPartitions 不向标准输出打印任何内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33830676/