除了模式中预定义的原始类型和复杂类型之外,如何让 avro 代码生成器使用不同的类型?
How do I get the avro code generator to use a different type, other than the predefined primitive and complex types in schema?
我有一个简单的 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] Failed to execute goal
Execution transaction-schemas of goal
org.apache.avro:avro-maven-plugin:1.8.0:schema failed:
"org.joda.time.DateTime" is not a defined name. The type of the
"writeTimestamp" field must be a defined name or a {"type": ...}
expression. -> [Help 1]
如何让它工作?
Avro 目前不支持日期,您必须将时间存储为 long。并且不支持自定义类型,因为这意味着支持该类型的 avro 序列化和反序列化。
我有一个简单的 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] Failed to execute goal
Execution transaction-schemas of goal org.apache.avro:avro-maven-plugin:1.8.0:schema failed: "org.joda.time.DateTime" is not a defined name. The type of the "writeTimestamp" field must be a defined name or a {"type": ...} expression. -> [Help 1]
如何让它工作?
Avro 目前不支持日期,您必须将时间存储为 long。并且不支持自定义类型,因为这意味着支持该类型的 avro 序列化和反序列化。