Skip to content

Commit 0c66fe4

Browse files
ueshingatorsmile
authored andcommitted
[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 <[email protected]> Closes #20585 from ueshin/issues/SPARK-22002/fup1.
1 parent 5bb1141 commit 0c66fe4

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCSuite.scala

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,4 +1168,26 @@ class JDBCSuite extends SparkFunSuite
11681168
val df3 = sql("SELECT * FROM test_sessionInitStatement")
11691169
assert(df3.collect() === Array(Row(21519, 1234)))
11701170
}
1171+
1172+
test("jdbc data source shouldn't have unnecessary metadata in its schema") {
1173+
val schema = StructType(Seq(
1174+
StructField("NAME", StringType, true), StructField("THEID", IntegerType, true)))
1175+
1176+
val df = spark.read.format("jdbc")
1177+
.option("Url", urlWithUserAndPass)
1178+
.option("DbTaBle", "TEST.PEOPLE")
1179+
.load()
1180+
assert(df.schema === schema)
1181+
1182+
withTempView("people_view") {
1183+
sql(
1184+
s"""
1185+
|CREATE TEMPORARY VIEW people_view
1186+
|USING org.apache.spark.sql.jdbc
1187+
|OPTIONS (uRl '$url', DbTaBlE 'TEST.PEOPLE', User 'testUser', PassWord 'testPass')
1188+
""".stripMargin.replaceAll("\n", " "))
1189+
1190+
assert(sql("select * from people_view").schema === schema)
1191+
}
1192+
}
11711193
}

0 commit comments

Comments
 (0)