pig-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Cheolsoo Park (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (PIG-3926) ROUND_TO function: rounds double/float to fixed number of decimal places
Date Sat, 10 May 2014 23:05:14 GMT

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

Cheolsoo Park updated PIG-3926:
-------------------------------

    Resolution: Fixed
        Status: Resolved  (was: Patch Available)

All patches committed to trunk. Note I removed a unused variable {{dbl}} in TestBuiltin.java
while committing.

Thank you Philip for the awesome work!

> ROUND_TO function: rounds double/float to fixed number of decimal places
> ------------------------------------------------------------------------
>
>                 Key: PIG-3926
>                 URL: https://issues.apache.org/jira/browse/PIG-3926
>             Project: Pig
>          Issue Type: New Feature
>    Affects Versions: 0.12.0
>            Reporter: Philip (flip) Kromer
>            Assignee: Philip (flip) Kromer
>            Priority: Minor
>              Labels: builtin, function, math
>             Fix For: 0.13.0
>
>         Attachments: 0001-ROUND_TO-handles-nulls-accepts-rounding-mode.patch, 0001-Unit-tests-for-ROUND.patch,
0002-ROUND_TO-UDF-safely-rounds-values-to-given-precision.patch
>
>
> The too-often used trick of rounding to a fixed number of decimal places by writing '1000
* Math.round(num / 1000.0)' is not only unsightly, it's numerically imprecise (http://stackoverflow.com/a/12684082/41857).
The attached patch adds a function to do this.
> ROUND_TO(val, digits) accepts a single float or double value, along with an integer number
of digits, and returns the value to that number of decimal places 
> Examples:  
> {code}
> ROUND_TO(3.14159f, 3) -- returns a float 3.142
> ROUND_TO(3.14159d, 0) -- returns a double 3.0.
> {code}
> I also added unit tests for ROUND -- there were none before that I could find.
> I don't know how to write a unit test that the schema correctly routes to FloatRoundTo
and DoubleRoundTo -- if the ones I provided are insufficient please point me to a simple example
to emulate.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Mime
View raw message