Reputation: 37
I am using pig to read a file and want to pass those data to a java method and count the records. But I am getting exception, kindly help my why I am getting this exception
REGISTER /user/rakeshar/test.jar
DEFINE Test com.msdw.rakesh.Test;
temperature = LOAD 'NYQ_MWDATA_ge2_fact.csv' USING PigStorage(',') AS (period_fundmtls_id:int, metric_def_id:int, real_value:double, currency_unit_id:int, observation_type_cd:chararray, non_currency_unit_id:int);
return_val = com.msdw.rakesh.Test(temperature);
DUMP return_val;
In the above code I getting error on the 4th line, below is the exception
557506 [main] ERROR org.apache.pig.tools.grunt.Grunt - Failed to parse: <line 3, column 0> Syntax error, unexpected symbol at or near 'return_val'
at org.apache.pig.parser.QueryParserDriver.parse(QueryParserDriver.java:235)
Kindly help me out here, as I am new to hadoop and pig.
Upvotes: 0
Views: 943
Reputation: 3284
You have to do a projection to call such a UDF:
return_val = FOREACH temperature GENERATE com.msdw.rakesh.Test(*);
If you want to do some operation like the total number of records in temperature
do
X = GROUP temperature ALL;
return_val = FOREACH XGENERATE com.msdw.rakesh.Test(temperature);
as you probably know, there is the count function in pig already. also, you need to think about scalability. See here http://chimera.labs.oreilly.com/books/1234000001811/ch10.html.
Upvotes: 1