Search code examples
apache-pig

Pig hadoop returning 0's in division


I am trying to divide H by AB for each line. H / AB in the below line way below divies but produces an out of all ZEROS. I am really confused.

sum_of_scores = FOREACH final_group GENERATE group AS id,
            SUM(s.AB) AS AB,
            SUM(s.H) AS H;


final_final = FOREACH sum_of_scores GENERATE $0 AS month_state, $1 AS AB, $2 AS H;

dump final_final

enter image description here

out_put = FOREACH final_final GENERATE month_state, (H / AB) AS score; 

dump out_put

enter image description here


Solution

  • It appears as though the expression (H / AB) is using integer division, so the arguments should first make use of the cast operators to convert to float, for example.