Iceberg中进行行级别的数据更新及删除是怎么操作的?

提问者:帅平 问题分类:大数据
Iceberg中进行行级别的数据更新及删除是怎么操作的?
3 个回答
帅的很低调
帅的很低调
主要使用merge into函数,例如:
spark.sql(
  """
    |merge into test1.default.users1  t1
    |using (select id,name,age,cts from test1.default.users2) t2
    |on t1.id = t2.id
    |when matched and t2.tp = 'delete' then delete
    |when matched and t2.tp = 'update' then update set t1.name = t2.name,t1.age = t2.age
    |when not matched then insert (id,name,age) values (t2.id,t2.name,t2.age)
  """.stripMargin)
发布于:4个月前 (01-25) IP属地:未知
单身成瘾i
单身成瘾i
解释下这个sql:
spark.sql(
  """
    |merge into test1.default.users1  t1   //准备更新或者删除的表数据
    |using (select id,name,age,cts,type from test1.default.users2) t2  //待删除的数据(这里简单称为临时表),相当于做join
    |on t1.id = t2.id  //相当于做join
    |when matched and t2.type = 'delete' then delete  //如果临时表对应的值是删除,则直接删除表数据
    |when matched and t2.type = 'update' then update set t1.name = t2.name,t1.age = t2.age //如果临时表对应的值是更新,则直接删除表数据
    |when not matched then insert (id,name,age) values (t2.id,t2.name,t2.age) //如果临时表对应的值不匹配,则进行插入数据
  """.stripMargin)
发布于:4个月前 (01-25) IP属地:未知
我来回答