rdblue commented on a change in pull request #2021:
URL: https://github.com/apache/iceberg/pull/2021#discussion_r560585618
##########
File path:
spark3-extensions/src/test/java/org/apache/iceberg/spark/extensions/TestMergeIntoTable.java
##########
@@ -232,8 +235,65 @@ public void testSourceFromSetOps() throws
NoSuchTableException {
sql(sqlText, targetName);
sql("SELECT * FROM %s ORDER BY id, dep", targetName);
assertEquals("Should have expected rows",
- ImmutableList.of(row(1, "emp-id-1"), row(2, "emp-id-2")),
- sql("SELECT * FROM %s ORDER BY id ASC NULLS LAST", targetName));
+ ImmutableList.of(row(1, "emp-id-1"), row(2, "emp-id-2")),
+ sql("SELECT * FROM %s ORDER BY id ASC NULLS LAST", targetName));
+ }
+
+ @Test
+ public void testAmbiguousRowInTarget() throws NoSuchTableException {
+ append(targetName, new Employee(1, "emp-id-one"), new Employee(6,
"emp-id-6"));
+ append(sourceName, new Employee(1, "emp-id-first"), new Employee(1,
"emp-id-second"), new Employee(6, "emp-id-6"));
+ String sqlText = "MERGE INTO %s AS target " +
+ "USING %s AS source " +
+ "ON target.id = source.id " +
+ "WHEN MATCHED AND target.id = 1 THEN UPDATE SET * " +
+ "WHEN MATCHED AND target.id = 6 THEN DELETE " +
+ "WHEN NOT MATCHED AND source.id = 2 THEN INSERT * ";
+
+ String tabName = catalogName + "." + "default.target";
+ String errorMsg = "The same row of target table `" + tabName + "` was
identified more than\n" +
+ " once for an update, delete or insert operation of the MERGE
statement.";
+ AssertHelpers.assertThrows("Should complain ambiguous row in target",
+ SparkException.class, errorMsg, () -> sql(sqlText, targetName,
sourceName));
+ }
+
+ @Test
+ public void testDisableAmbiguousRowInTargetCheck() throws
NoSuchTableException {
+ append(targetName, new Employee(1, "emp-id-one"), new Employee(6,
"emp-id-6"));
+ append(sourceName, new Employee(1, "emp-id-1"), new Employee(1,
"emp-id-1"),
+ new Employee(2, "emp-id-2"), new Employee(6, "emp-id-6"));
Review comment:
Another reason to do this is that the merge always deletes, which looks
like it may hit the case where an unconditional delete is allowed. It would be
good to have a fourth test that mirrors the unconditional delete test, but adds
a condition and asserts that the merge is rejected.
----------------------------------------------------------------
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]