Skip to content

Commit b20837b

Browse files
committed
Add failing test for new NaN comparision ordering
1 parent 5b88b2b commit b20837b

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -743,18 +743,27 @@ class DataFrameSuite extends QueryTest with SQLTestUtils {
743743
df.col("t.``")
744744
}
745745

746-
test("SPARK-8797: sort by float column containing NaN") {
746+
test("SPARK-8797: sort by float column containing NaN should not crash") {
747747
val inputData = Seq.fill(10)(Tuple1(Float.NaN)) ++ (1 to 1000).map(x => Tuple1(x.toFloat))
748748
val df = Random.shuffle(inputData).toDF("a")
749749
df.orderBy("a").collect()
750750
}
751751

752-
test("SPARK-8797: sort by double column containing NaN") {
752+
test("SPARK-8797: sort by double column containing NaN should not crash") {
753753
val inputData = Seq.fill(10)(Tuple1(Double.NaN)) ++ (1 to 1000).map(x => Tuple1(x.toDouble))
754754
val df = Random.shuffle(inputData).toDF("a")
755755
df.orderBy("a").collect()
756756
}
757757

758+
test("SPARK-9146: NaN is greater than all other non-NaN numeric values") {
759+
val maxDouble = Seq(Double.NaN, Double.PositiveInfinity, Double.MaxValue)
760+
.map(Tuple1.apply).toDF("a").selectExpr("max(a)").first()
761+
assert(java.lang.Double.isNaN(maxDouble.getDouble(0)))
762+
val maxFloat = Seq(Float.NaN, Float.PositiveInfinity, Float.MaxValue)
763+
.map(Tuple1.apply).toDF("a").selectExpr("max(a)").first()
764+
assert(java.lang.Float.isNaN(maxFloat.getFloat(0)))
765+
}
766+
758767
test("SPARK-8072: Better Exception for Duplicate Columns") {
759768
// only one duplicate column present
760769
val e = intercept[org.apache.spark.sql.AnalysisException] {

0 commit comments

Comments
 (0)