Search code examples
avro

How do I get the avro code generator to use a different type, other than the predefined primitive and complex types in schema?


I have a simple avro schema that looks like this:

{
        "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"
        }
}

When I compile it using avro-maven-plugin, I get the following error:

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]

How do I get this to work?


Solution

  • There is no date support as of now in Avro, you would have to store the time as a long. And there is no support for custom types, as that would mean to support avro serialization and deserialization of that type.