如何从子目录中将所有数据提取到配置单元中 [英] How to pick up all data into hive from subdirectories

查看:106
本文介绍了如何从子目录中将所有数据提取到配置单元中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将数据以特定格式(如下所示)组织在目录中,并希望将这些数据添加到配置单元表中。我想添加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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆