首页 > 代码库 > 数据仓库Hive数据导入导出

数据仓库Hive数据导入导出

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数据导入导出