question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Avro format enconding

See original GitHub issue

I would like to propose an official Avro encoding schema to be supported by CloudEvents.

I’ve seen a lot of uses cases, in special here in my current project, with Apache Kafka and the many of them were using Avro as the format. Inspired by this Gist (thanks @rbramley), the following schema could be the first draft:

{
  "namespace":"io.cloudevents",
  "type":"record",
  "name":"CloudEvent",
  "version": "1",
  "doc": "CloudEvents Spec for Avro format encoding (the version is just for the schema itself)",
  "fields":[
    {
      "name":"specversion",
      "type":"string"
    },
    {
      "name":"type",
      "type":"string"
    },
    {
      "name":"source",
      "type":"string"
    },
    {
      "name":"id",
      "type":"string",
    },
    {
      "name":"time",
      "type":[
        "null",
        "int"
      ],
      "logicalType": "date"
    },
    {
      "name":"schemaurl",
      "type":[
        "null",
        "string"
      ]
    },
    {
      "name":"contenttype",
      "type":[
        "null",
        "string"
      ]
    },
    {
      "name":"data",
      "type":[
        "null",
        "string"
      ]
    },
    {
      "name":"extensions",
      "type":[
        "null",
        {
          "type":"map",
          "values":[
            "string",
            "int",
            "long",
            "float",
            "double",
            "boolean",
            "bytes"
          ]
        }
      ]
    },
  ]
}
  • Official Avro spec available here

Extensions

To define a top-level extension (like below) is not allowed by Avro spec for avsc, because we do not have the feature for dynamic fields like JSON. Because of this, you will see the extension attribute to the example above.

...
    "comexampleextension1" : "value",
    "comexampleextension2" : {
        "othervalue": 5
    }
...

For that, we may employ Avro spec for ìdl that is a higher-level language for authoring Avro schemas.

  • Official Avro IDL docs available here

Special Types

What I mean with special types, logical types in JSON Schema, are: uri-reference. We do not have this type in Avro.

For that, again, we may employ Avro IDL.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
gunnarmorlingcommented, Jun 7, 2019

Ha, came here to file a feature request for Avro myself, it’s there already 😃 I’m not sure where things stand with that format spec, but I’ll be happy to help out with it.

1reaction
clemensvcommented, May 6, 2019

That’s a great idea. Avro and CBOR are the two extra encodings which I’d love to see.

@duglin this would be a different event format, not a different transport.

I’m in favor. Who writes the spec.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Avro Binary Format - Ambitious Systems
Avro specifies two serialization encodings: binary and JSON. Binary encoding is the default and used by most applications as it is smaller ...
Read more >
A short introduction to Avro binary encoding - Memory Spills
When developing applications processing Avro data, a basic understanding of Avro schema and Avro binary encoding is helpful.
Read more >
Apache Avro - Wikipedia
Avro uses a schema to structure the data that is being encoded. It has two different types of schema languages; one for human...
Read more >
Avro Binary encoding based on messages in Kafka
In this post we will explore Avro binary encoding. We will go from simple one value schemas, all the way to complex records....
Read more >
A Detailed Introduction to the Avro Data Format - SQream
Binary format: This is the compact, performant default format. Strings are encoded as UTF-8, the rest as binary. As a simplified example, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found