You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@avro.apache.org by Gustavo Monarin <gu...@gmail.com> on 2023/10/11 15:24:34 UTC

Metadata / Annotations support

Sometimes is usefull to give a contextual information to a field.

Other protocols like protobuf support annotations through what they call
Option <https://protobuf.dev/programming-guides/proto3/#customoptions>
which allows the following customization (uuid field annotation):


```
message FarmerRegisteredEvent {

  string uuid = 1[(pi2schema.subject_identifier) = true];

  oneof personalData {
    ContactInfo contactInfo = 2;
    pi2schema.EncryptedPersonalData encryptedPersonalData = 6;
  }

  google.protobuf.Timestamp registeredAt = 4;
  string referrer = 5;

}
```


Would it be possible to add such metadata information in an avro schema?
----
Gustavo Monarin de Sousa

Re: Metadata / Annotations support

Posted by Oscar Westra van Holthe - Kind <os...@westravanholthe.nl>.
On wed 11 okt. 2023 17:24, Gustavo Monarin <gu...@gmail.com> wrote:

> Sometimes is usefull to give a contextual information to a field.
>
> Other protocols like protobuf support annotations through what they call
> Option <https://protobuf.dev/programming-guides/proto3/#customoptions>
> which allows the following customization (uuid field annotation):
>
>
> ```
> message FarmerRegisteredEvent {
>
>   string uuid = 1[(pi2schema.subject_identifier) = true];
>
>   oneof personalData {
>     ContactInfo contactInfo = 2;
>     pi2schema.EncryptedPersonalData encryptedPersonalData = 6;
>   }
>
>   google.protobuf.Timestamp registeredAt = 4;
>   string referrer = 5;
>
> }
> ```
>
> Would it be possible to add such metadata information in an avro schema?
>
Yes. On schemata, fields and messages, you an add any property other than
the standard ones (like 'name', 'doc', etc.) with any json value as value.

As far as Avro is concerned these are ignored, but you can use them in your
code.

Sometimes you want more though, and for that there are logical types and
(for Java code generation) the 'javaAnnotation' property.

Kind regards,
Oscar

-- 
Oscar Westra van Holthe - Kind <os...@westravanholthe.nl>