Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -443,13 +443,6 @@ class TestHiveContext(sc: SparkContext) extends HiveContext(sc) {
defaultOverrides()

runSqlHive("USE default")

// Just loading src makes a lot of tests pass. This is because some tests do something like
// drop an index on src at the beginning. Since we just pass DDL to hive this bypasses our
// Analyzer and thus the test table auto-loading mechanism.
// Remove after we handle more DDL operations natively.
loadTestTable("src")
loadTestTable("srcpart")
} catch {
case e: Exception =>
logError("FATAL ERROR: Failed to reset TestDB state.", e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,11 @@ abstract class HiveComparisonTest
}

val installHooksCommand = "(?i)SET.*hooks".r
def createQueryTest(testCaseName: String, sql: String, reset: Boolean = true) {
def createQueryTest(
testCaseName: String,
sql: String,
reset: Boolean = true,
tryWithoutResettingFirst: Boolean = false) {
// testCaseName must not contain ':', which is not allowed to appear in a filename of Windows
assert(!testCaseName.contains(":"))

Expand Down Expand Up @@ -240,9 +244,6 @@ abstract class HiveComparisonTest
test(testCaseName) {
logDebug(s"=== HIVE TEST: $testCaseName ===")

// Clear old output for this testcase.
outputDirectories.map(new File(_, testCaseName)).filter(_.exists()).foreach(_.delete())

val sqlWithoutComment =
sql.split("\n").filterNot(l => l.matches("--.*(?<=[^\\\\]);")).mkString("\n")
val allQueries =
Expand All @@ -269,11 +270,32 @@ abstract class HiveComparisonTest
}.mkString("\n== Console version of this test ==\n", "\n", "\n")
}

try {
def doTest(reset: Boolean, isSpeculative: Boolean = false): Unit = {
// Clear old output for this testcase.
outputDirectories.map(new File(_, testCaseName)).filter(_.exists()).foreach(_.delete())

if (reset) {
TestHive.reset()
}

// Many tests drop indexes on src and srcpart at the beginning, so we need to load those
// tables here. Since DROP INDEX DDL is just passed to Hive, it bypasses the analyzer and
// thus the tables referenced in those DDL commands cannot be extracted for use by our
// test table auto-loading mechanism. In addition, the tests which use the SHOW TABLES
// command expect these tables to exist.
val hasShowTableCommand = queryList.exists(_.toLowerCase.contains("show tables"))
for (table <- Seq("src", "srcpart")) {
val hasMatchingQuery = queryList.exists { query =>
val normalizedQuery = query.toLowerCase.stripSuffix(";")
normalizedQuery.endsWith(table) ||
normalizedQuery.contains(s"from $table") ||
normalizedQuery.contains(s"from default.$table")
}
if (hasShowTableCommand || hasMatchingQuery) {
TestHive.loadTestTable(table)
}
}

val hiveCacheFiles = queryList.zipWithIndex.map {
case (queryString, i) =>
val cachedAnswerName = s"$testCaseName-$i-${getMd5(queryString)}"
Expand Down Expand Up @@ -430,12 +452,45 @@ abstract class HiveComparisonTest
""".stripMargin

stringToFile(new File(wrongDirectory, testCaseName), errorMessage + consoleTestCase)
fail(errorMessage)
if (isSpeculative && !reset) {
fail("Failed on first run; retrying")
} else {
fail(errorMessage)
}
}
}

// Touch passed file.
new FileOutputStream(new File(passedDirectory, testCaseName)).close()
}

val canSpeculativelyTryWithoutReset: Boolean = {
val excludedSubstrings = Seq(
"into table",
"create table",
"drop index"
)
!queryList.map(_.toLowerCase).exists { query =>
excludedSubstrings.exists(s => query.contains(s))
}
}

try {
try {
if (tryWithoutResettingFirst && canSpeculativelyTryWithoutReset) {
doTest(reset = false, isSpeculative = true)
} else {
doTest(reset)
}
} catch {
case tf: org.scalatest.exceptions.TestFailedException =>
if (tryWithoutResettingFirst && canSpeculativelyTryWithoutReset) {
logWarning("Test failed without reset(); retrying with reset()")
doTest(reset = true)
} else {
throw tf
}
}
} catch {
case tf: org.scalatest.exceptions.TestFailedException => throw tf
case originalException: Exception =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ abstract class HiveQueryFileTest extends HiveComparisonTest {
runAll) {
// Build a test case and submit it to scala test framework...
val queriesString = fileToString(testCaseFile)
createQueryTest(testCaseName, queriesString)
createQueryTest(testCaseName, queriesString, reset = true, tryWithoutResettingFirst = true)
} else {
// Only output warnings for the built in whitelist as this clutters the output when the user
// trying to execute a single test from the commandline.
Expand Down