【问题标题】:How do I get the avro code generator to use a different type, other than the predefined primitive and complex types in schema?我如何让 avro 代码生成器使用不同的类型,而不是模式中预定义的原始类型和复杂类型?
【发布时间】:2016-02-16 19:49:48
【问题描述】:

我有一个简单的 avro 架构,如下所示:

{
        "type": "record",
        "name": "transaction",
        "namespace": "com.mycompany",
        "doc": "Transaction records",
        "fields": [

        {
                "name": "version",
                "type": "int",
                "default": 1,
                "doc": "version the class"
        },
        {
                "name": "eventType",
                "type": "string",
                "default": "saleTransaction",
                "doc": "event type"
        },
        {
                "name": "writeTimestamp",
                "type": "org.joda.time.DateTime",
                "doc": "Timestamp when this event was written to the stream"
        },
        {
                "name": "originatingClient",
                "type": "string",
                "doc": "identifier of the originating client"
        }
}

当我使用 avro-maven-plugin 编译它时,我收到以下错误:

ERROR] 未能执行目标

目标的执行交易模式 org.apache.avro:avro-maven-plugin:1.8.0:schema 失败: “org.joda.time.DateTime”不是一个定义的名称。的类型 "writeTimestamp" 字段必须是定义的名称或 {"type": ...} 表达。 -> [帮助 1]

如何让它工作?

【问题讨论】:

    标签: avro


    【解决方案1】:

    目前在 Avro 中不支持日期,您必须将时间存储得尽可能长。并且不支持自定义类型,因为这意味着支持该类型的 avro 序列化和反序列化。

    【讨论】:

    • 啊,当然。反序列化是问题。明白了。
    猜你喜欢
    • 1970-01-01
    • 2019-01-28
    • 2010-12-06
    • 2017-01-21
    • 2014-09-26
    • 1970-01-01
    • 2013-02-02
    • 1970-01-01
    • 2011-03-14
    相关资源
    最近更新 更多