pyspark - PySpark。如何确保每日增量数据在 HIVE 中没有重复的 UUID 作为 PK
问题描述
例如,我在 Hive 中以 UUID 作为主键创建了一个表
create table if not exists mydb.mytable as SELECT uuid() as uni_id, c.name, g.city, g.country
FROM client c
INNER JOIN geo g ON c.geo_id = g.id
每天都需要往mytable中插入数据,如何保证每天的增量数据没有重复的UUID作为PK?
解决方案
如果通过 UUID,您正在寻找的是一系列Universally Unique Identifier,那么我认为您可以使用自动增量 id。在纯HQL中,可以通过row_numer
和cross join来实现。
insert overwrite table dest_tbl
select
a.rn + b.mid as id, col1, col2,...
from (
select
*, row_number() over(order by rand()) as rn
from src_tbl
) a
join (select max(id) as mid from dst_tbl) b
推荐阅读
- python - 用于动态变量的列表 - 与第一个和最后一个字符串一起传递的额外字符
- javascript - 节点中的空数组
- python - keras 根据列添加起始权重
- codeigniter - Codeigniter:index.php?按下后退按钮时删除
- csv - Java CSV:读取/写入具有多个标题行的 CSV
- uibutton - XCode 12 - iOS 14 - UIButton IBAction 不工作
- google-cloud-platform - GCP Compute Engine API 不断请求
- java - Microsoft Excel 在 CSV 文件中添加了特殊字符
- python - Django 中的模型对象创建测试失败
- oracle - 物化视图快速刷新 - 更新基表时插入和删除