内容纲要
概要说明
面对一些重要数据,很多场景下都需要将数据仓库进行复制,这本案例将演示使用HDFS 的 Distcp,以及Inceptor 的分区修复工具 MSCK 的使用方法,来迁移 ORC 普通表,以及ORC 单值分区表;
实际测试发现该方案适用于普通 ORC表、CSV表、Text表、分区表中适用于普通 ORC 单值分区表。
hyperbase、ES、holodesk等表类型未测试;ORC 事务表均不支持该种方案;
详细说明
在不同的 Incpeotr 中,ORC 表的数据文件压缩格式是相同的,本案例就是基于这一特点实现的;该方法主要分为两步:
- 在源集群执行distcp,将数据copy 到目标集群
- 在目标集群根据文件创建相同表结构的表;
- 如果是单值分区表,执行 MSCK 分区修复命令修复;
1. 在源集群执行distcp,将数据copy 到目标集群
将源集群的 source.orc_unpart_hdfs
表的数据文件 copy 到目标集群,distcp 的使用方法参见连接:
如果源集群开了安全,目标集群没有开启安全时,需要添加如下参数:-Dipc.client.fallback-to-simple-auth-allowed=true
$ hadoop distcp -Dipc.client.fallback-to-simple-auth-allowed=true hdfs://nameservice1/inceptor1/user/hive/warehouse/source.db/tableau/orc_unpart_hdfs/ hdfs://172.22.22.161:8020/distcp/
2. 在目标集群指定 location 数据路径创建相同结构的ORC表
CREATE TABLE dest.orc_unpart_hdfs(
group_id int DEFAULT NULL,
code string DEFAULT NULL,
name string DEFAULT NULL,
new_price decimal(8,2) DEFAULT NULL,
main_percent decimal(8,2) DEFAULT NULL,
today_ranking decimal(8,2) DEFAULT NULL,
rise_percent decimal(6,2) DEFAULT NULL,
fiveday_percent decimal(8,2) DEFAULT NULL,
fiveday_ranking decimal(6,2) DEFAULT NULL,
fiveday_rise_percent decimal(5,2) DEFAULT NULL,
teneday_percent decimal(8,2) DEFAULT NULL,
tenday_ranking decimal(6,2) DEFAULT NULL,
tenday_rise_percent decimal(5,2) DEFAULT NULL,
guild string DEFAULT NULL,
code_id string DEFAULT NULL,
data_dt date DEFAULT NULL
) STORED AS ORC
LOCATION '/distcp/orc_unpart_hdfs/';
3. 如果迁移的表是单值分区表,执行 MSCK 命令修复分区;
MSCK 的使用注意事项参见连接 Hive分区修复命令MSCK介绍与使用
USE dest;
MSCK REPAIR TABLE orc_part_key_hdfs;
验证目标集群的数据和源集群一致,至此数据迁移就完成了;