Skip to content

Commit

Permalink
Distinguishes sorted and possibly not sorted operations more accurate…
Browse files Browse the repository at this point in the history
…ly in HiveComparisonTest
  • Loading branch information
liancheng committed May 28, 2014
1 parent cf640d8 commit 4241a19
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,3 @@ object Unions {
case other => other :: Nil
}
}

/**
* A pattern that matches (some) sorted operations and returns corresponding sorting orders.
* Currently operations matched by this pattern are guaranteed to be sorted, but not all sorted
* operations are matched by this pattern.
*/
object SortedOperation {
// TODO (lian) detect more sorted operations
def unapply(plan: LogicalPlan): Option[Seq[SortOrder]] = plan match {
case FilteredOperation(_, Sort(order, _)) => Some(order)
case _ => None
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import java.io._
import org.scalatest.{BeforeAndAfterAll, FunSuite, GivenWhenThen}

import org.apache.spark.sql.Logging
import org.apache.spark.sql.catalyst.planning.SortedOperation
import org.apache.spark.sql.catalyst.plans.logical.{ExplainCommand, NativeCommand}
import org.apache.spark.sql.catalyst.planning.PhysicalOperation
import org.apache.spark.sql.catalyst.plans.logical._
import org.apache.spark.sql.catalyst.util._
import org.apache.spark.sql.hive.test.TestHive

Expand Down Expand Up @@ -129,10 +129,18 @@ abstract class HiveComparisonTest
protected def prepareAnswer(
hiveQuery: TestHive.type#HiveQLQueryExecution,
answer: Seq[String]): Seq[String] = {

def isSorted(plan: LogicalPlan): Boolean = plan match {
case _: Join | _: Aggregate | _: BaseRelation | _: Generate | _: Sample | _: Distinct => false
case PhysicalOperation(_, _, Sort(_, _)) => true
case _ => plan.children.iterator.map(isSorted).exists(_ == true)
}

val orderedAnswer = hiveQuery.logical match {
// Clean out non-deterministic time schema info.
case _: NativeCommand => answer.filterNot(nonDeterministicLine).filterNot(_ == "")
case _: ExplainCommand | SortedOperation(_) => answer
case _: ExplainCommand => answer
case plan if isSorted(plan) => answer
case _ => answer.sorted
}
orderedAnswer.map(cleanPaths)
Expand Down

0 comments on commit 4241a19

Please sign in to comment.