9

我将数据以特定格式(如下所示)组织在目录中,并希望将这些数据添加到配置单元表中。我想添加 2012 目录的所有数据。以下所有名称都是目录名称,最里面的目录(第 3 级)具有实际的数据文件。有什么方法可以直接提取数据而无需更改此目录结构。任何指针表示赞赏。

/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

到目前为止尝试的查询没有运气:

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/';

解决方案: 这个小参数解决了我的问题。添加到可能对其他人有益的问题:

SET mapred.input.dir.recursive=true;
4

4 回答 4

11

用适合我的情况的解决方案回答我自己的问题。设置 mapred.input.dir.recursive=true;

于 2013-12-25T09:12:13.613 回答
1
ALTER TABLE sampledata
ADD 
PARTITION (ystr ='2012', ymstr='2012-01', ymdstr='2012-01-01') 
LOCATION '/path/to/data/2012/2012-01/2012-01-01';
于 2013-12-24T07:22:09.470 回答
1
SET hive.mapred.supports.subdirectories=true;
SET mapred.input.dir.recursive=true;
于 2017-05-06T19:22:14.560 回答
0

以下工作于 hortonworks

alter table .... set blproperties (
    "hive.input.dir.recursive" = "TRUE",
    "hive.mapred.supports.subdirectories" = "TRUE",
    "hive.supports.subdirectories" = "TRUE",
    "mapred.input.dir.recursive" = "TRUE");
于 2017-10-10T16:32:10.520 回答