Skip to content
This repository was archived by the owner on Jan 9, 2020. It is now read-only.

Commit d5aefa8

Browse files
huaxingaogatorsmile
authored andcommitted
[SPARK-21338][SQL] implement isCascadingTruncateTable() method in AggregatedDialect
## What changes were proposed in this pull request? org.apache.spark.sql.jdbc.JdbcDialect's method: def isCascadingTruncateTable(): Option[Boolean] = None is not overriden in org.apache.spark.sql.jdbc.AggregatedDialect class. Because of this issue, when you add more than one dialect Spark doesn't truncate table because isCascadingTruncateTable always returns default None for Aggregated Dialect. Will implement isCascadingTruncateTable in AggregatedDialect class in this PR. ## How was this patch tested? In JDBCSuite, inside test("Aggregated dialects"), will add one line to test AggregatedDialect.isCascadingTruncateTable Author: Huaxin Gao <[email protected]> Closes apache#19256 from huaxingao/spark-21338.
1 parent 2f96242 commit d5aefa8

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

sql/core/src/main/scala/org/apache/spark/sql/jdbc/AggregatedDialect.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,8 @@ private class AggregatedDialect(dialects: List[JdbcDialect]) extends JdbcDialect
4141
override def getJDBCType(dt: DataType): Option[JdbcType] = {
4242
dialects.flatMap(_.getJDBCType(dt)).headOption
4343
}
44+
45+
override def isCascadingTruncateTable(): Option[Boolean] = {
46+
dialects.flatMap(_.isCascadingTruncateTable()).reduceOption(_ || _)
47+
}
4448
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,11 +740,13 @@ class JDBCSuite extends SparkFunSuite
740740
} else {
741741
None
742742
}
743+
override def isCascadingTruncateTable(): Option[Boolean] = Some(true)
743744
}, testH2Dialect))
744745
assert(agg.canHandle("jdbc:h2:xxx"))
745746
assert(!agg.canHandle("jdbc:h2"))
746747
assert(agg.getCatalystType(0, "", 1, null) === Some(LongType))
747748
assert(agg.getCatalystType(1, "", 1, null) === Some(StringType))
749+
assert(agg.isCascadingTruncateTable() === Some(true))
748750
}
749751

750752
test("DB2Dialect type mapping") {

0 commit comments

Comments
 (0)