Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix][client] Fix conversion of TimestampMillisConversion has no effect when Jsr310Conversion enabled #15863

Merged
merged 1 commit into from
Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ public static void addLogicalTypeConversions(ReflectData reflectData, boolean js
reflectData.addLogicalTypeConversion(new TimeConversions.DateConversion());
reflectData.addLogicalTypeConversion(new TimeConversions.TimeMillisConversion());
reflectData.addLogicalTypeConversion(new TimeConversions.TimeMicrosConversion());
reflectData.addLogicalTypeConversion(new TimeConversions.TimestampMicrosConversion());
if (jsr310ConversionEnabled) {
// The conversion that is registered first is higher priority than the registered later.
reflectData.addLogicalTypeConversion(new TimeConversions.TimestampMillisConversion());
} else {
try {
Expand All @@ -125,6 +125,7 @@ public static void addLogicalTypeConversions(ReflectData reflectData, boolean js
} catch (ClassNotFoundException e) {
// Skip if have not provide joda-time dependency.
}
reflectData.addLogicalTypeConversion(new TimeConversions.TimestampMicrosConversion());
}
reflectData.addLogicalTypeConversion(new Conversions.UUIDConversion());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.apache.avro.SchemaValidationException;
import org.apache.avro.SchemaValidator;
import org.apache.avro.SchemaValidatorBuilder;
import org.apache.avro.data.TimeConversions;
import org.apache.avro.io.BinaryEncoder;
import org.apache.avro.io.BufferedBinaryEncoder;
import org.apache.avro.reflect.AvroDefault;
Expand Down Expand Up @@ -459,4 +460,24 @@ public void testAvroBigDecimal() {
assertEquals(pojo2.value1, myBigDecimalPojo.value1);
assertEquals(pojo2.value2, myBigDecimalPojo.value2);
}


@Data
private static class TimestampStruct {
Instant value;
}

@Test
public void testTimestampWithJsr310Conversion() {
AvroSchema<TimestampStruct> schema = AvroSchema.of(TimestampStruct.class);
Assert.assertEquals(
schema.getAvroSchema().getFields().get(0).schema().getTypes().get(1).getLogicalType().getName(),
new TimeConversions.TimestampMicrosConversion().getLogicalTypeName());

AvroSchema<TimestampStruct> schema2 = AvroSchema.of(SchemaDefinition.<TimestampStruct>builder()
.withPojo(TimestampStruct.class).withJSR310ConversionEnabled(true).build());
Assert.assertEquals(
schema2.getAvroSchema().getFields().get(0).schema().getTypes().get(1).getLogicalType().getName(),
new TimeConversions.TimestampMillisConversion().getLogicalTypeName());
}
}