Spark任务执行系列

时间:2017-09-11 12:51:22

标签: apache-spark

我正在驱动程序上运行Spark应用程序。

很简单,如下

val count=0; 
val test_dataframe =//extrenal frame
count=test.count();
println("The count of frame is " + count);

我的问题是,如果在计算帧数后总是执行第三行。在执行数据帧及其计数之前,驱动程序是否可以首先运行println命令?

1 个答案:

答案 0 :(得分:1)

不可能驱动程序在上面提到的代码中test.count()之前执行println是不可能的,因为count是一个撕裂操作,并且调用终端操作会强制spark在继续之前执行计算。

如果你想要异步计数,那么这是一个有效的代码片段:

var future = test.rdd.countAsync
println("The count before future evaluation: " + count)
count = future.get
println("The count after future evaluation: " + count)

请注意,countAsync操作不能直接在数据帧上使用。它可以在RDD上执行。

相关问题