-
Notifications
You must be signed in to change notification settings - Fork 28.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SPARK-22002][SQL] Read JDBC table use custom schema support specify partial fields. #19231
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -971,12 +971,15 @@ class JDBCSuite extends SparkFunSuite | |
test("jdbc API support custom schema") { | ||
val parts = Array[String]("THEID < 2", "THEID >= 2") | ||
val props = new Properties() | ||
props.put("customSchema", "NAME STRING, THEID BIGINT") | ||
props.put("customSchema", "name STRING, THEID BIGINT") | ||
val schema = StructType(Seq( | ||
StructField("NAME", StringType, true), StructField("THEID", LongType, true))) | ||
val df = spark.read.jdbc(urlWithUserAndPass, "TEST.PEOPLE", parts, props) | ||
assert(df.schema.size === 2) | ||
assert(df.schema === schema) | ||
df.schema.zip(schema).foreach { | ||
case (c, v) => | ||
assert(c.dataType === v.dataType) | ||
} | ||
assert(df.count() === 3) | ||
} | ||
|
||
|
@@ -993,7 +996,10 @@ class JDBCSuite extends SparkFunSuite | |
Seq(StructField("NAME", StringType, true), StructField("THEID", IntegerType, true))) | ||
val df = sql("select * from people_view") | ||
assert(df.schema.size === 2) | ||
assert(df.schema === schema) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. revert it back. Change the following line https://github.com/apache/spark/blob/master/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc/JdbcUtils.scala#L309
You also need to update some test cases due to the above change, I think. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We shouldn't change it, because |
||
df.schema.zip(schema).foreach { | ||
case (c, v) => | ||
assert(c.dataType === v.dataType) | ||
} | ||
assert(df.count() === 3) | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
others
->and the others use the default type mapping