03-01-2018 03:06 AM
I'm using impala-2.7.0-cdh5.10.0, and I find execute round() in impala-shell may give unexpected result, while hive can give correct result.
impala> select round(269586/334026 * 100, 2); 80.70999999999999 hive > select round(269586/334026 * 100, 2); 80.71
Is this a known issue?
03-01-2018 09:22 AM
Looks like a client display issue. Both Impala and Hive return a DOUBLE for round(). A DOUBLE cannot precisely represent 80.71 so I'm guessing that technically the results are the same, it's just that the Hive client "pretty prints" the results in a different way than Impala's.
If you require precise rouding results it's recommended you use decimal:
select round(cast(269586 / 334026 * 100 as decimal(17, 15)), 2);