Best way to represent a UUID in Avro?
Here's how I've been doing it:
{
"name": "user_id",
"type": "string",
"logicalType": "UUID"
}
At the time of writing the logicalType
for UUIDs is not documented but it is nonetheless supported, you can check the code here and verify so yourself: https://github.com/apache/avro/blob/branch-1.8/lang/java/avro/src/main/java/org/apache/avro/LogicalTypes.java#L71
And here the docs: https://avro.apache.org/docs/1.10.0/spec.html#UUID
So far, the only way I found is defining a custom UUID:
{
"namespace" : "your.namespace",
"type" : "fixed",
"name" : "UUID",
"size" : 16
}
I'm using Scala, so I also defined an implicit conversion between java.util.UUID
and my custom UUID, so it's not that much of a hassle to use it.