1

完全坚持从 hive 外部表中获取数据。到目前为止,我已经完成了以下操作。

  1. 我有一个带有日期字段的托管表,其值为 2014-10-23。
  2. 我创建了外部表来在弹性搜索中存储数据,如下所示

    创建外部表 ext3 (run_date date) ROW FORMAT SERDE 'org.elasticsearch.hadoop.hive.EsSerDe' STORED BY 'org.elasticsearch.hadoop.hive.EsStorageHandler' TBLPROPERTIES('es.resource' = 'dfs/ext3', ' es.field.read.empty.as.null' = 'true','es.nodes'=);

  3. 在外部表中插入一行以创建弹性搜索索引和映射。

问题 1: 我的弹性搜索字段被创建为字符串。

  1. 后来我将弹性搜索中的映射更改为迄今为止。

    “运行日期”:{“类型”:“日期”,“格式”:“yyyy-MM-ddZ”,“索引”:“not_analyzed”}

  2. 重新插入外部表中的数据。当我查询弹性搜索时,它非常好。值显示为“2014-10-23+08:00”

问题 2 当我从 ext3 查询外部表(如select count(*))的数据时,出现以下错误。

2015-04-17 18:45:34,254 FATAL [main] org.apache.hadoop.hive.ql.exec.tez.MapRecordProcessor: org.apache.hadoop.hive.ql.metadata.HiveException: Hive Runtime Error while processing row [Error getting row data with exception java.lang.ClassCastException: org.apache.hadoop.hive.serde2.io.TimestampWritable cannot be cast to org.apache.hadoop.hive.serde2.io.DateWritable
    at org.apache.hadoop.hive.serde2.objectinspector.primitive.WritableDateObjectInspector.getPrimitiveWritableObject(WritableDateObjectInspector.java:38)
    at org.apache.hadoop.hive.serde2.SerDeUtils.buildJSONString(SerDeUtils.java:259)
    at org.apache.hadoop.hive.serde2.SerDeUtils.buildJSONString(SerDeUtils.java:349)
    at org.apache.hadoop.hive.serde2.SerDeUtils.getJSONString(SerDeUtils.java:193)
    at org.apache.hadoop.hive.serde2.SerDeUtils.getJSONString(SerDeUtils.java:179)
    at org.apache.hadoop.hive.ql.exec.MapOperator.process(MapOperator.java:545)

伙计们请帮助我,一整天都浪费了。我有另一个包含更多数据的外部表,我需要连接这两个表并创建一个视图,以便我的合并数据准备好进行分析。

4

1 回答 1

3

我认为该错误为您的问题提供了线索:

Error getting row data with exception java.lang.ClassCastException:
  org.apache.hadoop.hive.serde2.io.TimestampWritable cannot be cast to 
  org.apache.hadoop.hive.serde2.io.DateWritable

您的配置单元表中有一个date字段,但您插入的数据属于timestamp.

重新创建您的表(如果您不想替换它,则重新创建一个)

CREATE EXTERNAL TABLE ext3 ( run_date timestamp )
ROW FORMAT SERDE 'org.elasticsearch.hadoop.hive.EsSerDe' 
STORED BY 'org.elasticsearch.hadoop.hive.EsStorageHandler'
TBLPROPERTIES('es.resource' = 'dfs/ext3', 'es.field.read.empty.as.null' = 'true','es.nodes'=);
于 2015-04-17T12:07:26.940 回答