hive查询表,返回结果是null

问题:hive查询表,返回结果都是null

hive> create table testTable(id int, name string);

hive> load data local inpath '/home/test.txt' into table testTable;

其中“/home/test.txt”的内容为下面所示,每一行的(id,name)之间使用一个空格分割。

1 tom
2 lili

hive> select * from users;
OK
NULL NULL
NULL NULL

解决办法:

hive> create table testTable(id int, name string);

改为:

hive> CREATE TABLE testTable(id int, name string) ROW FORMAT DELIMITED FIELDS TERMINATED BY ' ' LINES TERMINATED BY ' ' STORED AS TEXTFILE;

其中TERMINATED BY ' '指定了数据分隔符是一个空格,与“/home/test.txt”中每行分隔符一致。

hive> select * from new_test;
OK
1 tom
2 lili

综上所述:hive 中创建表加载数据的时候,分隔符与加载文件中的分隔符需要一致,才能得到正确的查询结果.

原文地址:https://www.cnblogs.com/royfans/p/7211924.html