将变量发送到 Mapper 类

发布于 2024-11-25 09:12:03 字数 1130 浏览 1 评论 0原文

我试图从用户那里获取输入并将其传递给我创建的映射器类,但每当该值总是初始化为零而不是使用用户输入的实际值时。

如何确保每当我获取变量时它始终保持相同的值。我注意到 job1.setMapperClass(Parallel_for.class);创建该类的实例,从而强制变量重新初始化为其原始值。下面是两个课程的链接。我试图从 RunnerTool 类中获取时间值。

<一href="https://docs.google.com/leaf?id=0BwSPoDdRDme8NzVmYWRlODctNmEzNC00ZjcwLWEzZDEtZTJiODVmNDI0NWZk&hl=en_U S%20https://docs.google.com/leaf?id=0BwSPoDdRDme8NDE1Yzc4N2MtYTM0Yy00M2MxLWIzOWMtMmE1YjhlNmU4NmM3&hl=en_US" rel="nofollow">链接到 Java TestFor 类

链接到RunnerTool 类

// Mapper 中的设置方法

@Override
public void setup(Context context) {
    int defaultValue = 1;
    times = context.getConfiguration().getInt("parallel_for_iteration", defaultValue );
    LOG.info(context.getConfiguration().get("parallel_for_iteration") + " Actually name from the commandline");
    LOG.info(times + " Actually number of iteration from the commandline");
}

// RunnerTools 类

conf.setInt(ITERATION, times);

I am trying to get an input from the user and pass it to my mapper class that I have created but whenever the value always initialises to zero instead of using the actual value the user input.

How can make sure that whenever I get the variable it always maintain the same value. I have noticed that job1.setMapperClass(Parallel_for.class); creates an instance of the class hence forcing the variable to reinitialize to its original value. Below is the link to the two classes. I am trying to get the value of times from RunnerTool class.

Link to Java TestFor class

Link to RunnerTool class

// setup method in the Mapper

@Override
public void setup(Context context) {
    int defaultValue = 1;
    times = context.getConfiguration().getInt("parallel_for_iteration", defaultValue );
    LOG.info(context.getConfiguration().get("parallel_for_iteration") + " Actually name from the commandline");
    LOG.info(times + " Actually number of iteration from the commandline");
}

// RunnerTools class

conf.setInt(ITERATION, times);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

墨落成白 2024-12-02 09:12:03

您应该注意,映射器类将在许多集群节点上重新创建,因此运行作业时对映射器类实例所做的任何初始化都不会影响其他节点。技术相关的 jar 文件将分布在节点之间,然后在那里创建映射器。
因此,正如上面的答案所指出的,将信息传递给映射器的唯一方法是使用 Configuration 类。

You should note that mapper class will be recreated on many cluster nodes so any initalization done to the instance of the mapper class when running the job will not affect other nodes. Technically relevant jar file/s will be distributed among nodes and then mappers will be created there.
So as pointed in the answer above, the only way to pass information to the mappers is using Configuration class.

極樂鬼 2024-12-02 09:12:03

Mapper get是通过反射初始化的,所以不能让用户与mapper类交互。

相反,您拥有 Configuration 对象,如果您要设置作业,则必须提供该对象。您可以使用 conf.set("YOUR KEY", "YOUR VALUE") 进行设置。在您的 Mapper 类中,您可以重写名为 setup(Context context) 的方法,您可以使用 context.getConfiguration().get("YOUR密钥”)。也许可以保存到您的映射器局部变量中。

Mapper get's initialized by reflection, so you can not let the user interact with the mapper class.

Instead you have your Configuration object, which you have to provide if you're setting up your job. There you can set this using conf.set("YOUR KEY", "YOUR VALUE"). In your Mapper class you can override a method called setup(Context context), there you can get the value using context.getConfiguration().get("YOUR KEY"). And maybe save to your mapper local variable.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文