Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
16ca7ac
It compiles!!
Aug 4, 2015
5e6a20c
Refactor SQLTestUtils to reduce duplication
Aug 5, 2015
d1d1449
Remove HiveTest singleton
Aug 5, 2015
d4aafb1
Avoid the need to switch to HiveContexts
Aug 5, 2015
6345cee
Clean up JsonSuite
Aug 5, 2015
68ac6fe
Rename the test traits properly
Aug 5, 2015
b15fdc6
Stop SparkContext in Java SQL tests
Aug 5, 2015
0d74a72
Load test data early in case tables are accessed by name
Aug 5, 2015
eee415d
Refactor implicits into SQLTestUtils
Aug 10, 2015
55d0b1b
Fix Java not serializable exception in tests
Aug 10, 2015
4f59bee
Fix DataSourceTest et al.
Aug 10, 2015
88d4f16
Fix hive tests to use the same pattern
Aug 11, 2015
5fe4bfb
Merge branch 'master' of github.com:apache/spark into sql-tests-refactor
Aug 11, 2015
c4a22bc
Fix compile after resolving merge conflicts
Aug 11, 2015
d9a8390
Merge branch 'master' of github.com:apache/spark into sql-tests-refactor
Aug 11, 2015
f5619f8
Fix test compile after resolving merge conflicts
Aug 11, 2015
9395cfa
Merge branch 'master' of github.com:apache/spark into sql-tests-refactor
Aug 11, 2015
c51b3d8
Fix OuterJoinSuite
Aug 11, 2015
997715e
Merge branch 'master' of github.com:apache/spark into sql-tests-refactor
Aug 11, 2015
1400770
Fix style
Aug 11, 2015
c92a3b0
Fix MiMa
Aug 11, 2015
4debedf
Clean up inheritance in test util traits
Aug 11, 2015
ca87dda
Merge branch 'master' of github.com:apache/spark into sql-tests-refactor
Aug 11, 2015
1cf53ad
Create new context in SBT console by default
Aug 11, 2015
bc5c999
Fix SemiJoinSuite
Aug 12, 2015
19fd6c3
Fix InnerJoinSuite
Aug 12, 2015
e1e513e
Merge branch 'master' of github.com:apache/spark into sql-tests-refactor
Aug 12, 2015
1e4c321
Address comments
Aug 12, 2015
54848e2
Merge branch 'master' of github.com:apache/spark into sql-tests-refactor
Aug 12, 2015
94f9c77
Revert the removal of some BeforeAndAfters
Aug 12, 2015
bec7d28
Fix a hive test + minor format updates
Aug 12, 2015
24c086d
Merge branch 'master' of github.com:apache/spark into sql-tests-refactor
Aug 12, 2015
561eacc
Merge branch 'master' of github.com:apache/spark into sql-tests-refactor
Aug 12, 2015
aaba277
Fix places where we override before / after alls
Aug 12, 2015
aac8f7f
Merge branch 'master' of github.com:apache/spark into sql-tests-refactor
Aug 12, 2015
40959bb
Fix test
Aug 12, 2015
55d6624
Merge branch 'master' of github.com:apache/spark into sql-tests-refactor
Aug 12, 2015
4ed58c8
Revert a few merge-conflict-induced unintentional changes
Aug 12, 2015
0ce5638
Minor updates
Aug 13, 2015
814df2f
Add back singletons but deprecate them
Aug 13, 2015
099c74f
Merge branch 'master' of github.com:apache/spark into sql-tests-refactor
Aug 13, 2015
451fa37
Use consistent name for added back singletons
Aug 13, 2015
9ea7f7c
Fix style
Aug 13, 2015
ddc4b05
Revert "Use consistent name for added back singletons"
Aug 13, 2015
ece3a81
Remove TestSQLContext, but keep TestHive
Aug 13, 2015
94cc3b5
Merge branch 'master' of github.com:apache/spark into sql-tests-refactor
Aug 13, 2015
8d69bf8
Fix test
Aug 13, 2015
7a0b1ef
Merge branch 'master' of github.com:apache/spark into sql-tests-refactor
Aug 13, 2015
b58ae73
Fix tests
Aug 13, 2015
828144f
Merge branch 'master' of github.com:apache/spark into sql-tests-refactor
Aug 13, 2015
c4d44c9
Merge branch 'master' of github.com:apache/spark into sql-tests-refactor
Aug 13, 2015
48af8e4
Fix another before / after alls
Aug 13, 2015
0606c82
Merge branch 'master' of github.com:apache/spark into sql-tests-refactor
Aug 13, 2015
f599bbc
Revert all Hive related changes
Aug 13, 2015
aed7fc7
Merge branch 'master' of github.com:apache/spark into sql-tests-refactor
Aug 13, 2015
d85a6d8
Add a shorthand for sqlContext.sql / ctx.sql
Aug 13, 2015
0b60325
Fix hive test compile
Aug 13, 2015
821ea67
Merge branch 'master' of github.com:apache/spark into sql-tests-refactor
Aug 13, 2015
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
Prev Previous commit
Next Next commit
Fix DataSourceTest et al.
Test suites that extend DataSourceTest used to have this weird
implicit SQLContext that was created in the constructor. This was
failing tests because the base SQLContext is not ready until after
the first test is run. A minor refactor was required to fix the
resulting NPEs.

This commit also fixes test suites that need to materialize the
test data. These suites were materializing them in the constructor
before the SQLContext was ready.
  • Loading branch information
Andrew Or committed Aug 10, 2015
commit 4f59beef61c7aceac8fe6400b720e1ef12bc4beb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import org.apache.spark.sql.test.SQLTestUtils
class JoinSuite extends QueryTest with BeforeAndAfterEach with SQLTestUtils {
import testImplicits._

loadTestData()
setupTestData()

test("equi-join is hash-join") {
val x = testData2.as("x")
Expand Down
6 changes: 0 additions & 6 deletions sql/core/src/test/scala/org/apache/spark/sql/QueryTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,6 @@ class QueryTest extends PlanTest {
checkAnswer(df, expectedAnswer.collect())
}

def sqlTest(sqlString: String, expectedAnswer: Seq[Row])(implicit sqlContext: SQLContext) {
test(sqlString) {
checkAnswer(sqlContext.sql(sqlString), expectedAnswer)
}
}

/**
* Asserts that a given [[DataFrame]] will be executed using the given number of cached results.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class MyDialect extends DefaultParserDialect
class SQLQuerySuite extends QueryTest with SQLTestUtils {
import testImplicits._

loadTestData()
setupTestData()

test("having clause") {
Seq(("one", 1), ("two", 2), ("three", 3), ("one", 5)).toDF("k", "v").registerTempTable("hav")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import org.apache.spark.storage.StorageLevel.MEMORY_ONLY
class InMemoryColumnarQuerySuite extends QueryTest with SQLTestUtils {
import testImplicits._

loadTestData()
setupTestData()

test("simple columnar query") {
val plan = ctx.executePlan(testData.logicalPlan).executedPlan
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import org.apache.spark.sql.{execution, Row, SQLConf}
class PlannerSuite extends SparkFunSuite with SQLTestUtils {
import testImplicits._

loadTestData()
setupTestData()

private def testPartialAggregationPlan(query: LogicalPlan): Unit = {
val _ctx = ctx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ abstract class SparkSqlSerializer2Suite extends QueryTest with SQLTestUtils {
var useSerializer2: Boolean = _

override def beforeAll(): Unit = {
super.beforeAll()
numShufflePartitions = ctx.conf.numShufflePartitions
useSerializer2 = ctx.conf.useSqlSerializer2

Expand Down Expand Up @@ -111,8 +112,6 @@ abstract class SparkSqlSerializer2Suite extends QueryTest with SQLTestUtils {
}

ctx.createDataFrame(rdd, schema).registerTempTable("shuffle")

super.beforeAll()
}

override def afterAll(): Unit = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ import org.apache.spark.sql.types._
class TungstenSortSuite extends SparkPlanTest {

override def beforeAll(): Unit = {
super.beforeAll()
ctx.conf.setConf(SQLConf.CODEGEN_ENABLED, true)
}

override def afterAll(): Unit = {
ctx.conf.setConf(SQLConf.CODEGEN_ENABLED, SQLConf.CODEGEN_ENABLED.defaultValue.get)
super.afterAll()
}

test("sort followed by limit") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,21 @@ import org.apache.spark.sql.catalyst.plans.{FullOuter, LeftOuter, RightOuter}
import org.apache.spark.sql.execution.{SparkPlan, SparkPlanTest}

class OuterJoinSuite extends SparkPlanTest {

val left = Seq(
private lazy val left = Seq(
(1, 2.0),
(2, 1.0),
(3, 3.0)
).toDF("a", "b")

val right = Seq(
private lazy val right = Seq(
(2, 3.0),
(3, 2.0),
(4, 1.0)
).toDF("c", "d")

val leftKeys: List[Expression] = 'a :: Nil
val rightKeys: List[Expression] = 'c :: Nil
val condition = Some(LessThan('b, 'd))
private val leftKeys: List[Expression] = 'a :: Nil
private val rightKeys: List[Expression] = 'c :: Nil
private val condition = Some(LessThan('b, 'd))

test("shuffled hash outer join") {
checkAnswer2(left, right, (left: SparkPlan, right: SparkPlan) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,24 @@ import org.apache.spark.sql.execution.{SparkPlan, SparkPlanTest}


class SemiJoinSuite extends SparkPlanTest {
val left = Seq(
private lazy val left = Seq(
(1, 2.0),
(1, 2.0),
(2, 1.0),
(2, 1.0),
(3, 3.0)
).toDF("a", "b")

val right = Seq(
private lazy val right = Seq(
(2, 3.0),
(2, 3.0),
(3, 2.0),
(4, 1.0)
).toDF("c", "d")

val leftKeys: List[Expression] = 'a :: Nil
val rightKeys: List[Expression] = 'c :: Nil
val condition = Some(LessThan('b, 'd))
private val leftKeys: List[Expression] = 'a :: Nil
private val rightKeys: List[Expression] = 'c :: Nil
private val condition = Some(LessThan('b, 'd))

test("left semi join hash") {
checkAnswer2(left, right, (left: SparkPlan, right: SparkPlan) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,27 @@ import org.apache.spark.sql.execution.datasources.DDLException
import org.apache.spark.util.Utils

class CreateTableAsSelectSuite extends DataSourceTest with BeforeAndAfterAll {

import caseInsensitiveContext.sql

private lazy val sparkContext = caseInsensitiveContext.sparkContext

var path: File = null
private var path: File = null

override def beforeAll(): Unit = {
super.beforeAll()
path = Utils.createTempDir()
val rdd = sparkContext.parallelize((1 to 10).map(i => s"""{"a":$i, "b":"str${i}"}"""))
caseInsensitiveContext.read.json(rdd).registerTempTable("jt")
}

override def afterAll(): Unit = {
caseInsensitiveContext.dropTempTable("jt")
super.afterAll()
}

after {
Utils.deleteRecursively(path)
}

test("CREATE TEMPORARY TABLE AS SELECT") {
sql(
caseInsensitiveContext.sql(
s"""
|CREATE TEMPORARY TABLE jsonTable
|USING org.apache.spark.sql.json.DefaultSource
Expand All @@ -59,8 +57,8 @@ class CreateTableAsSelectSuite extends DataSourceTest with BeforeAndAfterAll {
""".stripMargin)

checkAnswer(
sql("SELECT a, b FROM jsonTable"),
sql("SELECT a, b FROM jt").collect())
caseInsensitiveContext.sql("SELECT a, b FROM jsonTable"),
caseInsensitiveContext.sql("SELECT a, b FROM jt").collect())

caseInsensitiveContext.dropTempTable("jsonTable")
}
Expand All @@ -72,7 +70,7 @@ class CreateTableAsSelectSuite extends DataSourceTest with BeforeAndAfterAll {
path.setWritable(false)

val e = intercept[IOException] {
sql(
caseInsensitiveContext.sql(
s"""
|CREATE TEMPORARY TABLE jsonTable
|USING org.apache.spark.sql.json.DefaultSource
Expand All @@ -81,15 +79,15 @@ class CreateTableAsSelectSuite extends DataSourceTest with BeforeAndAfterAll {
|) AS
|SELECT a, b FROM jt
""".stripMargin)
sql("SELECT a, b FROM jsonTable").collect()
caseInsensitiveContext.sql("SELECT a, b FROM jsonTable").collect()
}
assert(e.getMessage().contains("Unable to clear output directory"))

path.setWritable(true)
}

test("create a table, drop it and create another one with the same name") {
sql(
caseInsensitiveContext.sql(
s"""
|CREATE TEMPORARY TABLE jsonTable
|USING org.apache.spark.sql.json.DefaultSource
Expand All @@ -100,11 +98,11 @@ class CreateTableAsSelectSuite extends DataSourceTest with BeforeAndAfterAll {
""".stripMargin)

checkAnswer(
sql("SELECT a, b FROM jsonTable"),
sql("SELECT a, b FROM jt").collect())
caseInsensitiveContext.sql("SELECT a, b FROM jsonTable"),
caseInsensitiveContext.sql("SELECT a, b FROM jt").collect())

val message = intercept[DDLException]{
sql(
caseInsensitiveContext.sql(
s"""
|CREATE TEMPORARY TABLE IF NOT EXISTS jsonTable
|USING org.apache.spark.sql.json.DefaultSource
Expand All @@ -119,7 +117,7 @@ class CreateTableAsSelectSuite extends DataSourceTest with BeforeAndAfterAll {
"CREATE TEMPORARY TABLE IF NOT EXISTS should not be allowed.")

// Overwrite the temporary table.
sql(
caseInsensitiveContext.sql(
s"""
|CREATE TEMPORARY TABLE jsonTable
|USING org.apache.spark.sql.json.DefaultSource
Expand All @@ -129,14 +127,14 @@ class CreateTableAsSelectSuite extends DataSourceTest with BeforeAndAfterAll {
|SELECT a * 4 FROM jt
""".stripMargin)
checkAnswer(
sql("SELECT * FROM jsonTable"),
sql("SELECT a * 4 FROM jt").collect())
caseInsensitiveContext.sql("SELECT * FROM jsonTable"),
caseInsensitiveContext.sql("SELECT a * 4 FROM jt").collect())

caseInsensitiveContext.dropTempTable("jsonTable")
// Explicitly delete the data.
if (path.exists()) Utils.deleteRecursively(path)

sql(
caseInsensitiveContext.sql(
s"""
|CREATE TEMPORARY TABLE jsonTable
|USING org.apache.spark.sql.json.DefaultSource
Expand All @@ -147,15 +145,15 @@ class CreateTableAsSelectSuite extends DataSourceTest with BeforeAndAfterAll {
""".stripMargin)

checkAnswer(
sql("SELECT * FROM jsonTable"),
sql("SELECT b FROM jt").collect())
caseInsensitiveContext.sql("SELECT * FROM jsonTable"),
caseInsensitiveContext.sql("SELECT b FROM jt").collect())

caseInsensitiveContext.dropTempTable("jsonTable")
}

test("CREATE TEMPORARY TABLE AS SELECT with IF NOT EXISTS is not allowed") {
val message = intercept[DDLException]{
sql(
caseInsensitiveContext.sql(
s"""
|CREATE TEMPORARY TABLE IF NOT EXISTS jsonTable
|USING org.apache.spark.sql.json.DefaultSource
Expand All @@ -172,7 +170,7 @@ class CreateTableAsSelectSuite extends DataSourceTest with BeforeAndAfterAll {

test("a CTAS statement with column definitions is not allowed") {
intercept[DDLException]{
sql(
caseInsensitiveContext.sql(
s"""
|CREATE TEMPORARY TABLE jsonTable (a int, b string)
|USING org.apache.spark.sql.json.DefaultSource
Expand All @@ -185,7 +183,7 @@ class CreateTableAsSelectSuite extends DataSourceTest with BeforeAndAfterAll {
}

test("it is not allowed to write to a table while querying it.") {
sql(
caseInsensitiveContext.sql(
s"""
|CREATE TEMPORARY TABLE jsonTable
|USING org.apache.spark.sql.json.DefaultSource
Expand All @@ -196,7 +194,7 @@ class CreateTableAsSelectSuite extends DataSourceTest with BeforeAndAfterAll {
""".stripMargin)

val message = intercept[AnalysisException] {
sql(
caseInsensitiveContext.sql(
s"""
|CREATE TEMPORARY TABLE jsonTable
|USING org.apache.spark.sql.json.DefaultSource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,18 @@ import org.apache.spark.sql.test.SQLTestUtils


abstract class DataSourceTest extends QueryTest with BeforeAndAfter with SQLTestUtils {

// We want to test some edge cases.
protected implicit lazy val caseInsensitiveContext = {
protected lazy val caseInsensitiveContext: SQLContext = {
val ctx = new SQLContext(sqlContext.sparkContext)
ctx.setConf(SQLConf.CASE_SENSITIVE, false)
ctx
}

protected def sqlTest(sqlString: String, expectedAnswer: Seq[Row]) {
test(sqlString) {
checkAnswer(caseInsensitiveContext.sql(sqlString), expectedAnswer)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,8 @@ object FiltersPushed {

class FilteredScanSuite extends DataSourceTest {

import caseInsensitiveContext.sql

before {
sql(
caseInsensitiveContext.sql(
"""
|CREATE TEMPORARY TABLE oneToTenFiltered
|USING org.apache.spark.sql.sources.FilteredScanSource
Expand Down Expand Up @@ -237,7 +235,7 @@ class FilteredScanSuite extends DataSourceTest {

def testPushDown(sqlString: String, expectedCount: Int): Unit = {
test(s"PushDown Returns $expectedCount: $sqlString") {
val queryExecution = sql(sqlString).queryExecution
val queryExecution = caseInsensitiveContext.sql(sqlString).queryExecution
val rawPlan = queryExecution.executedPlan.collect {
case p: execution.PhysicalRDD => p
} match {
Expand Down
Loading