Uploaded image for project: 'Apache Avro'
  1. Apache Avro
  2. AVRO-3014

logicalType annotation doesnt seem to work when generating java class from schema

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 1.9.0, 1.10.0
    • 1.10.2
    • java, logical types, tools
    • None

    Description

      I have a simple avro schema as follows:

       {
        "type": "record",
        "name": "OfferUnderwritingDetailsEvent",
        "namespace": "com.ferozed.avro",
        "fields": [
          {
          "name": "offerRequestId",
          "type": "string"
          },
          {
          "name": "modifiedTimestamp",
          "type": "long",
          "logicalType": "date"
          }
        ]
      }

       

      I use `avro-tools-1.9.0` to generate Java class from it:

      java -jar ~/DevTools/avro-tools-1.9.0.jar compile -dateTimeLogicalTypeImpl joda schema logicalType.avsc . 

       

      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.

          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;
          } 

       

      When using 1.10.0 version of avro-tools, I dont even see the `dateTimeLogicalTypeImpl` option.

      $ 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 
      
      
      

       

      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.

      Attachments

        1. logicalType.avsc
          0.3 kB
          Feroze Daud
        2. OfferUnderwritingDetailsEvent.java
          13 kB
          Feroze Daud

        Issue Links

          Activity

            People

              rskraba Ryan Skraba
              ferozedaud Feroze Daud
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: