【问题标题】:How to pick up all data into hive from subdirectories如何将所有数据从子目录中提取到配置单元中
【发布时间】:2014-01-12 10:34:29
【问题描述】:

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

【问题讨论】:

  • 上述 CREATE TABLE 语法中的哪一种对您有帮助。我面临同样的问题。我的数据分布在多个目录中。
  • 在最顶层的数据目录上使用第一个创建查询
  • LOCATION 中的通配符对您有用吗?我不能让它工作。它会创建架构,但在我查询表时没有为我检索到任何结果。

标签: hive partition


【解决方案1】:

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

【讨论】:

  • 还有(Hive 1.2):设置 hive.mapred.supports.subdirectories=true;
  • 这如何改变您的创建外部表语句?您还在该位置使用 glob 吗?
【解决方案2】:
ALTER TABLE sampledata
ADD 
PARTITION (ystr ='2012', ymstr='2012-01', ymdstr='2012-01-01') 
LOCATION '/path/to/data/2012/2012-01/2012-01-01';

【讨论】:

  • 这只会给我 2012-01-01 目录的数据。我需要 2012 年超级父目录中的所有数据,以及 2012 年的所有日子。
  • 查询select * from sampledata where ystr = '2012'时,hive会使用所有子目录作为输入。
【解决方案3】:
SET hive.mapred.supports.subdirectories=true;
SET mapred.input.dir.recursive=true;

【讨论】:

  • 请花时间阅读how-to-answer。仅发布代码不是最佳答案。
【解决方案4】:

以下在 hortonworks 上工作

alter table .... set blproperties (
    "hive.input.dir.recursive" = "TRUE",
    "hive.mapred.supports.subdirectories" = "TRUE",
    "hive.supports.subdirectories" = "TRUE",
    "mapred.input.dir.recursive" = "TRUE");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-22
    • 2019-08-14
    • 2018-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多