Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between a map and a record in avro?

I'm using Apache Avro for a project, but I can't seem to make sense of what it calls maps. I haven't been able to find any examples of maps in use, and the example on the spec is pretty bare:

Maps

Maps use the type name "map" and support one attribute:

  • values: the schema of the map's values.

Map keys are assumed to be strings.

For example, a map from string to long is declared with:

{"type": "map", "values": "long"}

What might data that fits that schema look like as JSON? What use does a map have that a record doesn't do better?

like image 822
kojiro Avatar asked Jan 19 '26 23:01

kojiro


1 Answers

My understanding is that difference is pretty similar to how Java deals with POJOs with named properties compared to java.util.Map. That is, names of entries in a Map are arbitrary, dynamic; but data types are all of same type (which however can be java.lang.Object to indicate any type).

That is, Maps are more versatile with respect to entries, but use up more storage space and are slower to process than POJOs (because of by-name lookups, compared to direct indexing of fields).

Avro itself is rather strongly typed, because of needing Schemas, which perhaps makes use of Maps less appealing than with more dynamic formats like JSON.

like image 195
StaxMan Avatar answered Jan 22 '26 15:01

StaxMan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!