[英]Pass parameters from driver to executors in spark
我正在使用spark 2.0.0。 有没有办法将参数从spark驱动程序传递给执行程序? 我尝试了以下内容。
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);
}
}
如上所述,我写了一个自定义mappartition函数来传递参数。 并在分区函数的调用方法中访问静态变量。 当我使用“setmaster(”local“)在我的本地运行时,这很有用。但是在使用.setmaster(”yarn“)的集群上运行时不起作用。(在system.out.println语句中打印为null)
有没有办法将参数从驱动程序传递给执行程序。
我的坏我正在使用私有静态Integer variableThatHastobePassed = null;
该变量不应声明为静态。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.