【HIVE 入门2】简单操作

本文详细介绍了如何使用Hive进行数据操作,包括创建表、导入本地数据、追加数据、从HDFS导入数据以及导入另一个表的数据等步骤,并演示了如何通过查询创建新表。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


0 前提

hive 安装完毕,进入 shell

1 创建表

create table test(
id int,
name string,
age string
)
row format delimited fields terminated by '\t'
stored as textfile;

Note:文本是通过table键分割,如果文本格式有问题,读到的数据都会成为Null

2 导入本地数据

在当前键入hive的目录下,创建一个文件test.txt;

1       apple   123
2       banana   234
3       pillow  345
4       orange  238

再键入hive,进入shell

hive >load data local inpath 'test.txt' into table test;
hive >select * from test;


3 追加本地数据

创建一个add.txt

5       Jame    321
6       Tom     344
7       Nathan  345

hive >load data local inpath 'add.txt' into table test;
hive > select * from test;

4 添加hdfs上文件

hdfs.txt

hadoop fs -put hdfs.txt /

9       Peter   987
10      Thunder 874
11      Kobe    785


hive >load data inpath '/hdfs.txt' into table test;
hive > select * from test;

5 导入表数据

newtest.txt
12    Babara    8472
13    Amy    837   
14    Emma    874

create table newtest(
id int,
name string,
tel string
)
row format delimited fields terminated by '\t'
stored as textfile;
hive>load data local inpath 'newtest.txt' into table newtest;
hive>insert into table test select * from newtest;
#hive>insert into table test select id,name,tel from newtest;


6 查询另存为表

hive> create table selecttest as select id,name from test;
hive> select * from selecttest;



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值