我使用的是spark 2.0.0。有没有办法将参数从spark驱动程序传递到executors?我尝试了以下方法。
class SparkDriver {
public static void main(String argv[]){
SparkConf conf = new SparkConf().setAppName("test").setMaster("yarn");
SparkSession sparkSession = SparkSession.builder().config(conf).getOrCreate();
Dataset<Row> input = sparkSession.read().load("inputfilepath");
Dataset<Row> modifiedinput = input.mapPartitions(new customMapPartition(5),Encoders.bean(Row.class));
}
class customMapPartition implements MapPartitionsFunction{
private static final long serialVersionUID = -6513655566985939627L;
private static Integer variableThatHastobePassed = null;
public customMapPartition(Integer passedInteger){
customMapPartition.variableThatHastobePassed= passedInteger;
}
@Override
public Iterator<Row> call(Iterator<Row> input) throws Exception {
System.out.println("number that is passed " + variableThatHastobePassed);
}
}
如上所述,我编写了一个自定义的mappartitionfunction来传递参数。并访问分区函数的调用方法中的静态变量。当我在本地使用"setmaster(" local ")运行时,这是有效的。但当我使用.setmaster("yarn")在集群上运行时,这不起作用。(在system.out.println语句中打印null )
有没有办法将参数从驱动程序传递到执行器。
发布于 2016-09-22 08:36:06
我的错误是我使用的是私有静态整数variableThatHastobePassed = null;
该变量不应声明为静态变量。
https://stackoverflow.com/questions/39633730
复制