jzhuge commented on a change in pull request #25330: [SPARK-28565][SQL]
DataFrameWriter saveAsTable support for V2 catalogs
URL: https://github.com/apache/spark/pull/25330#discussion_r309933345
##########
File path:
sql/core/src/test/scala/org/apache/spark/sql/sources/v2/DataSourceV2DataFrameSuite.scala
##########
@@ -104,4 +137,169 @@ class DataSourceV2DataFrameSuite extends QueryTest with
SharedSQLContext with Be
}
}
}
+
+ testQuietly("saveAsTable: with defined catalog and table doesn't exist") {
+ val t1 = "testcat.ns1.ns2.tbl"
+ withTable(t1) {
+ spark.table("source").write.saveAsTable(t1)
+ checkAnswer(spark.table(t1), spark.table("source"))
+ }
+ }
+
+ testQuietly("saveAsTable: with defined catalog and table exists") {
+ val t1 = "testcat.ns1.ns2.tbl"
+ withTable(t1) {
+ sql(s"CREATE TABLE $t1 (id bigint, data string) USING foo")
+ // Default saveMode is append, therefore this doesn't throw a table
already exists eception
+ spark.table("source").write.saveAsTable(t1)
+ checkAnswer(spark.table(t1), spark.table("source"))
+ }
+ }
+
+ testQuietly("saveAsTable: with defined catalog + table overwrite and table
doesn't exist") {
+ val t1 = "testcat.ns1.ns2.tbl"
+ withTable(t1) {
+ spark.table("source").write.mode("overwrite").saveAsTable(t1)
+ checkAnswer(spark.table(t1), spark.table("source"))
+ }
+ }
+
+ testQuietly("saveAsTable: with defined catalog + table overwrite and table
exists") {
+ val t1 = "testcat.ns1.ns2.tbl"
+ withTable(t1) {
+ sql(s"CREATE TABLE $t1 USING foo AS SELECT 'c', 'd'")
+ spark.table("source").write.mode("overwrite").saveAsTable(t1)
+ checkAnswer(spark.table(t1), spark.table("source"))
+ }
+ }
+
+ testQuietly("saveAsTable: with defined catalog + ignore mode and table
doesn't exist") {
+ val t1 = "testcat.ns1.ns2.tbl"
+ withTable(t1) {
+ spark.table("source").write.mode("ignore").saveAsTable(t1)
+ checkAnswer(spark.table(t1), spark.table("source"))
+ }
+ }
+
+ testQuietly("saveAsTable: with defined catalog + ignore mode and table
exists") {
+ val t1 = "testcat.ns1.ns2.tbl"
+ withTable(t1) {
+ sql(s"CREATE TABLE $t1 USING foo AS SELECT 'c', 'd'")
+ spark.table("source").write.mode("ignore").saveAsTable(t1)
+ checkAnswer(spark.table(t1), Seq(Row("c", "d")))
+ }
+ }
+
+ sessionCatalogTest("saveAsTable and v2 table - table doesn't exist") {
session =>
Review comment:
Consider moving all session catalog tests to a new suite file?
This way, the entire suite can have a Spark session that has v2 session
catalog defined.
We call also add new insertInto test cases for session catalog there.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]