在hive里建表如下:
CREATE TABLE `sor`(
`id` int,
`age` int,
`name` string,
`tel` string)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '\t'
LINES TERMINATED BY '\n'
STORED AS textfile
在本系统里写个文件(列分割\t)
~]$ cat sor
5 23 tom 123456789
6 24 jim 234567890
7 36 jany 536278493
4 26 meray 049784237
进入到hive,将本地的文件导入hive表中
> load data local inpath 'sor' into table sor;
Loading data to table cnntest.sor
OK
Time taken: 0.582 seconds
hive> select * from sor;
OK
5 23 tom 123456789
6 24 jim 234567890
7 36 jany 536278493
4 26 meray 049784237
NULL NULL NULL NULL
文件里多了空行,这里多了一行null
解决:
hive> select * from sor where id is null;
OK
NULL NULL NULL NULL
NULL NULL NULL NULL
Time taken: 0.274 seconds, Fetched: 2 row(s)
insert overwrite table sor select * from sor where id is not null; //覆盖之前表里的数据
hive> select * from sor;
OK
5 23 tom 123456789
6 24 jim 234567890
7 36 jany 536278493
4 26 meray 049784237
阅读(8187) | 评论(0) | 转发(0) |