@@ -19,7 +19,6 @@ package org.apache.spark.sql.execution
19
19
20
20
import org .apache .spark .SparkFunSuite
21
21
import org .apache .spark .sql .catalyst .analysis .UnresolvedAttribute
22
- import org .apache .spark .sql .catalyst .expressions .BoundReference
23
22
import org .apache .spark .sql .catalyst .util ._
24
23
import org .apache .spark .sql .test .TestSQLContext
25
24
import org .apache .spark .sql .{DataFrame , DataFrameHolder , Row }
@@ -145,12 +144,15 @@ class SparkPlanTest extends SparkFunSuite {
145
144
* instantiate a reference implementation of the physical operator
146
145
* that's being tested. The result of executing this plan will be
147
146
* treated as the source-of-truth for the test.
147
+ * @param sortAnswers if true, the answers will be sorted by their toString representations prior
148
+ * to being compared.
148
149
*/
149
150
protected def checkAnswer (
150
151
input : DataFrame ,
151
152
planFunction : SparkPlan => SparkPlan ,
152
- expectedPlanFunction : SparkPlan => SparkPlan ): Unit = {
153
- SparkPlanTest .checkAnswer(input, planFunction, expectedPlanFunction) match {
153
+ expectedPlanFunction : SparkPlan => SparkPlan ,
154
+ sortAnswers : Boolean ): Unit = {
155
+ SparkPlanTest .checkAnswer(input, planFunction, expectedPlanFunction, sortAnswers) match {
154
156
case Some (errorMessage) => fail(errorMessage)
155
157
case None =>
156
158
}
@@ -175,7 +177,8 @@ object SparkPlanTest {
175
177
def checkAnswer (
176
178
input : DataFrame ,
177
179
planFunction : SparkPlan => SparkPlan ,
178
- expectedPlanFunction : SparkPlan => SparkPlan ): Option [String ] = {
180
+ expectedPlanFunction : SparkPlan => SparkPlan ,
181
+ sortAnswers : Boolean ): Option [String ] = {
179
182
180
183
val outputPlan = planFunction(input.queryExecution.sparkPlan)
181
184
val expectedOutputPlan = expectedPlanFunction(input.queryExecution.sparkPlan)
@@ -210,7 +213,7 @@ object SparkPlanTest {
210
213
return Some (errorMessage)
211
214
}
212
215
213
- compareAnswers(actualAnswer, expectedAnswer).map { errorMessage =>
216
+ compareAnswers(actualAnswer, expectedAnswer, sortAnswers ).map { errorMessage =>
214
217
s """
215
218
| Results do not match.
216
219
| Actual result Spark plan:
@@ -262,7 +265,8 @@ object SparkPlanTest {
262
265
263
266
private def compareAnswers (
264
267
sparkAnswer : Seq [Row ],
265
- expectedAnswer : Seq [Row ]): Option [String ] = {
268
+ expectedAnswer : Seq [Row ],
269
+ sort : Boolean = true ): Option [String ] = {
266
270
def prepareAnswer (answer : Seq [Row ]): Seq [Row ] = {
267
271
// Converts data to types that we can do equality comparison using Scala collections.
268
272
// For BigDecimal type, the Scala type has a better definition of equality test (similar to
@@ -277,7 +281,11 @@ object SparkPlanTest {
277
281
case o => o
278
282
})
279
283
}
280
- converted.sortBy(_.toString())
284
+ if (sort) {
285
+ converted.sortBy(_.toString())
286
+ } else {
287
+ converted
288
+ }
281
289
}
282
290
if (prepareAnswer(expectedAnswer) != prepareAnswer(sparkAnswer)) {
283
291
val errorMessage =
0 commit comments