Skip to content

Commit

Permalink
[SPARK-10178] [SQL] HiveComparisionTest should print out dependent ta…
Browse files Browse the repository at this point in the history
…bles

In `HiveComparisionTest`s it is possible to fail a query of the form `SELECT * FROM dest1`, where `dest1` is the query that is actually computing the incorrect results.  To aid debugging this patch improves the harness to also print these query plans and their results.

Author: Michael Armbrust <[email protected]>

Closes #8388 from marmbrus/generatedTables.
  • Loading branch information
marmbrus authored and rxin committed Aug 25, 2015
1 parent a0c0aae commit 5175ca0
Showing 1 changed file with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package org.apache.spark.sql.hive.execution

import java.io._

import scala.util.control.NonFatal

import org.scalatest.{BeforeAndAfterAll, GivenWhenThen}

import org.apache.spark.{Logging, SparkFunSuite}
Expand Down Expand Up @@ -386,11 +388,45 @@ abstract class HiveComparisonTest
hiveCacheFiles.foreach(_.delete())
}

// If this query is reading other tables that were created during this test run
// also print out the query plans and results for those.
val computedTablesMessages: String = try {
val tablesRead = new TestHive.QueryExecution(query).executedPlan.collect {
case ts: HiveTableScan => ts.relation.tableName
}.toSet

TestHive.reset()
val executions = queryList.map(new TestHive.QueryExecution(_))
executions.foreach(_.toRdd)
val tablesGenerated = queryList.zip(executions).flatMap {
case (q, e) => e.executedPlan.collect {
case i: InsertIntoHiveTable if tablesRead contains i.table.tableName =>
(q, e, i)
}
}

tablesGenerated.map { case (hiveql, execution, insert) =>
s"""
|=== Generated Table ===
|$hiveql
|$execution
|== Results ==
|${insert.child.execute().collect().mkString("\n")}
""".stripMargin
}.mkString("\n")

} catch {
case NonFatal(e) =>
logError("Failed to compute generated tables", e)
s"Couldn't compute dependent tables: $e"
}

val errorMessage =
s"""
|Results do not match for $testCaseName:
|$hiveQuery\n${hiveQuery.analyzed.output.map(_.name).mkString("\t")}
|$resultComparison
|$computedTablesMessages
""".stripMargin

stringToFile(new File(wrongDirectory, testCaseName), errorMessage + consoleTestCase)
Expand Down

0 comments on commit 5175ca0

Please sign in to comment.