aokolnychyi commented on a change in pull request #3918:
URL: https://github.com/apache/iceberg/pull/3918#discussion_r787067750
##########
File path:
spark/v3.2/spark-extensions/src/test/java/org/apache/iceberg/spark/extensions/TestMerge.java
##########
@@ -1111,6 +1111,83 @@ public void testMergeRefreshesRelationCache() {
spark.sql("UNCACHE TABLE tmp");
}
+ @Test
+ public void testMergeResolvesColumnsByName() {
+ createAndInitTable("id INT, badge INT, dep STRING",
+ "{ \"id\": 1, \"badge\": 1000, \"dep\": \"emp-id-one\" }\n" +
+ "{ \"id\": 6, \"badge\": 6000, \"dep\": \"emp-id-6\" }");
+
+ createOrReplaceView("source", "badge INT, id INT, dep STRING",
+ "{ \"badge\": 1001, \"id\": 1, \"dep\": \"emp-id-1\" }\n" +
+ "{ \"badge\": 6006, \"id\": 6, \"dep\": \"emp-id-6\" }\n" +
+ "{ \"badge\": 7007, \"id\": 7, \"dep\": \"emp-id-7\" }");
+
+ sql("MERGE INTO %s AS t USING source AS s " +
+ "ON t.id == s.id " +
+ "WHEN MATCHED THEN " +
+ " UPDATE SET * " +
+ "WHEN NOT MATCHED THEN " +
+ " INSERT * ", tableName);
+
+ ImmutableList<Object[]> expectedRows = ImmutableList.of(
+ row(1, 1001, "emp-id-1"), // updated
+ row(6, 6006, "emp-id-6"), // updated
+ row(7, 7007, "emp-id-7") // new
+ );
+ assertEquals("Should have expected rows", expectedRows,
+ sql("SELECT id, badge, dep FROM %s ORDER BY id", tableName));
+ }
+
+ @Test
+ public void testMergeWithLiteralBooleanAsPredicate() {
+ createAndInitTable("id INT, dep STRING");
+
+ createOrReplaceView("source", "id INT, dep STRING",
+ "{ \"id\": 1, \"dep\": \"emp-id-1\" }\n" +
+ "{ \"id\": 2, \"dep\": \"emp-id-2\" }\n" +
+ "{ \"id\": 3, \"dep\": \"emp-id-3\" }");
+
+ sql("MERGE INTO %s AS t USING source AS s " +
+ "ON true " +
Review comment:
After a closer look, it does look weird. It works because there are no
table rows but I think we can remove this test. I also adapted the test below
and inverted the condition so that it's more reasonable.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]