What is Apache Avro?
Apache Avro stores or sends records in a form that software can read. A schema describes each record. It names the fields and says what kind of value each field holds, such as a whole number or a piece of text.
What is in an Avro file?
An Avro object container file starts with a header that holds the writer’s schema. After the header come blocks of binary data. The file uses that one schema for all its records, so it can store the values without repeating the field names for each record.
An .avsc file holds a schema in JSON. An .avro file holds the records and includes the schema used to write them. When you send someone the sample .avro file below, they can read its records without a separate .avsc file.
Example contacts and schema
Our Contact schema says that id is a long, a whole number, and name is a string, or text. The JSON array has two contacts. Each one needs the fields described by the schema.
[
{"id": 42, "name": "Avery"},
{"id": 51, "name": "Ellis"}
]{
"type": "record",
"name": "Contact",
"fields": [
{"name": "id", "type": "long"},
{"name": "name", "type": "string"}
]
}When is Avro useful?
Avro suits jobs that pass batches of records between systems. For example, a data pipeline might write new contact records every hour so another job can load them later. Use JSON when people often need to open and edit the data by hand.
Fields can change over time. An Avro reader can use the old writer schema and a newer reader schema together when the changes are compatible. For example, a new reader field can have a default to use when an old record lacks that field. Our Avro to JSON tool reads the schema stored in the file.
How do I convert it?
In Avro to JSON, open the sample .avro file and select Convert to JSON. The tool reads the embedded schema and shows the records as a JSON array.
In JSON to Avro, paste the contact records into JSON input and the schema into Avro schema. Select Convert to Avro and download the file. If you open that file in Avro to JSON, you should see both contacts again.
How is Avro different from Parquet?
Avro stores each record’s values together inside a block. That suits a job that reads one complete record after another. Parquet stores data by column, which helps a reporting tool read just the fields it needs.
If you are sending an address book to another service, Avro can carry each full contact and the rules for reading it. If you regularly run reports across many contacts and use just a few fields, Parquet may be a better fit. Check which formats the tools at both ends can read.
What should I check if conversion fails?
For a file you are opening, check that the exporter wrote an Avro object container file. Some services send individual Avro records with extra bytes at the start. This tool reads container files with uncompressed or deflate blocks.
When writing Avro, check the first record the error names. Make sure every required field is present, the names match the schema exactly, and whole numbers are supplied as numbers. Our converter reports unsupported schema features such as maps and logical types. Logical types give a stored value extra meaning, such as treating a number as a date.