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

Ryan Skraba resolved AVRO-3014.
-------------------------------
    Resolution: Fixed

Note that this fix only prints a log line, to give a hint why the logical type 
wasn't taken into account.  The right solution is to ensure that the logical 
type annotates the schema, not the field.

> logicalType annotation doesnt seem to work when generating java class from 
> schema
> ---------------------------------------------------------------------------------
>
>                 Key: AVRO-3014
>                 URL: https://issues.apache.org/jira/browse/AVRO-3014
>             Project: Apache Avro
>          Issue Type: Bug
>          Components: java, logical types, tools
>    Affects Versions: 1.9.0, 1.10.0
>            Reporter: Feroze Daud
>            Assignee: Ryan Skraba
>            Priority: Minor
>             Fix For: 1.10.2
>
>         Attachments: OfferUnderwritingDetailsEvent.java, logicalType.avsc
>
>
> I have a simple avro schema as follows:
> {noformat}
>  {
>   "type": "record",
>   "name": "OfferUnderwritingDetailsEvent",
>   "namespace": "com.ferozed.avro",
>   "fields": [
>     {
>     "name": "offerRequestId",
>     "type": "string"
>     },
>     {
>     "name": "modifiedTimestamp",
>     "type": "long",
>     "logicalType": "date"
>     }
>   ]
> }{noformat}
>  
> I use `avro-tools-1.9.0` to generate Java class from it:
> {noformat}
> java -jar ~/DevTools/avro-tools-1.9.0.jar compile -dateTimeLogicalTypeImpl 
> joda schema logicalType.avsc . {noformat}
>  
> When I look at the generated object, the type of the `setModifiedTimestamp` 
> settor is still `int`. I would have expected `joda.time.Date` or something 
> similar.
> {noformat}
>     public long getModifiedTimestamp() {
>       return modifiedTimestamp;
>     }
>     public com.ferozed.avro.OfferUnderwritingDetailsEvent.Builder 
> setModifiedTimestamp(long value) {
>       validate(fields()[1], value);
>       this.modifiedTimestamp = value;
>       fieldSetFlags()[1] = true;
>       return this;
>     } {noformat}
>  
> When using 1.10.0 version of avro-tools, I dont even see the 
> `dateTimeLogicalTypeImpl` option.
> {noformat}
> $ java -jar ~/DevTools/avro-tools-1.10.0.jar compile
> Usage: [-encoding <outputencoding>] [-string] [-bigDecimal] [-fieldVisibility 
> <visibilityType>] [-templateDir <templateDir>] (schema|protocol) input... 
> outputdir
>  input - input files or directories
>  outputdir - directory to write generated java
>  -encoding <outputencoding> - set the encoding of output file(s)
>  -string - use java.lang.String instead of Utf8
>  -fieldVisibility [private|public|public_deprecated]- use either and default 
> private
>  -bigDecimal - use java.math.BigDecimal for decimal type instead of 
> java.nio.ByteBuffer
>  -templateDir - directory with custom Velocity templates 
> {noformat}
>  
> And generating a java class using this schema generates the same object as 
> the 1.9.0 toolset.
> I also tried using `logicalType` with an `int` field, and it doesnt work.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to