dedpo
dedpo

Reputation: 502

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

Upvotes: 1

Views: 658

Answers (2)

Ryan Connelly
Ryan Connelly

Reputation: 1

To expand upon the answer above, each column should explicitly be cast to a float:

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

Upvotes: 0

alykhank
alykhank

Reputation: 453

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.

Upvotes: 2

Related Questions