Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top