Hive复制分区表结构以及表数据
发布日期:2021-06-29 01:25:02
浏览次数:2
分类:技术文章
本文共 4267 字,大约阅读时间需要 14 分钟。
目录
1、创建一张表,即将要被复制的表old_table:
hive (default)> create table old_table(age bigint,height string,weight string) partitioned by(p_month int,p_day int,p_hour int)row format delimited fields terminated by ',' STORED AS INPUTFORMAT 'org.apache.hadoop.mapred.TextInputFormat' OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat' ;OKTime taken: 0.429 secondshive (default)> desc old_table;OKcol_name data_type commentage bigint height string weight string p_month int p_day int p_hour int # Partition Information # col_name data_type comment p_month int p_day int p_hour int Time taken: 0.112 seconds, Fetched: 13 row(s)
2、向old_table中添加数据,新建文本文件data.txt,向其中添加三行数据,建表时的分隔符为逗号,所以我们用逗号分隔:
25,170,7024,175,6527,180,80
3、使用load命令向表中添加数据:
hive (default)> LOAD DATA LOCAL INPATH '/home/hadoop/temp/data.txt' OVERWRITE INTO TABLE old_table PARTITION (p_month='201609',p_day='20160908',p_hour='2016090800');Loading data to table default.old_table partition (p_month=201609, p_day=20160908, p_hour=2016090800)OKTime taken: 3.424 secondshive (default)> show partitions old_table;OKpartitionp_month=201609/p_day=20160908/p_hour=2016090800Time taken: 0.202 seconds, Fetched: 1 row(s)hive (default)> select * from old_table;OKold_table.age old_table.height old_table.weight old_table.p_month old_table.p_day old_table.p_hour25 170 70 201609 20160908 201609080024 175 65 201609 20160908 201609080027 180 80 201609 20160908 2016090800Time taken: 0.099 seconds, Fetched: 3 row(s)
4、复制该表结构到新表,即new_table:
hive (default)> create table new_table like old_table;OKTime taken: 0.099 secondshive (default)> desc new_table;OKcol_name data_type commentage bigint height string weight string p_month int p_day int p_hour int # Partition Information # col_name data_type comment p_month int p_day int p_hour int Time taken: 0.093 seconds, Fetched: 13 row(s)hive (default)> select * from new_table limit 10;OKnew_table.age new_table.height new_table.weight new_table.p_month new_table.p_day new_table.p_hourTime taken: 0.566 secondshive (default)> show partitions new_table;OKpartitionTime taken: 0.063 seconds
5、然后将使用命令hadoop fs -cp旧表数据复制到新表的hdfs目录下:
[hadoop@node1 ~]$ hadoop fs -cp /user/hive/warehouse/old_table/* /user/hive/warehouse/new_table/
6、使用命令 MSCK REPAIR TABLE new_table刷新原数据信息:
hive (default)> MSCK REPAIR TABLE new_table;OKPartitions not in metastore: new_table:p_month=201609/p_day=20160908/p_hour=2016090800Repair: Added partition to metastore new_table:p_month=201609/p_day=20160908/p_hour=2016090800Time taken: 0.447 seconds, Fetched: 2 row(s)
7、然后查询可看到new_table的数据:
hive (default)> select * from new_table;OKnew_table.age new_table.height new_table.weight new_table.p_month new_table.p_day new_table.p_hour25 170 70 201609 20160908 201609080024 175 65 201609 20160908 201609080027 180 80 201609 20160908 2016090800Time taken: 0.5 seconds, Fetched: 3 row(s)
转载地址:https://blog.csdn.net/ytp552200ytp/article/details/90697122 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
感谢大佬
[***.8.128.20]2024年04月28日 17时34分02秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
allure报告的定制化
2019-04-29
怎样给excel添加一行数据
2019-04-29
怎样彻底帮妹子解决weditor的安装的问题
2019-04-29
干货|一次完整的性能测试,测试人员需要做什么?
2019-04-29
全栈性能测试修炼宝典
2019-04-29
jmeter-性能测试9-测试执行
2019-04-29
沟通交流碎碎念
2019-04-29
电信集成笔试题
2019-04-29
jmeter-性能测试8-性能测试基本过程及示例
2019-04-29
1.vue起步
2019-04-29
3.vue条件语句
2019-04-29
10.vue实战--form表单属性绑定
2019-04-29
11.vue实战--form表单字段验证提交验证
2019-04-29
12.vue实战--接口请求,组件使用,页面跳转配置
2019-04-29
打破职能之缺陷预防之路
2019-04-29
mac开启mysql,重置mysql密码,允许远程连接
2019-04-29
安装kibana
2019-04-29
linux安装nodejs
2019-04-29
tomcat部署vue,spring项目
2019-04-29
idea2020打包war包
2019-04-29