Support Questions
Find answers, ask questions, and share your expertise
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

IMPALA float vs double fraction part usage

IMPALA float vs double fraction part usage

New Contributor

Hi All,


   When I use datatype float VS double I see that when data is ingested with n digit precision in fraction part ex (2.57) , subsequent query output returns 2.5 59999942779541  for float whereas it result exact 2 digit precision for float as shown in example below.  Is there a way we can achieve similar behavior of double for float.

 Problem with float is we need to roundoff the output value explicitly when using in different applications.



[hadoop-data.default.svc.cluster.local:21000] > create table parquet_table_name (x float, y float) STORED AS PARQUET;


[hadoop-data.default.svc.cluster.local:21000] > insert into TABLE test values(2.56,2.57);
Query: insert into TABLE test values(2.56,2.57)
Query submitted at: 2019-04-08 09:56:00 (Coordinator: https://hadoop-data-0:25000)
Query progress can be monitored at: https://hadoop-data-0:25000/query_plan?query_id=634a267b54e95cc1:2f111d6300000000
Modified 1 row(s) in 17.34s
[hadoop-data.default.svc.cluster.local:21000] >
[hadoop-data.default.svc.cluster.local:21000] >
[hadoop-data.default.svc.cluster.local:21000] > select * from test;
Query: select * from test
Query submitted at: 2019-04-08 09:56:25 (Coordinator: https://hadoop-data-0:25000)
Query progress can be monitored at: https://hadoop-data-0:25000/query_plan?query_id=cf4731ca88960669:972a651a00000000
| x | y |
|2.5 59999942779541 | 2.57 |

Fetched 1 row(s) in 2.52s
[hadoop-data.default.svc.cluster.local:21000] >






Re: IMPALA float vs double fraction part usage

Master Collaborator

If you want exact precision to a number of decimal digits, I'd recommend using the DECIMAL data type. Floating point can't exactly represent decimal numbers.


If you're returning a floating point type from a query, then you don't have any real control over the display because it's basically a client-side formatting decision.E.g. your Java code that uses the JDBC drive could take the value and format it however it wants. You *might* be able to get the desired behaviour in impala-shell by using the round() function but that depends on some undocumented behaviour. I'd recommend looking at decimal.

Don't have an account?
Coming from Hortonworks? Activate your account here