问题1:Hive load数据到表中,查询出来全部为null
查看创表语句并未定义分隔符
create external table if not exists users_test(id int,name string,email string,age int,address string);
文件格式:
[root@master hivedata]# cat users.txt
1胡盼 hupan@163.com 30 北京市立水桥
2 陈芬 chenpan@163.com 31 北京培新街
或者:
[root@master hivedata]# cat users.txt
1,胡盼,hupan@163.com,30,北京市立水桥
2,陈芬,chenpan@163.com,31,北京培新街
解决方法:
create external table if not exists users_test(
id int comment 'id value',
name string comment 'name value',
email string comment 'email value',
age int comment 'age value',
address string comment 'address value')
ROW FORMAT DELIMITED FIELDS TERMINATED BY ',';
重新建表:
hive> create external table if not exists users_test(
> id int comment 'id value',
> name string comment 'name value',
> email string comment 'email value',
> age int comment 'age value',
> address string comment 'address value')
> ROW FORMAT DELIMITED FIELDS TERMINATED BY ',';
OK
Time taken: 0.182 seconds
hive> create external table if not exists users_test(id int,name string,email string,age int,address string)ROW FORMAT DELIMITED FIELDS TERMINATED BY ',';
OK
Time taken: 0.426 seconds
重新插入数据:
hive> load data local inpath '/home/hivedata/userdata.txt' overwrite into table users_test;
Loading data to table regre_one.users_test
Table regre_one.users_test stats: [numFiles=1, numRows=0, totalSize=89, rawDataSize=0]
OK
Time taken: 1.786 seconds
查询数据,数据展示,问题解决。
hive> select * from users_test;
OK
1 胡盼 hupan@163.com 30 北京市立水桥
2 陈芬 chenpan@163.com 31 北京培新街
Time taken: 0.265 seconds, Fetched: 2 row(s)
问题2:Hive使用insert into values插入报错
原因:
Hive使用insert into values插入报错,是因为:
和我们熟悉的关系型数据库不一样,Hive现在还不支持在insert语句里面直接给出一组记录的文字形式,也就是说,Hive并不支持INSERT INTO …. VALUES形式的语句。
解决方法:
从文件中导入数据
[root@master hivedata]# cat userdata.txt
1,胡盼,hupan@163.com,30,北京市立水桥
2,陈芬,chenpan@163.com,31,北京培新街
hive> load data local inpath '/home/cg/hivedata/userdata.txt' overwrite into table users_test;