ES往HIVE倒数据遇到时间格式问题
来源:互联网 发布:linux 32位兼容包 编辑:程序博客网 时间:2024/06/01 08:56
项目中遇到ES中的时间格式导入HIVE中,出现异常。
今天晚上有空研究了一下Elasticsearch-hadoop 源码,发现HiveValueReader用的是下面这个方法在解析时间字符串
DatatypeConverter.parseDateTime(value)
没有用到ES中我们指定的时间格式。
curl -XPUT 'localhost:9200/myindex?pretty' -H 'Content-Type: application/json' -d'{ "mappings": { "myindex": { "_all": { "enabled": false }, "properties": { "id": { "type": "keyword" }, "created": { "type": "date", "format": "yyyyMMddHHmmssSSS||epoch_millis" } } } }}'
解决方法:
在HIVE中指定时间格式,并自定义自己的reader. 这里的时间格式是自定义个属性。
CREATE EXTERNAL TABLE myindex (id STRING, created timestamp )STORED BY 'org.elasticsearch.hadoop.hive.EsStorageHandler'TBLPROPERTIES('es.resource' = 'myindex/myindex', 'es.date.format' = 'yyyyMMddHHmmssSSS', 'es.ser.reader.value.class' = 'gez.es.hadoop.reader.EsValueReader');
自定义的reader
package gez.es.hadoop.reader;import java.sql.Timestamp;import java.util.Date;import javax.xml.bind.DatatypeConverter;import org.apache.hadoop.hive.serde2.io.TimestampWritable;import org.elasticsearch.hadoop.cfg.Settings;import org.elasticsearch.hadoop.hive.HiveValueReader;import jodd.util.StringUtil;public class EsValueReader extends HiveValueReader{private String dateFormat;org.apache.hadoop.io.Writable f;@Override public void setSettings(Settings settings) { super.setSettings(settings); dateFormat = settings.getProperty("es.date.format"); }@Override protected Object parseDate(String value, boolean richDate) {Date d = null;System.out.println(String.format("value : %s, dataFormat: %s ", value, dateFormat));if(StringUtil.isNotEmpty(dateFormat)) {d = DateUtil.parseDate(value, dateFormat);} else { d = DatatypeConverter.parseDateTime(value).getTime();}return (richDate ? new TimestampWritable(new Timestamp(d.getTime())) : parseString(value)); }public static void main(String[] args) {}}
新jar 需要添加到HIVE的lib
运行结果如下:
阅读全文
0 0
- ES往HIVE倒数据遇到时间格式问题
- es-hadoop-hive 时间格式问题记录
- hive建表没使用LZO存储格式,但是数据是LZO格式时遇到的问题
- hive 数据写入es
- hive读取es数据
- es遇到的问题
- Mysql倒数据问题
- hive 时间格式,计算
- Hive时间格式转换
- es使用遇到的问题
- excel导入数据的时间格式问题
- hive导入数据到hbase 遇到的问题
- mysql数据导入到hive遇到的问题
- Hive 不同存储格式表数据同步问题
- hive与es之间实现数据交互
- 利用hive将数据写入es
- ES存储的时间问题
- 使用sqoop做Mysql与Hive数据互倒操作
- 浏览器关闭后,Session会话结束了么?
- 时序
- span创建行内元素
- 导航制作
- 增加点赞手势图及提交按钮图标
- ES往HIVE倒数据遇到时间格式问题
- 弄丢了CSDN保温杯及答复迄今的评论
- Vuejs入门(1.0)
- 后端开发框架
- 我的CSDN账号C币莫名其妙少了约200个
- Bootstrap学习心得
- Indeed2017/10/21 BackUp Integrity
- 【Cassandra】数据模型
- tomcat7配置systemd服务示例