我无法从 foreach 中调用宏,例如
DEFINE valid_attribute(id,attribute)
RETURNS result {
data = LOAD '/user/sathish/sessAttr' AS (id:chararray,browser_version:chararray);
filtered_data = FILTER data BY id == '$id' AND $attribute is NOT null;
$result = foreach filtered_data generate $attribute;
};
ip = load '/user/sathish/macros/inputParams' AS (id:chararray,attribute:chararray);
op = foreach ip {generate valid_attribute('ip::id','ip:attribute');};
dump op;
调用相同时出现以下异常:
2013-06-25 04:47:42,239 [main] ERROR org.apache.pig.tools.grunt.Grunt - ERROR 1070: Could not resolve valid_attribute using imports: [, org.apache.pig.builtin., org.apache.pig.impl.builtin.]
最佳答案
您不能以这种方式使用宏。宏返回一个关系(表),而不是一个单独的值。 GENERATE
用于在您的关系中生成单独的值。您使用宏的方式看起来就像是在尝试使用 UDF,这就是 Pig 在其默认类路径中查找函数的原因,就像在任何 UDF 中一样。
关于hadoop - 无法在 FOREACH block 内调用 PIG 宏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17296706/