Skip to content

Commit 884981d

Browse files
authored
HIVE-28119: Iceberg: Allow insert clause with a column list in Merge query not_matched condition (Denys Kuzmenko, reviewed by Butao Zhang, Simhadri Govindappa)
Closes #5127
1 parent df45194 commit 884981d

File tree

5 files changed

+366
-314
lines changed

5 files changed

+366
-314
lines changed

iceberg/iceberg-handler/src/test/queries/positive/merge_iceberg_copy_on_write_partitioned.q

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ merge into target_ice as t using source src ON t.a = src.a
2727
when not matched then insert values (src.a, src.b, src.c);
2828

2929
merge into target_ice as t using source src ON t.a = src.a
30-
when not matched then insert values (src.a, src.b, src.c);
30+
when not matched and src.a <= 5 then insert values (src.a, src.b, src.c);
31+
32+
select * from target_ice;
33+
34+
-- insert clause with a column list
35+
merge into target_ice as t using source src ON t.a = src.a
36+
when not matched then insert (a, c) values (src.a, src.c);
3137

3238
select * from target_ice;
39+
40+
41+

iceberg/iceberg-handler/src/test/queries/positive/merge_iceberg_copy_on_write_unpartitioned.q

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ insert into source values (1, 'one', 50), (2, 'two', 51), (3, 'three', 52), (4,
1414
explain
1515
merge into target_ice as t using source src ON t.a = src.a
1616
when matched and t.a > 100 THEN DELETE
17+
when matched then update set b = 'Merged', c = t.c + 10
1718
when not matched then insert values (src.a, src.b, src.c);
1819

20+
-- insert clause with a column list
1921
explain
2022
merge into target_ice as t using source src ON t.a = src.a
2123
when matched and t.a > 100 THEN DELETE
22-
when matched then update set b = 'Merged', c = t.c + 10
23-
when not matched then insert values (src.a, src.b, src.c);
24+
when not matched then insert (a, b) values (src.a, src.b);
2425

2526
merge into target_ice as t using source src ON t.a = src.a
2627
when matched and t.a > 100 THEN DELETE

iceberg/iceberg-handler/src/test/results/positive/merge_iceberg_copy_on_write_partitioned.q.out

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -551,13 +551,39 @@ STAGE PLANS:
551551
Basic Stats Work:
552552

553553
PREHOOK: query: merge into target_ice as t using source src ON t.a = src.a
554-
when not matched then insert values (src.a, src.b, src.c)
554+
when not matched and src.a <= 5 then insert values (src.a, src.b, src.c)
555555
PREHOOK: type: QUERY
556556
PREHOOK: Input: default@source
557557
PREHOOK: Input: default@target_ice
558558
PREHOOK: Output: default@target_ice
559559
POSTHOOK: query: merge into target_ice as t using source src ON t.a = src.a
560-
when not matched then insert values (src.a, src.b, src.c)
560+
when not matched and src.a <= 5 then insert values (src.a, src.b, src.c)
561+
POSTHOOK: type: QUERY
562+
POSTHOOK: Input: default@source
563+
POSTHOOK: Input: default@target_ice
564+
POSTHOOK: Output: default@target_ice
565+
PREHOOK: query: select * from target_ice
566+
PREHOOK: type: QUERY
567+
PREHOOK: Input: default@target_ice
568+
PREHOOK: Output: hdfs://### HDFS PATH ###
569+
POSTHOOK: query: select * from target_ice
570+
POSTHOOK: type: QUERY
571+
POSTHOOK: Input: default@target_ice
572+
POSTHOOK: Output: hdfs://### HDFS PATH ###
573+
1 Merged 60
574+
2 Merged 61
575+
3 three 52
576+
333 two 56
577+
4 four 53
578+
5 five 54
579+
PREHOOK: query: merge into target_ice as t using source src ON t.a = src.a
580+
when not matched then insert (a, c) values (src.a, src.c)
581+
PREHOOK: type: QUERY
582+
PREHOOK: Input: default@source
583+
PREHOOK: Input: default@target_ice
584+
PREHOOK: Output: default@target_ice
585+
POSTHOOK: query: merge into target_ice as t using source src ON t.a = src.a
586+
when not matched then insert (a, c) values (src.a, src.c)
561587
POSTHOOK: type: QUERY
562588
POSTHOOK: Input: default@source
563589
POSTHOOK: Input: default@target_ice
@@ -571,7 +597,7 @@ POSTHOOK: type: QUERY
571597
POSTHOOK: Input: default@target_ice
572598
POSTHOOK: Output: hdfs://### HDFS PATH ###
573599
1 Merged 60
574-
111 one 55
600+
111 NULL 55
575601
2 Merged 61
576602
3 three 52
577603
333 two 56

0 commit comments

Comments
 (0)