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;