You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@impala.apache.org by "Taras Bobrovytsky (JIRA)" <ji...@apache.org> on 2017/11/21 21:25:00 UTC

[jira] [Closed] (IMPALA-3436) Round(double, int) should return decimal

     [ https://issues.apache.org/jira/browse/IMPALA-3436?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Taras Bobrovytsky closed IMPALA-3436.
-------------------------------------
    Resolution: Won't Fix

[~dhecht], I agree that doubles in general have problems (such as there being different ways to represent the same double). If customers want to avoid these problems, they should avoid using the double type. Also, as Tim mentioned, they can still get correct rounding behavior by casting to decimal first.

I created IMPALA-6230, to keep track of the required round() changes.

> Round(double, int) should return decimal
> ----------------------------------------
>
>                 Key: IMPALA-3436
>                 URL: https://issues.apache.org/jira/browse/IMPALA-3436
>             Project: IMPALA
>          Issue Type: Improvement
>          Components: Backend
>    Affects Versions: Impala 2.5.0
>            Reporter: Tim Armstrong
>            Assignee: Taras Bobrovytsky
>            Priority: Minor
>              Labels: compatibility, usability
>
> Impala has several versions of round: round(double a), round(double a, int d), round(decimal a, int_type d)
> round(double a) returns a BIGINT, which makes sense because it rounds to the nearest int.
> round(decimal a, int_type d) returns a DECIMAL, which makes sense because it rounds to a decimal digit.
> round(double a, int d) predates DECIMAL support, so it returns a DOUBLE. It is specified to return the nearest double value. 
> E.g. round(cast(1 as DOUBLE) / 10, 1) returns the binary floating point value closest to 0.1. This number has no exact decimal representation. Both 0.100000000000000000000000000 and 0.10000000000000000555 are valid decimal representations of this floating point number.  I.e. if you convert them back to float, you will get the same number.
> This is correct according to floating point conversion rules and the Impala documentation, but it is confusing for two reasons:
> * round() returning a double is a little surprising, because it can't precisely represent the result
> * Impala clients can display the floating-point result in multiple *valid* ways. Different clients have different algorithms for converting floating-point to decimal for display, so even if Impala returns the same result it may appear as 0.1 in one client and 0.10000000000000000555. We don't specify that clients have to use a particular algorithm, so it's valid as long as it converts back to the same float as part of a round-trip.
> We should consider changing the spec of round() in Impala to always return a decimal to avoid this confusion.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)