rdblue commented on a change in pull request #2021:
URL: https://github.com/apache/iceberg/pull/2021#discussion_r560585170



##########
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:
       I think it would be better if the query here is the same one that fails 
in the test above. That way identical queries with identical data have 
different behavior based on the table property.




----------------------------------------------------------------
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]

Reply via email to