火花foreachPartition是在驱动程序上还是在工作者上运行的?

时间:2018-03-07 07:32:05

标签: apache-spark pyspark spark-dataframe

目前还不清楚文件中给予foreachpartition的lambda究竟在哪里运行驱动程序或工作者?

1 个答案:

答案 0 :(得分:1)

foreach() foreachPartition()相同的是对工人执行。没有理由将数据传输到驱动程序来处理它。

rdd.foreachPartition { rddpartition =>
    val thinUrl = "some jdbc url"
    val conn = DriverManager.getConnection(thinUrl)
    rddpartition.foreach { record =>
        conn.createStatement().execute("some statement" )
    }
    conn.commit()
}
相关问题