Skip to content

[SPARK-5002][SQL] Using ascending by default when not specify order in order by #3838

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,11 @@ class SqlParser extends AbstractSparkSQLParser {
)

protected lazy val ordering: Parser[Seq[SortOrder]] =
( rep1sep(singleOrder, ",")
| rep1sep(expression, ",") ~ direction.? ^^ {
case exps ~ d => exps.map(SortOrder(_, d.getOrElse(Ascending)))
( rep1sep(expression ~ direction.? , ",") ^^ {
case exps => exps.map(pair => SortOrder(pair._1, pair._2.getOrElse(Ascending)))
}
)

protected lazy val singleOrder: Parser[SortOrder] =
expression ~ direction ^^ { case e ~ o => SortOrder(e, o) }

protected lazy val direction: Parser[SortDirection] =
( ASC ^^^ Ascending
| DESC ^^^ Descending
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,13 @@ class SQLQuerySuite extends QueryTest with BeforeAndAfterAll {
)
}

test("oder by asc by default when not specify ascending and descending") {
checkAnswer(
sql("SELECT a, b FROM testData2 ORDER BY a desc, b"),
Seq((3, 1), (3, 2), (2, 1), (2,2), (1, 1), (1, 2))
)
}

test("Supporting relational operator '<=>' in Spark SQL") {
val nullCheckData1 = TestData(1,"1") :: TestData(2,null) :: Nil
val rdd1 = sparkContext.parallelize((0 to 1).map(i => nullCheckData1(i)))
Expand Down