-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-15776][SQL] Type coercion incorrect #13524
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
Conversation
|
Test build #60051 has finished for PR 13524 at commit
|
10b906a to
e396735
Compare
|
Test build #60295 has finished for PR 13524 at commit
|
|
Can you put the description in the pull request description? it becomes part of the commit log and would be great to avoid requiring looking up jira. |
|
@rxin Done. Pleas help review, thank you. |
| DecimalPrecision :: | ||
| BooleanEquality :: | ||
| StringToIntegralCasts :: | ||
| Division :: |
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.
Just to be sure: are you moving the Division rule above the FunctionArgumentConversion rule in order to pass correct double arguments to functions? If so, could you add a test for this?
|
I think you can use a simpler case to reproduce this in the description of this PR. Such as: The expected result is: The actual result is: |
|
This seems is a blocking issue. |
|
@Sephiroth-Lin can you close this pull request? Thanks. |
…asted to wrong type
## What changes were proposed in this pull request?
This PR fixes the problem that Divide Expression inside Aggregation function is casted to wrong type, which cause `select 1/2` and `select sum(1/2)`returning different result.
**Before the change:**
```
scala> sql("select 1/2 as a").show()
+---+
| a|
+---+
|0.5|
+---+
scala> sql("select sum(1/2) as a").show()
+---+
| a|
+---+
|0 |
+---+
scala> sql("select sum(1 / 2) as a").schema
res4: org.apache.spark.sql.types.StructType = StructType(StructField(a,LongType,true))
```
**After the change:**
```
scala> sql("select 1/2 as a").show()
+---+
| a|
+---+
|0.5|
+---+
scala> sql("select sum(1/2) as a").show()
+---+
| a|
+---+
|0.5|
+---+
scala> sql("select sum(1/2) as a").schema
res4: org.apache.spark.sql.types.StructType = StructType(StructField(a,DoubleType,true))
```
## How was this patch tested?
Unit test.
This PR is based on #13524 by Sephiroth-Lin
Author: Sean Zhong <[email protected]>
Closes #13651 from clockfly/SPARK-15776.
…asted to wrong type
## What changes were proposed in this pull request?
This PR fixes the problem that Divide Expression inside Aggregation function is casted to wrong type, which cause `select 1/2` and `select sum(1/2)`returning different result.
**Before the change:**
```
scala> sql("select 1/2 as a").show()
+---+
| a|
+---+
|0.5|
+---+
scala> sql("select sum(1/2) as a").show()
+---+
| a|
+---+
|0 |
+---+
scala> sql("select sum(1 / 2) as a").schema
res4: org.apache.spark.sql.types.StructType = StructType(StructField(a,LongType,true))
```
**After the change:**
```
scala> sql("select 1/2 as a").show()
+---+
| a|
+---+
|0.5|
+---+
scala> sql("select sum(1/2) as a").show()
+---+
| a|
+---+
|0.5|
+---+
scala> sql("select sum(1/2) as a").schema
res4: org.apache.spark.sql.types.StructType = StructType(StructField(a,DoubleType,true))
```
## How was this patch tested?
Unit test.
This PR is based on #13524 by Sephiroth-Lin
Author: Sean Zhong <[email protected]>
Closes #13651 from clockfly/SPARK-15776.
(cherry picked from commit 9bd80ad)
Signed-off-by: Wenchen Fan <[email protected]>
What changes were proposed in this pull request?
The only difference is WHEN condition, but will result different output column type(one is bigint, one is double) , so update type coercion order.
How was this patch tested?
Add new UT