简体   繁体   中英

Java Spark broadcast variable in separate file

I need to create a broadcast variable in my driver program and use it in a class in a separate file.

For example I have this in the driver:

public static final Relation[] relations = {
     Test1.getRelationSigleton(),
     Test2.getRelationSigleton()
};

relationsBroadcast = ctx.broadcast(relations);

And in a map step I need to get this:

private Relation[] relations = relationsBroadcast.value();

The problem is that it can't compile because relationsBroadcast hasn't been declared in the scope of the new file.

My solution now is to have the map step in the same file as the driver, but it looks messy and I want to move it out.

正如@rhernando在评论中提到的那样,执行此操作的方法是使用对主类中变量的静态引用。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM