解决elasticsearch -在Hive external table 无法读取 date 字段

本文介绍在Elasticsearch中使用日期字段时遇到的问题及解决方案。当在Hive外部表中使用@timestamp字段并尝试将其设置为date类型时,会触发ClassCastException异常。文章提供了解决方案,即将date类型更改为timestamp。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.问题描述

   对于@timestamp字段,在es中类型为date,创建hive外表时如果使用类型仍为date,操作时会报如下错误

 Failed with exception java.io.IOException:org.apache.hadoop.hive.ql.metadata.HiveException: java.lang.ClassCastException: org.apache.hadoop.hive.serde2.io.TimestampWritable cannot be cast to org.apache.hadoop.hive.serde2.io.DateWritable

  

2.解决办法

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

  

 参考:http://www.itkeyword.com/doc/6573413286728074561/unable-to-query-date-field-in-hive-external-table

             https://www.iteblog.com/archives/892.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值