如何在pig中增加jythonudfs中的hadoop计数器

bz4sfanl  于 2021-06-04  发布在  Hadoop
关注(0)|答案(2)|浏览(378)

我想监督我的养Pig工作的进展。大部分工作都是在jython编写的udf中完成的。有没有办法从jythonudf中定义/增加hadoop计数器?
提前谢谢。

56lgkhnf

56lgkhnf1#

您可以使用 setInt("<counter>", <value>) . 然后,每当udf运行时,调用并使用 setInt("<counter>", getInt("<counter>") + 1) . 我想我在 hive 里也做过类似的事情。
在java文档中。

drkbr07n

drkbr07n2#

我现在无法检查它(对于未经测试的代码感到抱歉),但是在使用pig0.8的java udfs(非常类似)中,应该是这样的:

public class INC_COUNTER extends EvalFunc<DataBag> {

    @Override
    public DataBag exec(Tuple input) throws IOException {

        PigStatusReporter reporter = PigStatusReporter.getInstance();
        if (reporter != null) {
           reporter.getCounter(Counters.EXAMPLE).increment(1);//Counters.EXAMPLE is an enum value
        }
        return null;
    }
}

我希望这能起作用,您可以将此代码转换为JythonUDF的解决方案。

相关问题