-
Notifications
You must be signed in to change notification settings - Fork 28.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SPARK-20665][SQL]"Bround" and "Round" function return NULL #17906
Conversation
Hi, @10110346 . |
"round" has the same problem. @dongjoon-hyun . Actually, this PR can solve the problem for both of them |
Then, let's change the title and description of this PR and the JIRA. |
ok, i will do it, thanks @dongjoon-hyun |
f5ef3e7
to
b76f802
Compare
Please reveiw it,thanks @dongjoon-hyun @cloud-fan |
@@ -546,15 +546,14 @@ class MathExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper { | |||
val bdResults: Seq[BigDecimal] = Seq(BigDecimal(3.0), BigDecimal(3.1), BigDecimal(3.14), | |||
BigDecimal(3.142), BigDecimal(3.1416), BigDecimal(3.14159), | |||
BigDecimal(3.141593), BigDecimal(3.1415927)) | |||
// round_scale > current_scale would result in precision increase | |||
// and not allowed by o.a.s.s.types.Decimal.changePrecision, therefore null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems we are changing the behavior, can you check with other database and see if it's expected to return the original value for this case?
@cloud-fan Also,I tested in spark1.4, as follows:
|
LGTM, cc @gatorsmile to double check |
ok to test |
Yeah. This is a right fix. I checked Hive and it behaves the same.
Before the fix, we return a wrong result.
|
checkAnswer( | ||
sql(s"SELECT bround($bdPi, 7), bround($bdPi, 8), bround($bdPi, 9), bround($bdPi, 10), " + | ||
s"bround($bdPi, 100), bround($bdPi, 6), bround(null, 8)"), | ||
Seq(Row(bdPi, bdPi, bdPi, bdPi, bdPi, BigDecimal("3.141592"), null)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about moving the test case to SQLQueryTestSuite
and create a new file mathFunctions.sql
. You can refer to s.c.s.t.resources/sql-tests/inputs/cast.sql
. To generate the result file, you can run the following command:
SPARK_GENERATE_GOLDEN_FILES=1 build/sbt "sql/test-only *SQLQueryTestSuite"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can do it in a follow-up
Test build #76820 has finished for PR 17906 at commit
|
Retest this please. |
Test build #76832 has finished for PR 17906 at commit
|
hi @10110346 , can you set the |
@cloud-fan ok, I will do it |
@cloud-fan Spark 2.0 and Spark 2.1 have the same issue. I have updated the affected versions in the JIRA. Thanks! |
## What changes were proposed in this pull request? spark-sql>select bround(12.3, 2); spark-sql>NULL For this case, the expected result is 12.3, but it is null. So ,when the second parameter is bigger than "decimal.scala", the result is not we expected. "round" function has the same problem. This PR can solve the problem for both of them. ## How was this patch tested? unit test cases in MathExpressionsSuite and MathFunctionsSuite Author: liuxian <liu.xian3@zte.com.cn> Closes #17906 from 10110346/wip_lx_0509. (cherry picked from commit 2b36eb6) Signed-off-by: Wenchen Fan <wenchen@databricks.com>
spark-sql>select bround(12.3, 2); spark-sql>NULL For this case, the expected result is 12.3, but it is null. So ,when the second parameter is bigger than "decimal.scala", the result is not we expected. "round" function has the same problem. This PR can solve the problem for both of them. unit test cases in MathExpressionsSuite and MathFunctionsSuite Author: liuxian <liu.xian3@zte.com.cn> Closes #17906 from 10110346/wip_lx_0509. (cherry picked from commit 2b36eb6) Signed-off-by: Wenchen Fan <wenchen@databricks.com>
thanks, merging to master/2.2/2.1/2.0! |
spark-sql>select bround(12.3, 2); spark-sql>NULL For this case, the expected result is 12.3, but it is null. So ,when the second parameter is bigger than "decimal.scala", the result is not we expected. "round" function has the same problem. This PR can solve the problem for both of them. unit test cases in MathExpressionsSuite and MathFunctionsSuite Author: liuxian <liu.xian3@zte.com.cn> Closes #17906 from 10110346/wip_lx_0509. (cherry picked from commit 2b36eb6) Signed-off-by: Wenchen Fan <wenchen@databricks.com>
## What changes were proposed in this pull request? spark-sql>select bround(12.3, 2); spark-sql>NULL For this case, the expected result is 12.3, but it is null. So ,when the second parameter is bigger than "decimal.scala", the result is not we expected. "round" function has the same problem. This PR can solve the problem for both of them. ## How was this patch tested? unit test cases in MathExpressionsSuite and MathFunctionsSuite Author: liuxian <liu.xian3@zte.com.cn> Closes apache#17906 from 10110346/wip_lx_0509.
## What changes were proposed in this pull request? spark-sql>select bround(12.3, 2); spark-sql>NULL For this case, the expected result is 12.3, but it is null. So ,when the second parameter is bigger than "decimal.scala", the result is not we expected. "round" function has the same problem. This PR can solve the problem for both of them. ## How was this patch tested? unit test cases in MathExpressionsSuite and MathFunctionsSuite Author: liuxian <liu.xian3@zte.com.cn> Closes apache#17906 from 10110346/wip_lx_0509.
## What changes were proposed in this pull request? add test case to MathExpressionsSuite as apache#17906 ## How was this patch tested? unit test cases Author: liuxian <liu.xian3@zte.com.cn> Closes apache#18082 from 10110346/wip-lx-0524.
spark-sql>select bround(12.3, 2); spark-sql>NULL For this case, the expected result is 12.3, but it is null. So ,when the second parameter is bigger than "decimal.scala", the result is not we expected. "round" function has the same problem. This PR can solve the problem for both of them. unit test cases in MathExpressionsSuite and MathFunctionsSuite Author: liuxian <liu.xian3@zte.com.cn> Closes apache#17906 from 10110346/wip_lx_0509. (cherry picked from commit 2b36eb6) Signed-off-by: Wenchen Fan <wenchen@databricks.com>
What changes were proposed in this pull request?
spark-sql>select bround(12.3, 2);
spark-sql>NULL
For this case, the expected result is 12.3, but it is null.
So ,when the second parameter is bigger than "decimal.scala", the result is not we expected.
"round" function has the same problem. This PR can solve the problem for both of them.
How was this patch tested?
unit test cases in MathExpressionsSuite and MathFunctionsSuite