Github user wojtek-szymanski commented on a diff in the pull request:
https://github.com/apache/spark/pull/17075#discussion_r104327814
--- Diff:
sql/core/src/test/scala/org/apache/spark/sql/MathFunctionsSuite.scala ---
@@ -233,6 +233,18 @@ class MathFunctionsSuite extends QueryTest with
SharedSQLContext {
)
}
+ test("round/bround with data frame from a local Seq of Product") {
+ val df = spark.createDataFrame(Seq(NumericRow(BigDecimal("5.9"))))
--- End diff --
The fundamental difference is in the underlying row type assigned to
dataframe/dataset. Dataframe is based on `GenericInternalRow`, while Dataset
uses `UnsafeRow`. During evaluation of round expression, method `getDecimal` is
called on a row, see
[BoundAttribute.scala#L52](https://github.com/apache/spark/blob/39e2bad6a866d27c3ca594d15e574a1da3ee84cc/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/BoundAttribute.scala#L52).
As a result `GenericInternalRow` returns just an element of an array, which
points to the reference of the original column, see
[rows.scala#L200](https://github.com/apache/spark/blob/97594c29b723f372a5c4c061760015bd78d01f50/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/rows.scala#L200).
Strategy used in `UnsafeRow` is completely different, so new decimal instance
is created, see
[UnsafeRow.java#L399](https://github.com/apache/spark/blob/a1e40b1f5d651305bbd0ba05779263a44f607498/sql/catalyst/src/main/java/org/apache/
spark/sql/catalyst/expressions/UnsafeRow.java#L399).
I hope it helps to explain why only dataframe is affected.
---
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]