Skip to content

Commit

Permalink
[SPARK-8782] [SQL] Fix code generation for ORDER BY NULL
Browse files Browse the repository at this point in the history
This fixes code generation for queries containing `ORDER BY NULL`.  Previously, the generated code would fail to compile.

Author: Josh Rosen <joshrosen@databricks.com>

Closes apache#7179 from JoshRosen/generate-order-fixes and squashes the following commits:

6ef49a6 [Josh Rosen] Fix ORDER BY NULL
0036696 [Josh Rosen] Add regression test for SPARK-8782 (ORDER BY NULL)
  • Loading branch information
JoshRosen authored and rxin committed Jul 3, 2015
1 parent e589e71 commit d983819
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ class CodeGenContext {
// use c1 - c2 may overflow
case dt: DataType if isPrimitiveType(dt) => s"($c1 > $c2 ? 1 : $c1 < $c2 ? -1 : 0)"
case BinaryType => s"org.apache.spark.sql.catalyst.util.TypeUtils.compareBinary($c1, $c2)"
case NullType => "0"
case other => s"$c1.compare($c2)"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1451,4 +1451,11 @@ class SQLQuerySuite extends QueryTest with BeforeAndAfterAll with SQLTestUtils {
checkAnswer(sql("SELECT a.b FROM t ORDER BY b[0].d"), Row(Seq(Row(1))))
}
}

test("SPARK-8782: ORDER BY NULL") {
withTempTable("t") {
Seq((1, 2), (1, 2)).toDF("a", "b").registerTempTable("t")
checkAnswer(sql("SELECT * FROM t ORDER BY NULL"), Seq(Row(1, 2), Row(1, 2)))
}
}
}

0 comments on commit d983819

Please sign in to comment.