Hudi merge into多条件更新

验证这个jira

创建表

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

create table base (
id int,
price int
) using hudi
tblproperties (
primaryKey = 'id'
);

create table change (
id int,
price int
) using hudi
tblproperties (
primaryKey = 'id'
);

插入数据

1
2
3
4

insert into base values (1, 1), (2, 2);
insert into change values (1, 10), (2, 20), (3, 30);

执行按条件更新(设置多种条件)

1
2
3
4
5
6
7
8
9
10
11
12
merge into base as target
using (select id, price from change) source
on target.id = source.id
/* 条件一 id=1时相加 */
when matched and target.id = 1 then
update set target.price = source.price + target.price
/* 条件二 设置为较大的price */
when matched and target.price < source.price then
update set target.price = source.price
/* 不匹配时插入 */
when not matched then
insert *;

查询base表数据

1
2
3
20230517133958447       20230517133958447_0_0   2               c4be3a67-b9f4-4593-883f-9cca0f1e1e15-0_0-4-4_20230517133958447.parquet      2       20
20230517133958447 20230517133958447_0_1 1 c4be3a67-b9f4-4593-883f-9cca0f1e1e15-0_0-4-4_20230517133958447.parquet 1 11
20230517133958447 20230517133958447_0_2 3 c4be3a67-b9f4-4593-883f-9cca0f1e1e15-0_0-4-4_20230517133958447.parquet 3 30