Skip to content

Commit

Permalink
Update tests and add comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
yhuai committed Aug 17, 2015
1 parent 75aeab7 commit bc4b8e0
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ class SQLConfSuite extends QueryTest with SharedSQLContext {
}

test("programmatic ways of basic setting and getting") {
// Set a conf first.
ctx.setConf(testKey, testVal)
// Clear the conf.
ctx.conf.clear()
// The number of confs set after we call clear equals to the number of
// confs in TestSQLContext.overrideConfs (we always override these confs
// when we use TestSQLContext).
assert(ctx.getAllConfs.size === TestSQLContext.overrideConfs.size)
// After clear, only overrideConfs used by unit test should be in the SQLConf.
assert(ctx.getAllConfs === TestSQLContext.overrideConfs)

ctx.setConf(testKey, testVal)
assert(ctx.getConf(testKey) === testVal)
Expand Down
14 changes: 12 additions & 2 deletions sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import org.apache.spark.sql.catalyst.DefaultParserDialect
import org.apache.spark.sql.catalyst.errors.DialectException
import org.apache.spark.sql.execution.aggregate
import org.apache.spark.sql.functions._
import org.apache.spark.sql.test.SharedSQLContext
import org.apache.spark.sql.test.{TestSQLContext, SharedSQLContext}
import org.apache.spark.sql.test.SQLTestData._
import org.apache.spark.sql.types._

Expand Down Expand Up @@ -990,7 +990,17 @@ class SQLQuerySuite extends QueryTest with SharedSQLContext {
val nonexistentKey = "nonexistent"

// "set" itself returns all config variables currently specified in SQLConf.
assert(sql("SET").collect().size == 0)
assert(sql("SET").collect().size == TestSQLContext.overrideConfs.size)
sql("SET").collect().foreach { row =>
val key = row.getString(0)
val value = row.getString(1)
assert(
TestSQLContext.overrideConfs.contains(key),
s"$key should not exist in SQLConf.")
assert(
TestSQLContext.overrideConfs(key) === value,
s"The value of $key should be ${TestSQLContext.overrideConfs(key)} instead of $value.")
}

// "set key=val"
sql(s"SET $testKey=$testVal")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ private[sql] class TestSQLContext(sc: SparkContext) extends SQLContext(sc) { sel
}

private[sql] object TestSQLContext {

/**
* A map used to store all confs that need to be overridden in sql/core unit tests.
*/
val overrideConfs: Map[String, String] =
Map(
// Fewer shuffle partitions to speed up testing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,10 @@ class TestHiveContext(sc: SparkContext) extends HiveContext(sc) {
}

private[hive] object TestHiveContext {

/**
* A map used to store all confs that need to be overridden in sql/hive unit tests.
*/
val overrideConfs: Map[String, String] =
Map(
// Fewer shuffle partitions to speed up testing.
Expand Down

0 comments on commit bc4b8e0

Please sign in to comment.