Skip to content

Commit

Permalink
move tests to SQLQuerySuite
Browse files Browse the repository at this point in the history
  • Loading branch information
mengxr committed Oct 8, 2014
1 parent 67fdebb commit d8af0ed
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 45 deletions.
45 changes: 0 additions & 45 deletions sql/core/src/test/scala/org/apache/spark/sql/MetadataSuite.scala

This file was deleted.

21 changes: 21 additions & 0 deletions sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -673,4 +673,25 @@ class SQLQuerySuite extends QueryTest with BeforeAndAfterAll {
sql("SELECT CAST(TRUE AS STRING), CAST(FALSE AS STRING) FROM testData LIMIT 1"),
("true", "false") :: Nil)
}

test("metadata is propagated correctly") {
val person = sql("SELECT * FROM person")
val schema = person.schema
val docKey = "doc"
val docValue = "first name"
val schemaWithMeta = new StructType(Seq(
schema("id"), schema("name").copy(metadata = Map(docKey -> docValue)), schema("age")))
val personWithMeta = applySchema(person, schemaWithMeta)
def validateMetadata(rdd: SchemaRDD): Unit = {
assert(rdd.schema("name").metadata(docKey) === docValue)
}
personWithMeta.registerTempTable("personWithMeta")
validateMetadata(personWithMeta.select('name))
validateMetadata(personWithMeta.select("name".attr))
validateMetadata(personWithMeta.select('id, 'name))
validateMetadata(sql("SELECT * FROM personWithMeta"))
validateMetadata(sql("SELECT id, name FROM personWithMeta"))
validateMetadata(sql("SELECT * FROM personWithMeta JOIN salary ON id = personId"))
validateMetadata(sql("SELECT name, salary FROM personWithMeta JOIN salary ON id = personId"))
}
}
11 changes: 11 additions & 0 deletions sql/core/src/test/scala/org/apache/spark/sql/TestData.scala
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,15 @@ object TestData {
// An RDD with 4 elements and 8 partitions
val withEmptyParts = TestSQLContext.sparkContext.parallelize((1 to 4).map(IntField), 8)
withEmptyParts.registerTempTable("withEmptyParts")

case class Person(id: Int, name: String, age: Int)
case class Salary(personId: Int, salary: Double)
val person = TestSQLContext.sparkContext.parallelize(
Person(0, "mike", 30) ::
Person(1, "jim", 20) :: Nil)
person.registerTempTable("person")
val salary = TestSQLContext.sparkContext.parallelize(
Salary(0, 2000.0) ::
Salary(1, 1000.0) :: Nil)
salary.registerTempTable("salary")
}

0 comments on commit d8af0ed

Please sign in to comment.