Hive Table returning empty result set on all queries

拥有回忆 提交于 2019-12-01 13:16:11

问题


I created a Hive Table, which loads data from a text file. But its returning empty result set on all queries.

I tried the following command:

CREATE TABLE table2(
id1 INT,
id2 INT,
id3 INT,
id4 STRING,
id5 INT,
id6 STRING,
id7 STRING,
id8 STRING,
id9 STRING,
id10 STRING,
id11 STRING,
id12 STRING,
id13 STRING,
id14 STRING,
id15 STRING
)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '|'
STORED AS TEXTFILE
LOCATION '/user/biadmin/lineitem';

The command gets executed, and the table gets created. But, always returns 0 rows for all queries, including SELECT * FROM table2;

Sample data:

Single line of the input data:

1|155190|7706|1|17|21168.23|0.04|0.02|N|O|1996-03-13|1996-02-12|1996-03-22|DELIVER IN PERSON|TRUCK|egular courts above the|

I have attached the screen shot of the data file. Output for command: DESCRIBE FORMATTED table2;

| Wed Apr 16 20:18:58 IST 2014 : Connection obtained for host: big-instght-15.persistent.co.in, port number 1528. |
| # col_name                    data_type                   comment                                               |
|                                                                                                                 |
| id1                         int                         None                                                    |
| id2                         int                         None                                                    |
| id3                         int                         None                                                    |
| id4                         string                      None                                                    |
| id5                         int                         None                                                    |
| id6                         string                      None                                                    |
| id7                         string                      None                                                    |
| id8                         string                      None                                                    |
| id9                         string                      None                                                    |
| id10                        string                      None                                                    |
| id11                        string                      None                                                    |
| id12                        string                      None                                                    |
| id13                        string                      None                                                    |
| id14                        string                      None                                                    |
| id15                        string                      None                                                    |
|                                                                                                                 |
| # Detailed Table Information                                                                                    |
| Database:                   default                                                                             |
| Owner:                      biadmin                                                                             |
| CreateTime:                 Mon Apr 14 20:17:31 IST 2014                                                        |
| LastAccessTime:             UNKNOWN                                                                             |
| Protect Mode:               None                                                                                |
| Retention:                  0                                                                                   |
| Location:                   hdfs://big-instght-11.persistent.co.in:9000/user/biadmin/lineitem                 |
| Table Type:                 MANAGED_TABLE                                                                       |
| Table Parameters:                                                                                               |
|         serialization.null.format                                                                               |
|         transient_lastDdlTime        1397486851                                                                 |
|                                                                                                                 |
| # Storage Information                                                                                           |
| SerDe Library:              org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe                                  |
| InputFormat:                org.apache.hadoop.mapred.TextInputFormat                                            |
| OutputFormat:               org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat                          |
| Compressed:                 No                                                                                  |
| Num Buckets:                -1                                                                                  |
| Bucket Columns:             []                                                                                  |
| Sort Columns:               []                                                                                  |
| Storage Desc Params:                                                                                            |
|         field.delim                 |                                                                          |

+-----------------------------------------------------------------------------------------------------------------+

Thanks!


回答1:


Please make sure that the location /user/biadmin/lineitem.txt actually exists and you have data present there. Since you are using LOCATION clause your data must be present there, instead of the default warehouse location, /user/hive/warehouse.

Do a quick ls to verify that :

bin/hadoop fs -ls /user/biadmin/lineitem.txt

Also, make sure that you are using the proper delimiter.




回答2:


Did you tried with LOAD DATA LOCAL INFILE

LOAD DATA LOCAL INFILE'/user/biadmin/lineitem.txt' INTO TABLE table2 
FIELDS TERMINATED BY '|'
LINES TERMINATED BY '\n'
(id1,id2,id3........);

Documentation: http://dev.mysql.com/doc/refman/5.1/en/load-data.html




回答3:


Are you using managed table or external table?? If it is external table you should use external keyword while creating the table. after creating the table load data into the table using load command. if it is managed table, after loading data to the table, you could see the data in your hive warehouse directory in hadoop. the default path is "/user/hive/warehouse/yourtablename". you should run the load command in the hive shell.




回答4:


I was able to load the data to the table. The problem was:

LOCATION '/user/biadmin/lineitem';

wasn't loading any data. But when I gave the directory containing the file as the path like:

LOCATION '/user/biadmin/tpc-h';

where I put the lineite.txt file in the tpc-h directory.

It worked!



来源:https://stackoverflow.com/questions/23094261/hive-table-returning-empty-result-set-on-all-queries

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!