You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Ryan Skraba (Jira)" <ji...@apache.org> on 2020/09/23 14:38:00 UTC

[jira] [Commented] (AVRO-2930) avro-maven-plugin doesn't generate proper accessors for the logical type timestamp-millis

    [ https://issues.apache.org/jira/browse/AVRO-2930?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17200862#comment-17200862 ] 

Ryan Skraba commented on AVRO-2930:
-----------------------------------

Hello!  The correct way to annotate a logical type on a record would be:

{code}
 {
    "name" : "server_time",
    "type" : {
      "type" : "long",
      "logicalType" : "timestamp-millis"
    }
  }
{code}

This is a consequence of distinguishing between metadata on a record *field*, or on a record *field type* -- the {{logicalType}} property should be on the type.

> avro-maven-plugin doesn't generate proper accessors for the logical type timestamp-millis
> -----------------------------------------------------------------------------------------
>
>                 Key: AVRO-2930
>                 URL: https://issues.apache.org/jira/browse/AVRO-2930
>             Project: Apache Avro
>          Issue Type: Bug
>          Components: java
>    Affects Versions: 1.10.0, 1.9.1, 1.9.2
>            Reporter: DiĆ³genes Oliveira
>            Priority: Major
>
> The relevant field in the schema is:
> {code:json}
> {
>   "name": "server_time",
>   "logicalType": "timestamp-millis",
>   "type": "long"
> }
> {code}
> The plugin section in the pom.xml is as follows:
> {code:xml}
> <plugin>
>     <groupId>org.apache.avro</groupId>
>     <artifactId>avro-maven-plugin</artifactId>
>     <version>${avro.version}</version>
>     <executions>
>         <execution>
>             <phase>generate-sources</phase>
>             <goals>
>                 <goal>schema</goal>
>             </goals>
>             <configuration>
>                 <sourceDirectory>${project.basedir}/src/main/resources/avro/</sourceDirectory>
>                 <outputDirectory>${project.basedir}/src/main/java/</outputDirectory>
>                 <stringType>String</stringType>
>             </configuration>
>         </execution>
>     </executions>
> </plugin>
> {code}
> The generated source does seem to recognize the existence of the conversion:
> {code:java}
>   private static SpecificData MODEL$ = new SpecificData();
> static {
>     MODEL$.addLogicalTypeConversion(new org.apache.avro.data.TimeConversions.TimestampMillisConversion());
>   }
> {code}
> But the getters and setters still refer to a Java Long instead of an Instant:
> {code:java}
>   public long getServerTime() {
>     return server_time;
>   }
>   public void setServerTime(long value) {
>     this.server_time = value;
>   }
> {code}



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