无法查询配置单元外部表中的日期字段



完全无法从配置单元外部表中获取数据。到目前为止,我已经完成了以下操作。

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

    创建外部表ext3(运行日期)ROW FORMAT SERDE"org.elasticsearch.hadop.hive.EsSerDe"STORED BY"org.elasticsearch.hadop.hive.EsStorageHandler"TBLPROPERTIES('es.resource'='dfs/ext3','es.field.read.nempty.as.null'='true','es.nodes'=);

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

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

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

    "run_date":{"type":"date","format":"yyyy-MM-ddZ","index":"not_analyzed"}

  2. 在外部表中重新插入数据。当我查询Elastic搜索时,它非常好。值显示为"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)

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

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

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'=);

最新更新