rdblue commented on a change in pull request #24832: [SPARK-27845][SQL]
DataSourceV2: InsertTable
URL: https://github.com/apache/spark/pull/24832#discussion_r307378297
##########
File path:
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/DDLParserSuite.scala
##########
@@ -616,6 +617,112 @@ class DDLParserSuite extends AnalysisTest {
}
}
+ test("insert table: basic append") {
+ Seq(
+ "INSERT INTO TABLE testcat.ns1.ns2.tbl SELECT * FROM source",
+ "INSERT INTO testcat.ns1.ns2.tbl SELECT * FROM source"
+ ).foreach { sql =>
+ parseCompare(sql,
+ InsertIntoStatement(
+ UnresolvedRelation(Seq("testcat", "ns1", "ns2", "tbl")),
+ Map.empty,
+ Project(Seq(UnresolvedStar(None)),
UnresolvedRelation(Seq("source"))),
+ overwrite = false, ifPartitionNotExists = false))
+ }
+ }
+
+ test("insert table: append from another catalog") {
+ parseCompare("INSERT INTO TABLE testcat.ns1.ns2.tbl SELECT * FROM
testcat2.db.tbl",
+ InsertIntoStatement(
+ UnresolvedRelation(Seq("testcat", "ns1", "ns2", "tbl")),
+ Map.empty,
+ Project(Seq(UnresolvedStar(None)), UnresolvedRelation(Seq("testcat2",
"db", "tbl"))),
+ overwrite = false, ifPartitionNotExists = false))
+ }
+
+ test("insert table: append with partition") {
+ parseCompare(
+ """
+ |INSERT INTO testcat.ns1.ns2.tbl
+ |PARTITION (p1 = 3, p2)
+ |SELECT * FROM source
+ """.stripMargin,
+ InsertIntoStatement(
+ UnresolvedRelation(Seq("testcat", "ns1", "ns2", "tbl")),
+ Map("p1" -> Some("3"), "p2" -> None),
+ Project(Seq(UnresolvedStar(None)), UnresolvedRelation(Seq("source"))),
+ overwrite = false, ifPartitionNotExists = false))
+ }
+
+ test("insert table: overwrite") {
+ Seq(
+ "INSERT OVERWRITE TABLE testcat.ns1.ns2.tbl SELECT * FROM source",
+ "INSERT OVERWRITE testcat.ns1.ns2.tbl SELECT * FROM source"
+ ).foreach { sql =>
+ parseCompare(sql,
+ InsertIntoStatement(
+ UnresolvedRelation(Seq("testcat", "ns1", "ns2", "tbl")),
+ Map.empty,
+ Project(Seq(UnresolvedStar(None)),
UnresolvedRelation(Seq("source"))),
+ overwrite = true, ifPartitionNotExists = false))
+ }
+ }
+
+ test("insert table: overwrite with partition") {
+ parseCompare(
+ """
+ |INSERT OVERWRITE TABLE testcat.ns1.ns2.tbl
+ |PARTITION (p1 = 3, p2)
+ |SELECT * FROM source
+ """.stripMargin,
+ InsertIntoStatement(
+ UnresolvedRelation(Seq("testcat", "ns1", "ns2", "tbl")),
+ Map("p1" -> Some("3"), "p2" -> None),
+ Project(Seq(UnresolvedStar(None)), UnresolvedRelation(Seq("source"))),
+ overwrite = true, ifPartitionNotExists = false))
+ }
+
+ test("insert table: overwrite with partition if not exists") {
+ parseCompare(
+ """
+ |INSERT OVERWRITE TABLE testcat.ns1.ns2.tbl
+ |PARTITION (p1 = 3) IF NOT EXISTS
+ |SELECT * FROM source
+ """.stripMargin,
+ InsertIntoStatement(
+ UnresolvedRelation(Seq("testcat", "ns1", "ns2", "tbl")),
+ Map("p1" -> Some("3")),
+ Project(Seq(UnresolvedStar(None)), UnresolvedRelation(Seq("source"))),
+ overwrite = true, ifPartitionNotExists = true))
+ }
+
+ test("insert table: if not exists with dynamic partition fails") {
+ val exc = intercept[AnalysisException] {
+ parsePlan(
+ """
+ |INSERT OVERWRITE TABLE testcat.ns1.ns2.tbl
+ |PARTITION (p1 = 3, p2) IF NOT EXISTS
+ |SELECT * FROM source
+ """.stripMargin)
+ }
+
+ assert(exc.getMessage.contains("IF NOT EXISTS with dynamic partitions"))
+ assert(exc.getMessage.contains("p2"))
+ }
+
+ test("insert table: if not exists without overwrite fails") {
Review comment:
@cloud-fan, @brkyvz, this is the test that required adding the `IF NOT
EXISTS` to `INSERT INTO`. I think it is better to have a good error message
instead of relying on not being able to parse the statement.
----------------------------------------------------------------
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]