avro-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tiago Lima (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (AVRO-1764) Allow YAML files as Map to be added in RecordSchema
Date Mon, 30 Nov 2015 22:20:11 GMT

     [ https://issues.apache.org/jira/browse/AVRO-1764?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Tiago Lima updated AVRO-1764:
-----------------------------
    Description: 
I did this little improvement to allow me to add annotations to generated files. 

So, if I want to add persistence's annotation to the generated files, I will have to add some
"javaAnnotations` in schema. This is a bad idea, because my client also will have these annotations.
Maybe I just have to create a *new layer* using the *Decorator Pattern* to add those annotations,
but I don't want this level of complexity in my application. I just want that my Avro Objects
have some custom annotations.

Because of that, we should have the opportunity to add custom configuration to be accessed
via velocity template (record.vm). So, I added an attribute in RecordSchema (called metadata)
that read an YAML file, which has the same name of the Record, to be loaded as a Map. Now,
I just have to overwrite the record.vm from velocity to call metadata.

{code:title=record.vm|borderStyle=solid}
#set ($indexName = $schema.getMetadata().get('persistence').get('elasticsearch').get('indexName'))
#set ($type = $schema.getMetadata().get('persistence').get('elasticsearch').get('type'))
@Document(indexName = "$indexName", type = "$type")
{code}

This can also be used to add validations and any kind of behaviour to the Avro Object.

I just opened a PR that is just a preview of a solution.

Thanks.

  was:
I did this little improvement to allow me to add annotations to generated files. 

So, if I want to add persistence's annotation to the generated files, I will have to add some
"javaAnnotations` in schema. This is a bad idea, because my client also will have these annotations.
Maybe I just have to create a *new layer* using the *Decorator Pattern* to add those annotations,
but I don't want this level of complexity in my application. I just want that my Avro Objects
have some custom annotations.

Because of that, we should have the opportunity to add custom configuration to be accessed
via velocity template (record.vm). So, I added an attribute in RecordSchema (called metadata)
that read an YAML file, which has the same name of the Record, to be loaded as a Map. Now,
I just have to overwrite the record.vm from velocity to call metadata.

{code:title=record.vm|borderStyle=solid}
#set ($indexName = $schema.getMetadata().get('persistence').get('elasticsearch').get('indexName'))
#set ($type = $schema.getMetadata().get('persistence').get('elasticsearch').get('type'))
@Document(indexName = "$indexName", type = "$type")
{code}

This can also be used to add validations and any kind of behaviour to the Avro Object.


> Allow YAML files as Map to be added in RecordSchema
> ---------------------------------------------------
>
>                 Key: AVRO-1764
>                 URL: https://issues.apache.org/jira/browse/AVRO-1764
>             Project: Avro
>          Issue Type: Improvement
>          Components: java
>    Affects Versions: 1.9.0
>            Reporter: Tiago Lima
>
> I did this little improvement to allow me to add annotations to generated files. 
> So, if I want to add persistence's annotation to the generated files, I will have to
add some "javaAnnotations` in schema. This is a bad idea, because my client also will have
these annotations. Maybe I just have to create a *new layer* using the *Decorator Pattern*
to add those annotations, but I don't want this level of complexity in my application. I just
want that my Avro Objects have some custom annotations.
> Because of that, we should have the opportunity to add custom configuration to be accessed
via velocity template (record.vm). So, I added an attribute in RecordSchema (called metadata)
that read an YAML file, which has the same name of the Record, to be loaded as a Map. Now,
I just have to overwrite the record.vm from velocity to call metadata.
> {code:title=record.vm|borderStyle=solid}
> #set ($indexName = $schema.getMetadata().get('persistence').get('elasticsearch').get('indexName'))
> #set ($type = $schema.getMetadata().get('persistence').get('elasticsearch').get('type'))
> @Document(indexName = "$indexName", type = "$type")
> {code}
> This can also be used to add validations and any kind of behaviour to the Avro Object.
> I just opened a PR that is just a preview of a solution.
> Thanks.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message