1717
1818package org .apache .spark .sql .execution
1919
20- import org .apache .spark .sql .test .TestSQLContext
2120import org .scalatest .BeforeAndAfterAll
2221
23- import org .apache .spark .sql .{SQLConf , Row }
24- import org .apache .spark .sql .catalyst .CatalystTypeConverters
25- import org .apache .spark .sql .catalyst .expressions ._
26- import org .apache .spark .sql .types ._
22+ import org .apache .spark .sql .SQLConf
23+ import org .apache .spark .sql .catalyst .dsl .expressions ._
24+ import org .apache .spark .sql .test .TestSQLContext
2725
2826import scala .util .Random
2927
@@ -37,28 +35,23 @@ class UnsafeExternalSortSuite extends SparkPlanTest with BeforeAndAfterAll {
3735 TestSQLContext .conf.setConf(SQLConf .CODEGEN_ENABLED , SQLConf .CODEGEN_ENABLED .defaultValue.get)
3836 }
3937
40- private def createRow (values : Any * ): Row = {
41- new GenericRow (values.map(CatalystTypeConverters .convertToCatalyst).toArray)
42- }
43-
4438 test(" basic sorting" ) {
45-
46- val inputData = Seq (
47- (" Hello" , 9 ),
48- (" World" , 4 ),
49- (" Hello" , 7 ),
50- (" Skinny" , 0 ),
51- (" Constantinople" , 9 )
39+ val input = Seq (
40+ (" Hello" , 9 , 1.0 ),
41+ (" World" , 4 , 2.0 ),
42+ (" Hello" , 7 , 8.1 ),
43+ (" Skinny" , 0 , 2.2 ),
44+ (" Constantinople" , 9 , 1.1 )
5245 )
5346
54- val sortOrder : Seq [SortOrder ] = Seq (
55- SortOrder (BoundReference (0 , StringType , nullable = false ), Ascending ),
56- SortOrder (BoundReference (1 , IntegerType , nullable = false ), Descending ))
47+ checkAnswer(
48+ Random .shuffle(input).toDF(" a" , " b" , " c" ),
49+ ExternalSort (' a .asc :: ' b .asc :: Nil , global = false , _ : SparkPlan ),
50+ input.sorted)
5751
5852 checkAnswer(
59- Random .shuffle(inputData),
60- (input : SparkPlan ) => new UnsafeExternalSort (sortOrder, global = false , input),
61- inputData
62- )
53+ Random .shuffle(input).toDF(" a" , " b" , " c" ),
54+ ExternalSort (' b .asc :: ' a .asc :: Nil , global = false , _ : SparkPlan ),
55+ input.sortBy(t => (t._2, t._1)))
6356 }
6457}
0 commit comments