GitHub user dongjoon-hyun opened a pull request:
https://github.com/apache/spark/pull/12509
[WIP][SPARK-14639] Add `bround` function in Python/R.
## What changes were proposed in this pull request?
This issue aims to expose Scala `bround` function in Python/R API.
`bround` function is implemented in SPARK-14614 by extending current
`round` function.
We used the following semantics from Hive.
```java
public static double bround(double input, int scale) {
if (Double.isNaN(input) || Double.isInfinite(input)) {
return input;
}
return BigDecimal.valueOf(input).setScale(scale,
RoundingMode.HALF_EVEN).doubleValue();
}
```
After this PR, `pyspark` and `sparkR` also can use `bround` function.
**PySpark**
```python
>>> from pyspark.sql.functions import bround
>>> sqlContext.createDataFrame([(2.5,)], ['a']).select(bround('a',
0).alias('r')).collect()
[Row(r=2.0)]
```
**SparkR**
```r
> df = createDataFrame(sqlContext, data.frame(x=c(2.5,3.5)))
> head(collect(select(df, bround(df$x,0))))
bround(x, 0)
1 2
2 4
```
## How was this patch tested?
Pass the Jenkins tests (including new testcases).
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/dongjoon-hyun/spark SPARK-14639
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/spark/pull/12509.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #12509
----
commit e63e1faea44bb459711008568d917e94b89a9610
Author: Dongjoon Hyun <[email protected]>
Date: 2016-04-19T22:46:06Z
[SPARK-14639] Add bround function in Python/R.
----
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]