rdblue commented on a change in pull request #2021:
URL: https://github.com/apache/iceberg/pull/2021#discussion_r560584197
##########
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 {
Review comment:
The problem isn't the row in target, it is that two source rows match.
Could you update the name to `testMultipleUpdatesForTargetRow` or
`testCardinalityCheck`?
##########
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 {
Review comment:
How about `testIgnoreMultipleUpdatesForTargetRow` or
`testDisableCardinalityCheck`?
----------------------------------------------------------------
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]