我正致力于在配置单元表a上实现增量过程;表a-已在配置单元中创建,已在yearmonth(yyyymm列)上分区,卷已满。
我们正在计划从源代码导入更新/插入,并在配置单元增量表中捕获;
如下图所示,增量表表示新的更新与分区有关(201804/201611/201705)。
对于增量过程,我计划
从原始表中选择3个受影响的分区。
insert into delta2从yyyymm所在的表中选择yyyymm(从delta中选择不同的yyyymm);
将增量表中的这3个分区与原始表中相应的分区合并我可以按照horton works的4步策略应用更新)
Merge Delta2 + Delta : = new 3 partitions.
从原始表中删除3个分区
Alter Table Drop partitions 201804 / 201611 / 201705
将新合并的分区添加回原始表(具有新的更新)
我需要自动化这个脚本-你能不能建议如何把上面的逻辑放到HiveQL或spark中-专门识别分区并从原始表中删除它们。
1条答案
按热度按时间ecr0jaav1#
您可以使用pyspark构建解决方案。我用一些基本的例子来解释这个方法。您可以根据业务需要重新修改。
假设您在配置下面的配置单元中有一个分区表。
您得到了一些csv文件,其中包含一些输入记录,您希望将这些记录加载到分区表中
设置以下属性以仅覆盖特定分区数据。
假设您得到了另一组数据并希望插入到其他分区中
假设您有另一组与现有分区相关的记录。
您可以在下面看到其他分区数据未被触及。