-
Notifications
You must be signed in to change notification settings - Fork 29.1k
[SPARK-23281][SQL] Query produces results in incorrect order when a composite order by clause refers to both original columns and aliases #20453
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,6 @@ | |
| package org.apache.spark.sql | ||
|
|
||
| import java.io.File | ||
| import java.math.MathContext | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BTW, please do not remove the unnecessary import next time. Thanks! When I backported it to 2.2, I hit a build break issue because it is still being used by the other test cases in 2.2
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gatorsmile Oh.. OK.. Sorry about it. I will not remove next time. |
||
| import java.net.{MalformedURLException, URL} | ||
| import java.sql.Timestamp | ||
| import java.util.concurrent.atomic.AtomicBoolean | ||
|
|
@@ -1618,6 +1617,46 @@ class SQLQuerySuite extends QueryTest with SharedSQLContext { | |
| } | ||
| } | ||
|
|
||
| test("SPARK-23281: verify the correctness of sort direction on composite order by clause") { | ||
| withTempView("src") { | ||
| Seq[(Integer, Integer)]( | ||
| (1, 1), | ||
| (1, 3), | ||
| (2, 3), | ||
| (3, 3), | ||
| (4, null), | ||
| (5, null) | ||
| ).toDF("key", "value").createOrReplaceTempView("src") | ||
|
|
||
| checkAnswer(sql( | ||
| """ | ||
| |SELECT MAX(value) as value, key as col2 | ||
| |FROM src | ||
| |GROUP BY key | ||
| |ORDER BY value desc, key | ||
| """.stripMargin), | ||
| Seq(Row(3, 1), Row(3, 2), Row(3, 3), Row(null, 4), Row(null, 5))) | ||
|
|
||
| checkAnswer(sql( | ||
| """ | ||
| |SELECT MAX(value) as value, key as col2 | ||
| |FROM src | ||
| |GROUP BY key | ||
| |ORDER BY value desc, key desc | ||
| """.stripMargin), | ||
| Seq(Row(3, 3), Row(3, 2), Row(3, 1), Row(null, 5), Row(null, 4))) | ||
|
|
||
| checkAnswer(sql( | ||
| """ | ||
| |SELECT MAX(value) as value, key as col2 | ||
| |FROM src | ||
| |GROUP BY key | ||
| |ORDER BY value asc, key desc | ||
| """.stripMargin), | ||
| Seq(Row(null, 5), Row(null, 4), Row(3, 3), Row(3, 2), Row(3, 1))) | ||
| } | ||
| } | ||
|
|
||
| test("run sql directly on files") { | ||
| val df = spark.range(100).toDF() | ||
| withTempPath(f => { | ||
|
|
||
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.
A good catch! Is this a bug since 1.6.x?
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.
@gatorsmile Yeah.. seems like it sean.