Github user srowen commented on a diff in the pull request:
https://github.com/apache/spark/pull/14086#discussion_r71984193
--- Diff:
sql/core/src/test/scala/org/apache/spark/sql/jdbc/JDBCWriteSuite.scala ---
@@ -145,14 +153,24 @@ class JDBCWriteSuite extends SharedSQLContext with
BeforeAndAfter {
assert(2 === spark.read.jdbc(url, "TEST.APPENDTEST", new
Properties()).collect()(0).length)
}
- test("CREATE then INSERT to truncate") {
+ test("Truncate") {
+ JdbcDialects.registerDialect(testH2Dialect)
val df = spark.createDataFrame(sparkContext.parallelize(arr2x2),
schema2)
val df2 = spark.createDataFrame(sparkContext.parallelize(arr1x2),
schema2)
+ val df3 = spark.createDataFrame(sparkContext.parallelize(arr2x3),
schema3)
df.write.jdbc(url1, "TEST.TRUNCATETEST", properties)
- df2.write.mode(SaveMode.Overwrite).jdbc(url1, "TEST.TRUNCATETEST",
properties)
+ df2.write.mode(SaveMode.Overwrite).option("truncate", true)
+ .jdbc(url1, "TEST.TRUNCATETEST", properties)
assert(1 === spark.read.jdbc(url1, "TEST.TRUNCATETEST",
properties).count())
assert(2 === spark.read.jdbc(url1, "TEST.TRUNCATETEST",
properties).collect()(0).length)
+
+ val m = intercept[SparkException] {
--- End diff --
Ah, nevermind my last comment. You test the truncate succeeds path already.
OK, the assertion here makes sense though it highlights that if truncation
can't succeed, then it only fails after truncating and the new dataframe can't
be written. I suppose that's reasonable semantics, since it otherwise requires
doing something like testing an insert.
---
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]