Skip to content

Commit d983819

Browse files
JoshRosenrxin
authored andcommitted
[SPARK-8782] [SQL] Fix code generation for ORDER BY NULL
This fixes code generation for queries containing `ORDER BY NULL`. Previously, the generated code would fail to compile. Author: Josh Rosen <[email protected]> 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)
1 parent e589e71 commit d983819

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/CodeGenerator.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ class CodeGenContext {
185185
// use c1 - c2 may overflow
186186
case dt: DataType if isPrimitiveType(dt) => s"($c1 > $c2 ? 1 : $c1 < $c2 ? -1 : 0)"
187187
case BinaryType => s"org.apache.spark.sql.catalyst.util.TypeUtils.compareBinary($c1, $c2)"
188+
case NullType => "0"
188189
case other => s"$c1.compare($c2)"
189190
}
190191

sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,4 +1451,11 @@ class SQLQuerySuite extends QueryTest with BeforeAndAfterAll with SQLTestUtils {
14511451
checkAnswer(sql("SELECT a.b FROM t ORDER BY b[0].d"), Row(Seq(Row(1))))
14521452
}
14531453
}
1454+
1455+
test("SPARK-8782: ORDER BY NULL") {
1456+
withTempTable("t") {
1457+
Seq((1, 2), (1, 2)).toDF("a", "b").registerTempTable("t")
1458+
checkAnswer(sql("SELECT * FROM t ORDER BY NULL"), Seq(Row(1, 2), Row(1, 2)))
1459+
}
1460+
}
14541461
}

0 commit comments

Comments
 (0)