Skip to content

Commit 4241a19

Browse files
committed
Distinguishes sorted and possibly not sorted operations more accurately in HiveComparisonTest
1 parent cf640d8 commit 4241a19

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/planning/patterns.scala

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -168,16 +168,3 @@ object Unions {
168168
case other => other :: Nil
169169
}
170170
}
171-
172-
/**
173-
* A pattern that matches (some) sorted operations and returns corresponding sorting orders.
174-
* Currently operations matched by this pattern are guaranteed to be sorted, but not all sorted
175-
* operations are matched by this pattern.
176-
*/
177-
object SortedOperation {
178-
// TODO (lian) detect more sorted operations
179-
def unapply(plan: LogicalPlan): Option[Seq[SortOrder]] = plan match {
180-
case FilteredOperation(_, Sort(order, _)) => Some(order)
181-
case _ => None
182-
}
183-
}

sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveComparisonTest.scala

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import java.io._
2222
import org.scalatest.{BeforeAndAfterAll, FunSuite, GivenWhenThen}
2323

2424
import org.apache.spark.sql.Logging
25-
import org.apache.spark.sql.catalyst.planning.SortedOperation
26-
import org.apache.spark.sql.catalyst.plans.logical.{ExplainCommand, NativeCommand}
25+
import org.apache.spark.sql.catalyst.planning.PhysicalOperation
26+
import org.apache.spark.sql.catalyst.plans.logical._
2727
import org.apache.spark.sql.catalyst.util._
2828
import org.apache.spark.sql.hive.test.TestHive
2929

@@ -129,10 +129,18 @@ abstract class HiveComparisonTest
129129
protected def prepareAnswer(
130130
hiveQuery: TestHive.type#HiveQLQueryExecution,
131131
answer: Seq[String]): Seq[String] = {
132+
133+
def isSorted(plan: LogicalPlan): Boolean = plan match {
134+
case _: Join | _: Aggregate | _: BaseRelation | _: Generate | _: Sample | _: Distinct => false
135+
case PhysicalOperation(_, _, Sort(_, _)) => true
136+
case _ => plan.children.iterator.map(isSorted).exists(_ == true)
137+
}
138+
132139
val orderedAnswer = hiveQuery.logical match {
133140
// Clean out non-deterministic time schema info.
134141
case _: NativeCommand => answer.filterNot(nonDeterministicLine).filterNot(_ == "")
135-
case _: ExplainCommand | SortedOperation(_) => answer
142+
case _: ExplainCommand => answer
143+
case plan if isSorted(plan) => answer
136144
case _ => answer.sorted
137145
}
138146
orderedAnswer.map(cleanPaths)

0 commit comments

Comments
 (0)