Skip to content

Commit 88b72db

Browse files
committed
Test ascending and descending sort orders.
1 parent f27be09 commit 88b72db

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

sql/catalyst/src/main/java/org/apache/spark/sql/execution/UnsafeExternalRowSorter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ public Iterator<InternalRow> sort(Iterator<InternalRow> inputIterator) throws IO
178178
* Return true if UnsafeExternalRowSorter can sort rows with the given schema, false otherwise.
179179
*/
180180
public static boolean supportsSchema(StructType schema) {
181+
// TODO: add spilling note.
181182
for (StructField field : schema.fields()) {
182183
if (UnsafeColumnWriter.forType(field.dataType()) instanceof ObjectUnsafeColumnWriter) {
183184
return false;

sql/core/src/test/scala/org/apache/spark/sql/execution/UnsafeExternalSortSuite.scala

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,28 @@ class UnsafeExternalSortSuite extends SparkPlanTest with BeforeAndAfterAll {
3737
}
3838

3939
// Test sorting on different data types
40-
(DataTypeTestUtils.atomicTypes ++ Set(NullType)).foreach{ dataType =>
41-
for (nullable <- Seq(true, false)) {
42-
RandomDataGenerator.forType(dataType, nullable).foreach { randomDataGenerator =>
43-
test(s"sorting on $dataType with nullable=$nullable") {
44-
val inputData = Seq.fill(1024)(randomDataGenerator()).filter {
45-
case d: Double => !d.isNaN
46-
case f: Float => !java.lang.Float.isNaN(f)
47-
case x => true
48-
}
49-
val inputDf = TestSQLContext.createDataFrame(
50-
TestSQLContext.sparkContext.parallelize(Random.shuffle(inputData).map(v => Row(v))),
51-
StructType(StructField("a", dataType, nullable = true) :: Nil)
52-
)
53-
checkAnswer(
54-
inputDf,
55-
UnsafeExternalSort('a.asc :: Nil, global = false, _: SparkPlan),
56-
Sort('a.asc :: Nil, global = false, _: SparkPlan)
57-
)
40+
// TODO: randomized spilling to ensure that merging is tested at least once for every data type.
41+
(DataTypeTestUtils.atomicTypes ++ Set(NullType)).foreach { dataType =>
42+
for (
43+
nullable <- Seq(true, false);
44+
sortOrder <- Seq('a.asc :: Nil, 'a.desc :: Nil);
45+
randomDataGenerator <- RandomDataGenerator.forType(dataType, nullable)
46+
) {
47+
test(s"sorting on $dataType with nullable=$nullable, sortOrder=$sortOrder") {
48+
val inputData = Seq.fill(1024)(randomDataGenerator()).filter {
49+
case d: Double => !d.isNaN
50+
case f: Float => !java.lang.Float.isNaN(f)
51+
case x => true
5852
}
53+
val inputDf = TestSQLContext.createDataFrame(
54+
TestSQLContext.sparkContext.parallelize(Random.shuffle(inputData).map(v => Row(v))),
55+
StructType(StructField("a", dataType, nullable = true) :: Nil)
56+
)
57+
checkAnswer(
58+
inputDf,
59+
UnsafeExternalSort(sortOrder, global = false, _: SparkPlan),
60+
Sort(sortOrder, global = false, _: SparkPlan)
61+
)
5962
}
6063
}
6164
}

0 commit comments

Comments
 (0)