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;
}
}
2条答案
按热度按时间56lgkhnf1#
您可以使用
setInt("<counter>", <value>)
. 然后,每当udf运行时,调用并使用setInt("<counter>", getInt("<counter>") + 1)
. 我想我在 hive 里也做过类似的事情。在java文档中。
drkbr07n2#
我现在无法检查它(对于未经测试的代码感到抱歉),但是在使用pig0.8的java udfs(非常类似)中,应该是这样的:
我希望这能起作用,您可以将此代码转换为JythonUDF的解决方案。