Reputation: 109
I am unable to call a macro from within a foreach, example
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;
I am getting the below exception when calling the same :
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.]
Upvotes: 1
Views: 1829
Reputation: 5801
You cannot use a macro in this manner. A macro returns a relation (table), not an individual value. GENERATE
is for producing individual values in your relation. The way you have used your macro looks like you are trying to use a UDF, which is why Pig looks in its default classpath to find the function, as it would for any UDF.
Upvotes: 4