【问题标题】:Hive query not reading partition fieldHive 查询未读取分区字段
【发布时间】:2019-05-04 08:16:47
【问题描述】:

我使用以下查询创建了一个分区 Hive 表

CREATE EXTERNAL TABLE `customer`(            
   `cid` string COMMENT '',              
   `member` string COMMENT '',           
   `account` string COMMENT '')
   PARTITIONED BY (update_period 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' 
 LOCATION                                           
   'hdfs://nameservice1/user/customer'          
 TBLPROPERTIES (                                    
   'avro.schema.url'='/user/schema/Customer.avsc')

我正在使用 map reduce 程序写入分区位置。当我使用 avro 工具读取输出文件时,它以 json 格式显示正确的数据。但是当我使用 hive 查询来显示数据时,什么都没有显示。如果我在创建表期间不使用分区字段,则这些值将显示在配置单元中。这可能是什么原因?我将 mapreduce 程序的输出位置指定为“/user/customer/update_period=201811”。

是否需要在 mapreduce 程序配置中添加任何内容来解决此问题?

【问题讨论】:

    标签: hadoop hive mapreduce avro hadoop-partitioning


    【解决方案1】:

    在 HDFS 位置加载新分区后,您需要运行 msck repair table

    为什么每次摄取后都需要运行 msck Repair table 语句?

    Hive 将每个表的分区列表存储在其元存储中。但是 新分区直接添加到 HDFS ,除非用户运行以下任一方式来添加新添加,否则元存储(以及 Hive)将不会知道这些分区分区。

    1.将每个分区添加到表中

    hive> alter table <db_name>.<table_name> add partition(`date`='<date_value>')
     location '<hdfs_location_of the specific partition>';
    

    (或)

    2.使用修复表选项运行 Metastore 检查

    hive> Msck repair table <db_name>.<table_name>;
    

    将为尚不存在此类元数据的分区添加有关分区的元数据到 Hive 元存储。换句话说,它将任何存在于 HDFS 上但不在 Metastore 中的分区添加到 Metastore。

    【讨论】:

      猜你喜欢
      • 2018-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-25
      • 2016-09-06
      • 1970-01-01
      • 1970-01-01
      • 2023-03-05
      相关资源
      最近更新 更多