You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Jörn Gersdorf (Jira)" <ji...@apache.org> on 2019/08/29 13:08:00 UTC
[jira] [Commented] (AVRO-2471) Java maven plugin code generation
doesn't add conversion for timestamp-micros
[ https://issues.apache.org/jira/browse/AVRO-2471?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16918600#comment-16918600 ]
Jörn Gersdorf commented on AVRO-2471:
-------------------------------------
We face the same issue. The reason seems to be caused by the following issue:
First, https://github.com/apache/avro/blob/master/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java#L114 registers two Conversions {{(Instant, "timestamp-millis")}} and {{(Instant, "timestamp-micros")}} for the same java type {{Instant}} and two different logical types {{"timestamp-millis"}} resp. {{"timestamp-micros"}}.
Second, in [SpecificCompiler#getUsedConversionClasses|https://github.com/apache/avro/blob/master/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java#L324] the list of available Conversion-Pairs {{(java-type, logical-type)}} is grouped by {{java-type}}, therefore the last conversions winning, which is in this bug always the conversion {{(Instant, "timestamp-millis")}}.
Failing test case for reproduction available at https://github.com/j0xaf/avro-2471.
> Java maven plugin code generation doesn't add conversion for timestamp-micros
> -----------------------------------------------------------------------------
>
> Key: AVRO-2471
> URL: https://issues.apache.org/jira/browse/AVRO-2471
> Project: Apache Avro
> Issue Type: Bug
> Components: java
> Affects Versions: 1.9.0
> Reporter: Marek Tracz
> Priority: Major
>
> Field in schema: (there is no single field with timestamp-millis logical type)
> {code:java}
> {
> "name": "RECORDING_TIME",
> "type": [
> "null",
> {
> "type": "long",
> "logicalType": "timestamp-micros"
> }
> ],
> "default": null
> }
> {code}
> Maven plugin configuration:
> {code:xml}
> <plugin>
> <groupId>org.apache.avro</groupId>
> <artifactId>avro-maven-plugin</artifactId>
> <version>1.9.0</version>
> <executions>
> <execution>
> <goals>
> <goal>schema</goal>
> </goals>
> <configuration>
> <stringType>String</stringType>
> <enableDecimalLogicalType>true</enableDecimalLogicalType>
> <sourceDirectory>${project.basedir}/src/main/resources/</sourceDirectory>
> </configuration>
> </execution>
> </executions>
> </plugin>
> {code}
> Part of the generated class:
> {code:java}
> private static SpecificData MODEL$ = new SpecificData();
> static {
> MODEL$.addLogicalTypeConversion(new org.apache.avro.data.TimeConversions.DateConversion());
> MODEL$.addLogicalTypeConversion(new org.apache.avro.data.TimeConversions.TimestampMillisConversion()); // <--- this should be TimestampMicrosConversion
> MODEL$.addLogicalTypeConversion(new org.apache.avro.Conversions.DecimalConversion());
> }
> {code}
> For example this code:
> {code:java}
> Data data = Data.newBuilder()
> .setRECORDINGTIME(Instant.now())
> .build();
> {code}
> Fails during comparison:
> {noformat}
> org.apache.kafka.common.errors.SerializationException: Error serializing Avro message
> Caused by: org.apache.avro.AvroRuntimeException: Unknown datum type java.time.Instant: 2019-07-12T14:24:47.322Z
> at org.apache.avro.generic.GenericData.getSchemaName(GenericData.java:887)
> at org.apache.avro.specific.SpecificData.getSchemaName(SpecificData.java:420)
> at org.apache.avro.generic.GenericData.resolveUnion(GenericData.java:850)
> at org.apache.avro.generic.GenericDatumWriter.resolveUnion(GenericDatumWriter.java:249)
> at org.apache.avro.generic.GenericDatumWriter.writeWithoutConversion(GenericDatumWriter.java:142)
> at org.apache.avro.specific.SpecificDatumWriter.writeField(SpecificDatumWriter.java:98)
> at org.apache.avro.generic.GenericDatumWriter.writeRecord(GenericDatumWriter.java:195)
> at org.apache.avro.specific.SpecificDatumWriter.writeRecord(SpecificDatumWriter.java:83)
> at org.apache.avro.generic.GenericDatumWriter.writeWithoutConversion(GenericDatumWriter.java:130)
> at org.apache.avro.specific.SpecificDatumWriter.writeField(SpecificDatumWriter.java:98)
> at org.apache.avro.generic.GenericDatumWriter.writeRecord(GenericDatumWriter.java:195)
> at org.apache.avro.specific.SpecificDatumWriter.writeRecord(SpecificDatumWriter.java:83)
> at org.apache.avro.generic.GenericDatumWriter.writeWithoutConversion(GenericDatumWriter.java:130)
> at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:82)
> at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:72)
> at io.confluent.kafka.serializers.AbstractKafkaAvroSerializer.serializeImpl(AbstractKafkaAvroSerializer.java:92)
> at io.confluent.kafka.serializers.KafkaAvroSerializer.serialize(KafkaAvroSerializer.java:53)
> at org.apache.kafka.common.serialization.ExtendedSerializer$Wrapper.serialize(ExtendedSerializer.java:65)
> at org.apache.kafka.common.serialization.ExtendedSerializer$Wrapper.serialize(ExtendedSerializer.java:55)
> at org.apache.kafka.clients.producer.KafkaProducer.doSend(KafkaProducer.java:841)
> at org.apache.kafka.clients.producer.KafkaProducer.send(KafkaProducer.java:803)
> at org.apache.kafka.clients.producer.KafkaProducer.send(KafkaProducer.java:690)
> {noformat}
> When manually changed to *org.apache.avro.data.TimeConversions.TimestampMicrosConversion* everything works properly.
--
This message was sent by Atlassian Jira
(v8.3.2#803003)