您的位置:首页 > 其它

hive中快速对表结构数据进行复制

2017-06-22 15:37 246 查看
1. CREATE TABLE new_table LIKE old_table;

2. 使用Hadoop fs -cp 命令,把old_table对应的HDFS目录的文件夹全部拷贝到new_table对应的HDFS目录下;

3. 使用MSCK REPAIR TABLE new_table;修复新表的分区元数据;

#当前没有partition元信息  

hive> show partitions cr_cdma_bsi_mscktest;  

OK  

Time taken: 0.104 seconds  

#创建两个分区目录  

hive> dfs -mkdir /user/hive/warehouse/cr_cdma_bsi_mscktest/month=201603;  

hive> dfs -mkdir /user/hive/warehouse/cr_cdma_bsi_mscktest/month=201604;  

#使用MSCK修复分区  

hive> msck repair table cr_cdma_bsi_mscktest;  

OK  

Partitions not in metastore:    cr_cdma_bsi_mscktest:month=201603  

Partitions not in metastore:    cr_cdma_bsi_mscktest:month=201604  

Repair: Added partition to metastore cr_cdma_bsi_mscktest:month=201603  

Repair: Added partition to metastore cr_cdma_bsi_mscktest:month=201604  

Time taken: 0.286 seconds, Fetched: 2 row(s)  

#再次查看,发现已经成功更新元信息  

hive> show partitions cr_cdma_bsi_mscktest;  

OK  

month=201603  

month=201604  

Time taken: 0.102 seconds, Fetched: 1 row(s)
 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: