rdblue commented on a change in pull request #2189:
URL: https://github.com/apache/iceberg/pull/2189#discussion_r568175582
##########
File path:
spark3-extensions/src/test/java/org/apache/iceberg/spark/extensions/TestMerge.java
##########
@@ -48,6 +48,55 @@ public void removeTables() {
sql("DROP TABLE IF EXISTS source");
}
+ // TODO: add tests for multiple NOT MATCHED clauses when we move to Spark 3.1
+
+ @Test
+ public void testMergeInsertOnly() {
+ createAndInitTable("id STRING, v STRING",
+ "{ \"id\": \"a\", \"v\": \"v1\" }\n" +
+ "{ \"id\": \"b\", \"v\": \"v2\" }");
+ createOrReplaceView("source",
+ "{ \"id\": \"a\", \"v\": \"v1_1\" }\n" +
+ "{ \"id\": \"a\", \"v\": \"v1_2\" }\n" +
+ "{ \"id\": \"c\", \"v\": \"v3\" }\n" +
+ "{ \"id\": \"d\", \"v\": \"v4_1\" }\n" +
+ "{ \"id\": \"d\", \"v\": \"v4_2\" }");
+
+ sql("MERGE INTO %s t USING source " +
+ "ON t.id == source.id " +
+ "WHEN NOT MATCHED THEN " +
+ " INSERT *", tableName);
+
+ ImmutableList<Object[]> expectedRows = ImmutableList.of(
+ row("a", "v1"), // kept
+ row("b", "v2"), // kept
+ row("c", "v3"), // new
+ row("d", "v4_1"), // new
+ row("d", "v4_2") // new
+ );
+ assertEquals("Output should match", expectedRows, sql("SELECT * FROM %s
ORDER BY id", tableName));
+ }
+
+ @Test
+ public void testMergeInsertOnlyWithCondition() {
+ createAndInitTable("id INTEGER, v INTEGER", "{ \"id\": 1, \"v\": 1 }");
+ createOrReplaceView("source",
+ "{ \"id\": 1, \"v\": 11, \"is_new\": true }\n" +
+ "{ \"id\": 2, \"v\": 21, \"is_new\": true }\n" +
+ "{ \"id\": 2, \"v\": 22, \"is_new\": false }");
+
+ sql("MERGE INTO %s t USING source s " +
+ "ON t.id == s.id " +
+ "WHEN NOT MATCHED AND is_new = TRUE THEN " +
+ " INSERT (v, id) VALUES (s.v + 100, s.id)", tableName);
Review comment:
I agree. A comment would be helpful if we are validating order.
----------------------------------------------------------------
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]