drill-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Karthikeyan Manivannan (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (DRILL-520) ceiling/ceil and floor functions return decimal value instead of an integer
Date Fri, 16 Mar 2018 05:02:00 GMT

    [ https://issues.apache.org/jira/browse/DRILL-520?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16401459#comment-16401459
] 

Karthikeyan Manivannan commented on DRILL-520:
----------------------------------------------

This cannot be fixed simply by changing the return type of the builtin functions (as suggested
in the attached patch) because floating point types (Float4, Float8) have a range that is
beyond what can be represented in any integer type, even in BigInt.

This is what happens if the patch (change the outputType of ceil/floor to Int and use a (int)
cast to return the value of java.lang.Math.ceil/floor) is applied

0: jdbc:drill:zk=local> select floor(cast('340280000.5' as float));

 

| 340280000  |

1 row selected (0.157 seconds)

0: jdbc:drill:zk=local> select floor(cast('3402800000.5' as float));   <--- too big
to represent as Int

| 2147483647  |  <----- Int max

A similar overflow will happen even if a BigInt output type and a 'double' cast is used.

I looked up how ProsgreSQL implements ceil/floor:
|Name|Return Type|Description|Example|Result|
|{{ceil(dp}} or {{numeric}})|same as input)|nearest integer greater than or equal to argument|{{ceil(-42.8)}}|{{-42}}|
|{{floor(dp}} or {{numeric}})|(same as input)|nearest integer less than or equal to argument|{{floor(-42.8)}}|{{-43}}|

where 

_*dp*_ is a double precision 8byte floating-point number
 _*numeric*_ is numeric [ (p, s) ] exact numeric of selectable precision

I am not sure how a the dp/numeric return type is returned as an Int

I think the way to fix this in Drill would be to use BigDecimal as the return type. 

 

 

> ceiling/ceil and floor functions return decimal value instead of an integer
> ---------------------------------------------------------------------------
>
>                 Key: DRILL-520
>                 URL: https://issues.apache.org/jira/browse/DRILL-520
>             Project: Apache Drill
>          Issue Type: Bug
>          Components: Functions - Drill
>    Affects Versions: 1.0.0
>            Reporter: Krystal
>            Assignee: Karthikeyan Manivannan
>            Priority: Critical
>             Fix For: Future
>
>         Attachments: DRILL-520.patch
>
>
> Ran the following queries in drill:
> 0: jdbc:drill:schema=dfs> select ceiling(55.8) from dfs.`student` where rownum=11;
> +------------+
> |   EXPR$0   |
> +------------+
> | 56.0       |
> +------------+
> 0: jdbc:drill:schema=dfs> select floor(55.8) from dfs.`student` where rownum=11;
> +------------+
> |   EXPR$0   |
> +------------+
> | 55.0       |
> +------------+
> The same queries executed from oracle, postgres and mysql returned integer values of
56 and 55.
> Found the following description of the two functions from http://users.atw.hu/sqlnut/sqlnut2-chp-4-sect-4.html
:
> Ceil/Ceiling:
> Rounds a noninteger value upwards to the next greatest integer. Returns an integer value
unchanged.
> Floor:
> Rounds a noninteger value downwards to the next least integer. Returns an integer value
unchanged.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message