You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pig.apache.org by Senthil <kv...@gmail.com> on 2015/01/23 20:36:13 UTC

Bigdecimal calculations Issue

Hi,

I have a pig script as specified below :


d1 = LOAD '/user/test/file1' USING PigStorage(',') AS (id,col1);
d2 = LOAD '/user/test/file2' USING PigStorage(',') AS (id2,col2);
d3 = JOIN d1 by id, d2 by id2;
DUMP d3;
TESTOUT2 = FOREACH d3 GENERATE id, col1, col2, col2 + col1, col2 - col1, 
col2/1000, col2/22;
dump TESTOUT2;


file1 has data as

1,2343242343284329473289473298432.2342323094324903248329048320948320943284093284093248320948
2,492234328432947328947329843223094324903248.29048320948320943284093284093248320948
3,299234328432947328947329843223094324903248.29048320948320943284093284093248320948
4,929923432843294732894732984322309432490324.329048320948320943284093284093248320948
5,699234328432947328947329843269292929.29223094324903248329048320948320943284093284093248320948


fiile 2 has data as

1,432827429384234327498324732984732984732984732984732984723984327498324.234
2,249920023943204382049328409324832094823094832094.23
3,2982920023943204382049328409324832094823094832094.9
4,1920023943204382049328409324832094823094832094.292
5,2928282892929.2929

If  I run the pig script above as it is it dumps the data except for  
co2/22 it returns null.

(1,2343242343284329473289473298432.2342323094324903248329048320948320943284093284093248320948,432827429384234327498324732984732984732984732984732984723984327498324.234,4.328274293842343E68,4.328274293842343E68,,)
(2,492234328432947328947329843223094324903248.29048320948320943284093284093248320948,249920023943204382049328409324832094823094832094.23,2.4992051617753283E47,2.4991953170887593E47,,)
(3,299234328432947328947329843223094324903248.29048320948320943284093284093248320948,2982920023943204382049328409324832094823094832094.9,2.982920323177533E48,2.9829197247088756E48,,)
(4,929923432843294732894732984322309432490324.329048320948320943284093284093248320948,1920023943204382049328409324832094823094832094.292,1.9209538666372255E45,1.919094019771539E45,,)
(5,699234328432947328947329843269292929.29223094324903248329048320948320943284093284093248320948,2928282892929.2929,6.992343284329473E35,-6.992343284329473E35,,)


When I change the loading as LOAD '/user/test/file1' USING 
PigStorage(',') AS *(id,col1:bigdecimal)* and LOAD '/user/test/file2' 
USING PigStorage(',') AS *(id2,col2:bigdecimal)**;* the pig scripts 
errors out with the error after DUMP d3;

ERROR 1066: Unable to open iterator for alias TESTOUT2. Backend error : 
Exception while executing [Divide (Name: Divide[bigdecimal] - scope-81 
Operator Key: scope-81) children: [[POProject (Name: 
Project[bigdecimal][3] - scope-78 Operator Key: scope-78) children: null 
at []], [POCast (Name: Cast[bigdecimal] - scope-80 Operator Key: 
scope-80) children: [[ConstantExpression (Name: Constant(22) - scope-79 
Operator Key: scope-79) children: null at []]] at []]] at []]: 
java.lang.ArithmeticException: *Non-terminating decimal expansion; no 
exact representable decimal result.

*If I read the above data as big decimal and divide it by the increments 
of 10 i.e 10,100,1000 it returns proper results whereas when I change 
the denominator to other than these it errors out with above error.

Can someone help to identify the issue.

Thanks,

Senthil.