Hive分区表跨集群迁移

网友投稿 309 2022-11-24

Hive分区表跨集群迁移

(1)先从集群1使用hadoop fs -get将文件下载到本地磁盘 (2)再使用hadoop fs -put将数据上传至集群2的hdfs上 (3)在集群2上创建语句一模一样的表 (4)给集群2的同名hive表添加分区,数据就会自动加载到Hive表中 添加分区可写一个脚本: 首先在集群1下,shell命令行执行 hive -e "show partitions table_name" > partitions.txt 得到类似如下内容:day=17987/event=$AppClick day=17987/event=$AppEnd day=17987/event=$AppStart day=17987/event=$AppStartPassively day=17987/event=$AppViewScreen day=17987/event=$SignUp day=17987/event=$WebClick 我这里day是int类型的,event是字符串类型的, 然后写如下脚本执行: import os file = open("partitions.txt") for line in file: splits = line.split("/") events = splits[1].split("=") partition = splits[0] + "," + events[0] + "=\"" + events[1].strip() + "\"" command = "hive -e 'alter table analysis.events_parquet_mtmy add partition("+partition+");'" os.system(command) 在集群2上执行即可。

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:SpringBoot整合Redisson实现分布式锁
下一篇:hive jdbc连接报错 thrift.TApplicationException: Required field ‘client_protocol‘ is unset !
相关文章

 发表评论

暂时没有评论,来抢沙发吧~