【问题标题】:Hive Table from Multiple Avro Files?来自多个 Avro 文件的 Hive 表?
【发布时间】:2016-02-23 16:46:56
【问题描述】:

我在 HDFS 目录中有数千个 Avro 文件,格式为 yyyy/mm/dd/。在每个目录中可能有 200-400 个 .avro 文件,其中包含当天的数据。

当我创建一个 EXTERNAL 表时,我认为 LOCATION 属性假定一个文件...有没有办法将它指向一个文件目录并让它读取所有文件?

【问题讨论】:

  • LOCATION,如果设置为一个目录,将读取该目录下的所有文件。
  • 包括子目录?
  • 如果你也想处理子目录,你会想看看动态分区,假设你每天都很高兴成为一个分区,并且每天的文件夹中没有数据目录.

标签: hadoop hive avro


【解决方案1】:

确保在构建表时指定分区。然后使用更改表并根据需要添加分区,如下所示:

create external table mydatabase.NEW_TABLE
partitioned by (date string)
row format serde 'org.apache.hadoop.hive.serde2.avro.AvroSerDe'
stored as inputformat    '
'org.apache.hadoop.hive.ql.io.avro.AvroContainerInputFormat'
outputformat 'org.apache.hadoop.hive.ql.io.avro.AvroContainerOutputFormat'
tblproperties ('avro.schema.literal'='{
"name": "my_record",
"type": "record",
"fields": [
   {"name":"boolean1", "type":"boolean"},
   {"name":"int1", "type":"int"},
   {"name":"long1", "type":"long"},
   {"name":"float1", "type":"float"},
   {"name":"double1", "type":"double"},
   {"name":"string1", "type":"string"},
   {"name": "nullable_int", "type": ["int", "null"]]}');
alter table mydatabase.NEW_TABLE add partition (date='20150304') location '/path/to/somefiles/20150304;
alter table mydatabase.NEW_TABLE add partition (date='20150305') location '/path/to/somefiles/20150305;
alter table mydatabase.NEW_TABLE add partition (date='20150306') location '/path/to/somefiles/20150306;

您可以根据需要添加任意数量的分区。我建议您将此表设置为外部表,这样您就不会在出错时删除分区中的数据。

【讨论】:

    【解决方案2】:

    直接来自Hive documentation

    hive.mapred.supports.subdirectories
      Default Value: false
      Added In: Hive 0.10.0 with HIVE-3276
    

    运行的Hadoop版本是否支持 表/分区的子目录。许多 Hive 优化可以是 如果 Hadoop 版本支持子目录 表/分区。此支持由 MAPREDUCE-1501 添加。

    反过来,Hadoop 功能可以通过mapred.input.dir.recursive 切换。

    参考:that post(以及其他)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多