网站首页
网站导航
Ctrl+D收藏
首 页
代码段
源码包
文档库
工具箱
代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
Hive
】
Hive复制分区表结构以及表数据
作者:
/ 发布于
2017/6/30
/
381
创建一张表,即将要被复制的表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' ; OK Time taken: 0.429 seconds hive (default)> desc old_table; OK col_name data_type comment age 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) 向old_table中添加数据,新建文本文件data.txt,向其中添加三行数据,建表时的分隔符为逗号,所以我们用逗号分隔: 25,170,70 24,175,65 27,180,80 使用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) OK Time taken: 3.424 seconds hive (default)> show partitions old_table; OK partition p_month=201609/p_day=20160908/p_hour=2016090800 Time taken: 0.202 seconds, Fetched: 1 row(s) hive (default)> select * from old_table; OK old_table.age old_table.height old_table.weight old_table.p_month old_table.p_day old_table.p_hour 25 170 70 201609 20160908 2016090800 24 175 65 201609 20160908 2016090800 27 180 80 201609 20160908 2016090800 Time taken: 0.099 seconds, Fetched: 3 row(s) 复制该表结构到新表,即new_table: hive (default)> create table new_table like old_table; OK Time taken: 0.099 seconds hive (default)> desc new_table; OK col_name data_type comment age 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; OK new_table.age new_table.height new_table.weight new_table.p_month new_table.p_day new_table.p_hour Time taken: 0.566 seconds hive (default)> show partitions new_table; OK partition Time taken: 0.063 seconds 然后将使用命令hadoop fs -cp旧表数据复制到新表的hdfs目录下: [hadoop@node1 ~]$ hadoop fs -cp /user/hive/warehouse/old_table/* /user/hive/warehouse/new_table/ 之后使用命令 MSCK REPAIR TABLE new_table刷新原数据信息: hive (default)> MSCK REPAIR TABLE new_table; OK Partitions not in metastore: new_table:p_month=201609/p_day=20160908/p_hour=2016090800 Repair: Added partition to metastore new_table:p_month=201609/p_day=20160908/p_hour=2016090800 Time taken: 0.447 seconds, Fetched: 2 row(s) 然后查询可看到new_table的数据: hive (default)> select * from new_table; OK new_table.age new_table.height new_table.weight new_table.p_month new_table.p_day new_table.p_hour 25 170 70 201609 20160908 2016090800 24 175 65 201609 20160908 2016090800 27 180 80 201609 20160908 2016090800 Time taken: 0.5 seconds, Fetched: 3 row(s)
评论列表
本站所提供的代码,版权归原作者所有,若有侵犯作者版权,请与我们联系,我们将立即删除或修改。谢谢!
本站所有代码发布及提供者。
试试其它关键字
同语言下
.
hive 数据清理--数据去重
.
实现一个字段包含另一个字段的查询
.
Hive窗口函数之累积值、平均值、首尾值的计算学习
.
Hive 累积和的计算
.
hive表创建,删除,导入数据,删除数据
.
INNER JOIN连接两个表、三个表、五个表的SQL语句
.
多表inner join用法
.
Hive创建临时表
.
分组排序 取top N
.
hive指定hadoop执行队列
可能有用的
.
hive 数据清理--数据去重
.
实现一个字段包含另一个字段的查询
.
Hive窗口函数之累积值、平均值、首尾值的计算学习
.
Hive 累积和的计算
.
hive表创建,删除,导入数据,删除数据
.
INNER JOIN连接两个表、三个表、五个表的SQL语句
.
多表inner join用法
.
Hive创建临时表
.
分组排序 取top N
.
hive指定hadoop执行队列
贡献的其它代码
Label
地图
本站
我们
服务
版权
联系
回馈
博客