简体   繁体   English

Java Spark广播变量在单独的文件中

[英]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); 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. 问题在于它不能编译,因为还没有在新文件的范围内声明RelationsBroadcast。

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在评论中提到的那样,执行此操作的方法是使用对主类中变量的静态引用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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