Github user HyukjinKwon commented on a diff in the pull request:
https://github.com/apache/spark/pull/12601#discussion_r77946660
--- Diff:
sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCWriteSuite.scala ---
@@ -208,4 +208,75 @@ class JDBCWriteSuite extends SharedSQLContext with
BeforeAndAfter {
assert(2 === spark.read.jdbc(url1, "TEST.PEOPLE1", properties).count())
assert(2 === spark.read.jdbc(url1, "TEST.PEOPLE1",
properties).collect()(0).length)
}
+
+ test("save works for format(\"jdbc\") if url and dbtable are set") {
+ val df = sqlContext.createDataFrame(sparkContext.parallelize(arr2x2),
schema2)
+
+ df.write.format("jdbc")
+ .options(Map("url" -> url, "dbtable" -> "TEST.BASICCREATETEST"))
+ .save
+
+ assert(2 === sqlContext.read.jdbc(url, "TEST.BASICCREATETEST", new
Properties).count)
+ assert(
+ 2 === sqlContext.read.jdbc(url, "TEST.BASICCREATETEST", new
Properties).collect()(0).length)
+ }
+
+ test("save API with SaveMode.Overwrite") {
+ import scala.collection.JavaConverters._
+
+ val df = spark.createDataFrame(sparkContext.parallelize(arr2x2),
schema2)
+ val df2 = spark.createDataFrame(sparkContext.parallelize(arr1x2),
schema2)
+
+ df.write.format("jdbc")
+ .option("url", url1)
+ .option("dbtable", "TEST.TRUNCATETEST")
+ .options(properties.asScala)
+ .save()
+ df2.write.mode(SaveMode.Overwrite).format("jdbc")
+ .option("url", url1)
+ .option("dbtable", "TEST.TRUNCATETEST")
+ .options(properties.asScala)
+ .save()
+ assert(1 === spark.read.jdbc(url1, "TEST.TRUNCATETEST",
properties).count())
+ assert(2 === spark.read.jdbc(url1, "TEST.TRUNCATETEST",
properties).collect()(0).length)
+ }
+
+ test("save errors if url is not specified") {
+ import scala.collection.JavaConverters._
+ val df = spark.createDataFrame(sparkContext.parallelize(arr2x2),
schema2)
+
+ var e = intercept[RuntimeException] {
+ df.write.format("jdbc")
+ .option("dbtable", "TEST.TRUNCATETEST")
+ .options(properties.asScala)
+ .save()
+ }.getMessage
+ assert(e.contains("Option 'url' is required"))
+ }
+
+ test("save errors if dbtable is not specified") {
+ import scala.collection.JavaConverters._
+ val df = spark.createDataFrame(sparkContext.parallelize(arr2x2),
schema2)
+
+ var e = intercept[RuntimeException] {
+ df.write.format("jdbc")
+ .option("url", url1)
+ .options(properties.asScala)
+ .save()
+ }.getMessage
+ assert(e.contains("Option 'dbtable' is required"))
+ }
+
+ test("save errors if wrong user/password combination") {
+ import scala.collection.JavaConverters._
--- End diff --
How about putting this import in the top with other imports if either is
okay? I understand your point putting this inside but let's just follow the
majority of other codes just to speed up.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]