目錄
1、建立一張表,即將要被複製的表old_table:
2、向old_table中新增資料,新建文字檔案data.txt,向其中新增三行資料,建表時的分隔符為逗號,所以我們用逗號分隔:
3、使用load命令向表中新增資料:
4、複製該錶結構到新錶,即new_table:
5、然後將使用命令hadoop fs -cp舊表資料複製到新錶的hdfs目錄下:
6、使用命令 msck repair table new_table重新整理原資料資訊:
7、然後查詢可看到new_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 seconds
hive (default)> desc old_table;
okcol_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)
25,170,70
24,175,65
27,180,80
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 seconds
hive (default)> show partitions old_table;
okpartition
p_month=201609/p_day=20160908/p_hour=2016090800
time 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_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)
hive (default)> create table new_table like old_table;
oktime taken: 0.099 seconds
hive (default)> desc new_table;
okcol_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;
oknew_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;
okpartition
time taken: 0.063 seconds
[hadoop@node1 ~]$ hadoop fs -cp /user/hive/warehouse/old_table/* /user/hive/warehouse/new_table/
hive (default)> msck repair table new_table;
okpartitions 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)
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_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分割槽表快速複製
drop table if exists dwt.dwt activity auction house activity sale full 1d 0805forliuqian create table dwt.dwt activity auction house activity sale ful...
hive 分割槽表
partitioned by create table tb name name string partitioned by age int row format delimited fields terminated by t load data local inpath file path in...
hive分割槽表
partition對應於資料庫的 partition 列的密集索引 在 hive 中,表中的乙個 partition 對應於表下的乙個目錄,所有的 partition 的資料都儲存在對應的目錄中 例如 test表中包含 date 和 city 兩個 partition 則對應於date 201302...