如何从子目录中将所有数据提取到配置单元中 [英] How to pick up all data into hive from subdirectories
问题描述
我将数据以特定格式(如下所示)组织在目录中,并希望将这些数据添加到配置单元表中。我想添加2012目录的所有数据。
以下所有名称都是目录名称,而最内层的目录(第三层)具有实际的数据文件。
有没有什么办法可以直接选择数据,而无需更改此dir结构。
赞赏任何指针。
/ 2012 /
|
| --------- 2012-01
| --------- 2012-01-01
| --------- 2012-01-02
| ...
| ...
| --------- 2012-01-31
|
| --------- 2012-02
| --------- 2012-02-01
| --------- 2012-02-02
| ...
| ...
| --------- 2012-02-28
|
| --------- 2012-03
| ...
| ...
| --------- 2012-12
到目前为止尝试的查询没有运气:
<$ $'$'$'$ $ $ $'$'$'$'$'$'$'$'$'$'$'$'$'$'$'$'$'$'到/数据/ 2012 / * / *';
CREATE EXTERNAL TABLE sampledata
(datestr string,id string,locations string)
被(ystr string, TERMINATED BY'|';
ALTER TABLE sampledata
ADD
PARTITION(ystr ='2012')
LOCATION'/ path / to / data / 2012 /';
解决方案:
这个小参数解决了我的问题。添加到可能对其他人有用的问题中:
SET mapred.input.dir.recursive = true;
回答我自己的问题, 。 SET mapred.input.dir.recursive = true;
I have data organized in directories in a particular format (shown below) and want to add these to hive table. I want to add all data of 2012 directory. All below names are directory names, and the inner most dir (3rd level) has the actual data files. Is there any way to pick in the data directly without having to change this dir structure. Any pointers are appreciated.
/2012/
|
|---------2012-01
|---------2012-01-01
|---------2012-01-02
|...
|...
|---------2012-01-31
|
|---------2012-02
|---------2012-02-01
|---------2012-02-02
|...
|...
|---------2012-02-28
|
|---------2012-03
|...
|...
|---------2012-12
Queries tried so far without luck:
CREATE EXTERNAL TABLE sampledata
(datestr string, id string, locations string)
ROW FORMAT DELIMITED FIELDS TERMINATED BY '|'
LOCATION '/path/to/data/2012/*/*';
CREATE EXTERNAL TABLE sampledata
(datestr string, id string, locations string)
partitioned by (ystr string, ymstr string, ymdstr string)
ROW FORMAT DELIMITED FIELDS TERMINATED BY '|';
ALTER TABLE sampledata
ADD
PARTITION (ystr ='2012')
LOCATION '/path/to/data/2012/';
SOLUTION: This small parameter fixes my issue. Adding to the question where it might be beneficial for others:
SET mapred.input.dir.recursive=true;
Answering my own question with solution that works for my case. SET mapred.input.dir.recursive=true;
这篇关于如何从子目录中将所有数据提取到配置单元中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!