[SPARK-22002][SQL][FOLLOWUP][TEST] Add a test to check if the original schema doesn't have metadata.
## What changes were proposed in this pull request? This is a follow-up pr of #19231 which modified the behavior to remove metadata from JDBC table schema. This pr adds a test to check if the schema doesn't have metadata. ## How was this patch tested? Added a test and existing tests. Author: Takuya UESHIN <ueshin@databricks.com> Closes #20585 from ueshin/issues/SPARK-22002/fup1.
This commit is contained in:
parent
5bb11411ae
commit
0c66fe4f22
|
@ -1168,4 +1168,26 @@ class JDBCSuite extends SparkFunSuite
|
|||
val df3 = sql("SELECT * FROM test_sessionInitStatement")
|
||||
assert(df3.collect() === Array(Row(21519, 1234)))
|
||||
}
|
||||
|
||||
test("jdbc data source shouldn't have unnecessary metadata in its schema") {
|
||||
val schema = StructType(Seq(
|
||||
StructField("NAME", StringType, true), StructField("THEID", IntegerType, true)))
|
||||
|
||||
val df = spark.read.format("jdbc")
|
||||
.option("Url", urlWithUserAndPass)
|
||||
.option("DbTaBle", "TEST.PEOPLE")
|
||||
.load()
|
||||
assert(df.schema === schema)
|
||||
|
||||
withTempView("people_view") {
|
||||
sql(
|
||||
s"""
|
||||
|CREATE TEMPORARY VIEW people_view
|
||||
|USING org.apache.spark.sql.jdbc
|
||||
|OPTIONS (uRl '$url', DbTaBlE 'TEST.PEOPLE', User 'testUser', PassWord 'testPass')
|
||||
""".stripMargin.replaceAll("\n", " "))
|
||||
|
||||
assert(sql("select * from people_view").schema === schema)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue