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-15776][SQL] Divide Expression inside Aggregation function is casted to wrong type #13651

Closed
wants to merge 6 commits into from

Conversation

clockfly
Copy link
Contributor

@clockfly clockfly commented Jun 13, 2016

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

@@ -2847,4 +2847,15 @@ class SQLQuerySuite extends QueryTest with SharedSQLContext {
test("SPARK-15887: hive-site.xml should be loaded") {
assert(spark.sessionState.newHadoopConf().get("hive.in.test") == "true")
}

test("SPARK-15776 Divide expression inside an Aggregation function should not " +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need some low level unit test instead of end-to-end test

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cloud-fan

It involves Analyzer, low level unit test is hard to cover that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TypeCoercionSuite

@SparkQA
Copy link

SparkQA commented Jun 14, 2016

Test build #60439 has finished for PR 13651 at commit df08eea.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@yhuai
Copy link
Contributor

yhuai commented Jun 14, 2016

I think we need to explain the inconsistent behavior in the PR description, which is the main reason of making this change. (right now, if we run select 1/2, the result is 0.5. However, select sum(1/2) will return 0).


// Cast integer to double
ruleTest(analyzer, sum(Divide(4, 3)), sum(Divide(Cast(4, DoubleType), Cast(3, DoubleType))))
// left expression is already Double, skip
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if left expression is int and right expression is double?

@SparkQA
Copy link

SparkQA commented Jun 14, 2016

Test build #60515 has finished for PR 13651 at commit bce5ea7.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@clockfly clockfly changed the title [SPARK-15776][SQL] Divide Expression inside Aggregation function is casted to wrong type [SPARK-15776][SQL][WIP] Divide Expression inside Aggregation function is casted to wrong type Jun 14, 2016
@clockfly clockfly force-pushed the SPARK-15776 branch 6 times, most recently from 3dd03b7 to ab4ada0 Compare June 14, 2016 23:07
@clockfly clockfly changed the title [SPARK-15776][SQL][WIP] Divide Expression inside Aggregation function is casted to wrong type [SPARK-15776][SQL] Divide Expression inside Aggregation function is casted to wrong type Jun 14, 2016
@clockfly clockfly force-pushed the SPARK-15776 branch 2 times, most recently from 1787c05 to c7e0b33 Compare June 14, 2016 23:29
@rxin
Copy link
Contributor

rxin commented Jun 14, 2016

cc @hvanhovell

@SparkQA
Copy link

SparkQA commented Jun 15, 2016

Test build #60527 has finished for PR 13651 at commit f539392.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Jun 15, 2016

Test build #60524 has finished for PR 13651 at commit d8f3263.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Jun 15, 2016

Test build #60528 has finished for PR 13651 at commit ef83429.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Jun 15, 2016

Test build #60529 has finished for PR 13651 at commit 3dd03b7.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Jun 15, 2016

Test build #60532 has finished for PR 13651 at commit 659f17c.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Jun 15, 2016

Test build #60533 has finished for PR 13651 at commit 1787c05.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Jun 15, 2016

Test build #60535 has finished for PR 13651 at commit c7e0b33.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Jun 15, 2016

Test build #60536 has finished for PR 13651 at commit ff3aa3b.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Jun 15, 2016

Test build #60551 has finished for PR 13651 at commit 3735411.

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

@Sephiroth-Lin
Copy link
Contributor

LGTM thank you

checkConsistencyBetweenInterpretedAndCodegen(Divide, tpe, tpe)
}
}

test("/ (Divide) for integral type") {
test("SPARK-15776: Divide report unresolved when children's data type is " +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This suite is to test the correctness, not resolution.
BTW, the resolution logic is defined by ExpectedInputTypes, I think we don't need to test it again for divide.

@clockfly clockfly force-pushed the SPARK-15776 branch 4 times, most recently from 70d4cc6 to da25d7a Compare June 15, 2016 19:20
@clockfly
Copy link
Contributor Author

@hvanhovell @cloud-fan Thanks! Updated.

@cloud-fan
Copy link
Contributor

LGTM, pending jenkins

@SparkQA
Copy link

SparkQA commented Jun 15, 2016

Test build #60586 has finished for PR 13651 at commit 2589b57.

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

@SparkQA
Copy link

SparkQA commented Jun 15, 2016

Test build #60590 has finished for PR 13651 at commit cbbc67c.

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

@hvanhovell
Copy link
Contributor

LGTM, pending jenkins

@SparkQA
Copy link

SparkQA commented Jun 15, 2016

Test build #60591 has finished for PR 13651 at commit da25d7a.

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

@cloud-fan
Copy link
Contributor

merging to master/2.0!

@rxin
Copy link
Contributor

rxin commented Jun 15, 2016

@clockfly can you add "Closes # #13524 " to the pr description before we merge.

@asfgit asfgit closed this in 9bd80ad Jun 15, 2016
asfgit pushed a commit that referenced this pull request Jun 15, 2016
…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 <seanzhong@databricks.com>

Closes #13651 from clockfly/SPARK-15776.

(cherry picked from commit 9bd80ad)
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
@SparkQA
Copy link

SparkQA commented Jun 15, 2016

Test build #60592 has finished for PR 13651 at commit 8fc6ba7.

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

LuciferYang pushed a commit that referenced this pull request Jan 26, 2024
### What changes were proposed in this pull request?
The pr aims to upgrade `Netty` from `4.1.100.Final` to `4.1.106.Final`.

### Why are the changes needed?
- To bring the latest bug fixes
Automatically close Http2StreamChannel when Http2FrameStreamExceptionreaches end ofChannelPipeline ([#13651](netty/netty#13651))
Symbol not found: _netty_jni_util_JNI_OnLoad ([#13695](netty/netty#13728))

- 4.1.106.Final release note: https://netty.io/news/2024/01/19/4-1-106-Final.html
- 4.1.105.Final release note: https://netty.io/news/2024/01/16/4-1-105-Final.html
- 4.1.104.Final release note: https://netty.io/news/2023/12/15/4-1-104-Final.html
- 4.1.103.Final release note: https://netty.io/news/2023/12/13/4-1-103-Final.html
- 4.1.101.Final release note: https://netty.io/news/2023/11/09/4-1-101-Final.html

### Does this PR introduce _any_ user-facing change?
No.

### How was this patch tested?
Pass GA.

### Was this patch authored or co-authored using generative AI tooling?
No.

Closes #44384 from panbingkun/SPARK-46432.

Lead-authored-by: panbingkun <panbingkun@baidu.com>
Co-authored-by: panbingkun <pbk1982@gmail.com>
Signed-off-by: yangjie01 <yangjie01@baidu.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
8 participants