码迷,mamicode.com
首页 > 其他好文 > 详细

数据仓库Hive数据导入导出

时间:2017-04-08 14:03:10      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:log4j   awd   cal   txt   ini   format   etc   ogg   second   

Hive库数据导入导出

1、新建表data

hive (ebank)> create table data(id int,name string)

            > ROW FORMAT DELIMITED

            > FIELDS TERMINATED BY‘\t‘     

            > stored as textfile;

OK

Time taken: 0.257 seconds

2、向data表中插入数据

hive (ebank)> load data local inpath ‘/home/hive/data.txt‘ overwrite into table data;

Loading data to table ebank.data

Table ebank.data stats: [numFiles=1, numRows=0, totalSize=33, rawDataSize=0]

OK

Time taken: 0.909 seconds

3、查询表中数据

hive (ebank)> select * from data;

OK

data.id data.name

101     张三

102     李四

103     王五

Time taken: 0.092 seconds, Fetched: 3 row(s)

4、表中数据落地

[hive@ksh-master result]$ hive -e "select * from ebank.data" >> /home/hive/result/data.txt

 

Logging initialized using configuration in file:/etc/hive/2.5.3.0-37/0/hive-log4j.properties

OK

Time taken: 1.283 seconds, Fetched: 3 row(s)

5、查看落地的数据

[hive@ksh-master result]$ head data.txt

data.id data.name

101     张三

102     李四

103     王五

6、新建一张和data相同表结构的表data002

hive (ebank)> create table data002 like data;

OK

Time taken: 5.533 seconds

7、查看新建表结构

hive (ebank)> desc data002;

OK

col_name        data_type       comment

id                int                                         

name             string                                      

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

8、落地的数据文件再次入表

hive (ebank)> load data local inpath ‘/home/hive/result/data.txt‘ overwrite into table data002;

Loading data to table ebank.data002

Table ebank.data002 stats: [numFiles=1, numRows=0, totalSize=51, rawDataSize=0]

OK

Time taken: 39.613 seconds

9、查看新表中数据

hive (ebank)> select * from data002;

OK

data002.id      data002.name

NULL    data.name------------>(这一行为原表表头)

101     张三

102     李四

103     王五

Time taken: 3.874 seconds, Fetched: 4 row(s)

 

数据仓库Hive数据导入导出

标签:log4j   awd   cal   txt   ini   format   etc   ogg   second   

原文地址:http://www.cnblogs.com/RHadoop-Hive/p/6681486.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!