为时间戳记录创建正确的avro模式

编程入门 行业动态 更新时间:2024-10-24 15:12:39
本文介绍了为时间戳记录创建正确的avro模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想知道以这种格式进行json到avro转换的正确avro模式是什么:

I would like to know what the proper avro schema would be for some json to avro conversion that is in this format:

{"entryDate": "2018-01-26T12:00:40.930"}

我的模式:

{ "type" : "record", "name" : "schema", "fields" : [{ "name" : "entryDate", "type" : ["null", { "type" : "long", "logicalType" : "timestamp-micros" }], "default" : null }] }

我不断得到

`'Cannot convert field entryDate: Cannot resolve union: "2018-01-26T12:00:40.930" not in ["null",{"type":"long","logicalType":"timestamp-millis"}]'`

推荐答案

这是一个愚蠢的错误……很明显,我将时间戳记值存储为字符串,因此avro模式需要一个字符串而不是long类型.

It was a silly mistake...obviously I was storing the timestamp value as a string so the avro schema needed a string instead of long for type.

即.

{ "type" : "record", "name" : "schema", "fields" : [{ "name" : "entryDate", "type" : ["null", { "type" : `**"long"**`, "logicalType" : "timestamp-micros" }], "default" : null }] }

应该是

{ "type" : "record", "name" : "schema", "fields" : [{ "name" : "entryDate", "type" : ["null", { "type" : `**"string"**`, "logicalType" : "timestamp-micros" }], "default" : null }] }

doh!

更多推荐

为时间戳记录创建正确的avro模式

本文发布于:2023-10-13 09:49:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1487612.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:戳记   正确   模式   时间   avro

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!