将数据从 Hive 写入 Amazon S3,同时保持 table 分区目录结构

Write data from Hive to Amazon S3 while maintaining table partition directory structure

假设我在名为 T1 的 Hive 中有一个 table。它按日期字段 dt 列进行分区。在配置单元 Metastore 中,目录结构有一个名为 table T1 的文件夹,其中有子目录 - 每个日期一个文件夹。

我的objective是将table的数据复制到Amazon S3,同时保持目录结构。如果我尝试将 table 内容直接写入 S3 文件,如下所示,输出将写入单个文件并且目录结构丢失:

INSERT OVERWRITE DIRECTORY "s3://<DESTINATION>" SELECT * FROM T1;

或者,如果我尝试使用该命令将目录从 HIVE-metatore 直接复制到 s3,则整个目录将复制到 S3,但底层文件不再以逗号分隔...这是一些改为不可读字符:

s3-dist-cp --src=hdfs://<directory location> --dest=s3://<destination>

谁能帮我完成这个?有什么建议或替代方案吗?

可能的解决方案是使用相同的架构创建 table 并将位置设置为所需位置,然后使用 Hive 和动态分区加载数据:

create table T2 like T1;

Alter table T2 set location = 'your destination location';

set hive.exec.dynamic.partition=true; 
set hive.exec.dynamic.partition.mode=nonstrict;

Insert overwrite table T2 partition (dt)
select * from T1
distribute by dt;