Skip to content
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

Closed
wants to merge 2 commits into from

Conversation

10110346
Copy link
Contributor

@10110346 10110346 commented May 9, 2017

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

@dongjoon-hyun
Copy link
Member

Hi, @10110346 .
What about round?

@10110346
Copy link
Contributor Author

10110346 commented May 10, 2017

"round" has the same problem. @dongjoon-hyun . Actually, this PR can solve the problem for both of them

@dongjoon-hyun
Copy link
Member

Then, let's change the title and description of this PR and the JIRA.
Also, could you add more test cases for round, too?

@10110346
Copy link
Contributor Author

ok, i will do it, thanks @dongjoon-hyun

@10110346 10110346 changed the title [SPARK-20665][SQL]"Bround" function return NULL [SPARK-20665][SQL]"Bround" and "Round" function return NULL May 10, 2017
@10110346 10110346 force-pushed the wip_lx_0509 branch 2 times, most recently from f5ef3e7 to b76f802 Compare May 10, 2017 02:04
@10110346
Copy link
Contributor Author

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
Copy link
Contributor

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?

@10110346
Copy link
Contributor Author

10110346 commented May 11, 2017

@cloud-fan
I have tested in mysql:
mysql> select round(12.3, 2);
+----------------+
| round(12.3, 2) |
+----------------+
| 12.30 |
+----------------+

Also,I tested in spark1.4, as follows:

select round(12.3,2)
+-------+
| _c0 |
+-------+
| 12.3 |
+-------+

@cloud-fan
Copy link
Contributor

LGTM, cc @gatorsmile to double check

@gatorsmile
Copy link
Member

ok to test

@gatorsmile
Copy link
Member

Yeah. This is a right fix. I checked Hive and it behaves the same.

hive> SELECT round(3.1415925, 7), round(3.1415925, 8), round(3.1415925, 9), round(3.1415925, 10), round(3.1415925, 100), round(3.1415925, 6), round(null, 8);
OK
3.1415925	3.1415925	3.1415925	3.1415925	3.1415925	3.141593	NULL

Before the fix, we return a wrong result.

spark-sql> SELECT round(3.1415925, 7), round(3.1415925, 8), round(3.1415925, 9), round(3.1415925, 10), round(3.1415925, 100), round(3.1415925, 6), round(null, 8);
3.1415925	NULL	NULL	NULL	NULL	3.141593	NULL

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))
Copy link
Member

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"

Copy link
Contributor

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

@SparkQA
Copy link

SparkQA commented May 11, 2017

Test build #76820 has finished for PR 17906 at commit 09712e1.

  • This patch fails from timeout after a configured wait of `250m`.
  • This patch merges cleanly.
  • This patch adds no public classes.

@dongjoon-hyun
Copy link
Member

Retest this please.

@SparkQA
Copy link

SparkQA commented May 11, 2017

Test build #76832 has finished for PR 17906 at commit 09712e1.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@cloud-fan
Copy link
Contributor

hi @10110346 , can you set the affected versions more accurate in the JIRA ticket? Does Spark 2.0 has the same issue? We rely on that information to decide which branches we want to backport this patch. Thanks!

@10110346
Copy link
Contributor Author

@cloud-fan ok, I will do it

@10110346
Copy link
Contributor Author

@cloud-fan Spark 2.0 and Spark 2.1 have the same issue. I have updated the affected versions in the JIRA. Thanks!

asfgit pushed a commit that referenced this pull request May 12, 2017
## 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>
@asfgit asfgit closed this in 2b36eb6 May 12, 2017
asfgit pushed a commit that referenced this pull request May 12, 2017
   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>
@cloud-fan
Copy link
Contributor

thanks, merging to master/2.2/2.1/2.0!

asfgit pushed a commit that referenced this pull request May 12, 2017
   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>
robert3005 pushed a commit to palantir/spark that referenced this pull request May 19, 2017
## 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.
liyichao pushed a commit to liyichao/spark that referenced this pull request May 24, 2017
## 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.
dataknocker pushed a commit to dataknocker/spark that referenced this pull request Jun 16, 2017
## 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.
jzhuge pushed a commit to jzhuge/spark that referenced this pull request Aug 20, 2018
   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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants