Home | About | Sematext search-lucene.com search-hadoop.com
 Search Hadoop and all its subprojects:

Switch to Threaded View
Pig, mail # user - question about AVG


Copy link to this message
-
question about AVG
Haitao Yao 2012-02-15, 06:19
hi, all
here's my pig script:

A = load 'input' as (b:bag{t:(x:int, y:int)});
B = foreach A generate AVG(b.x);
describe B;

 it works well.
 if the b.x is char array, the problems arise:
A = load 'input' as (b:bag{t:(x:chararray, y:int)});
B = foreach A generate AVG((int)b.x);
2012-02-15 14:17:17,937 [main] ERROR org.apache.pig.tools.grunt.Grunt - ERROR 1052:
<line 4, column 28> Cannot cast bag with schema :bag{:tuple(x:chararray)} to int
Details at logfile: /tmp/pig_1329286634873.log

Why?  How can I calculate the avg of b.x if b.x must be a chararray?
here's the running snapshot in Grunt:

grunt> A = load 'input' as (b:bag{t:(x:int, y:int)});
grunt> B = foreach A generate AVG(b.x);
grunt> describe B;
B: {double}
grunt> A = load 'input' as (b:bag{t:(x:chararray, y:int)});
grunt> B = foreach A generate AVG((int)b.x);
2012-02-15 14:17:17,937 [main] ERROR org.apache.pig.tools.grunt.Grunt - ERROR 1052:
<line 4, column 28> Cannot cast bag with schema :bag{:tuple(x:chararray)} to int
Details at logfile: /tmp/pig_1329286634873.log
grunt>

thanks.