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

managing logical type timestamp-millis #689

Merged
merged 3 commits into from
May 3, 2021
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
Binary file added src/.DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions src/main/java/org/akhq/controllers/TopicController.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.kafka.common.resource.ResourceType;
import org.codehaus.httpcache4j.uri.URIBuilder;
import org.reactivestreams.Publisher;
import org.akhq.models.Record;

import java.time.Instant;
import java.util.*;
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/org/akhq/utils/AvroToJsonSerializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
import java.io.IOException;
import java.math.BigDecimal;
import java.nio.ByteBuffer;
import java.time.temporal.ChronoUnit;

import java.time.Instant;
import java.time.LocalDate;

public class AvroToJsonSerializer {

Expand Down Expand Up @@ -42,6 +46,12 @@ protected void writeField(Object datum, Schema.Field f, Encoder out, Object stat
if (logicalType instanceof LogicalTypes.Decimal) {
value = convert(DECIMAL_CONVERSION, fieldSchema, logicalType, value);
}
if (logicalType instanceof LogicalTypes.TimestampMillis) { //to manage "logicalType": "timestamp-millis"
value= ChronoUnit.MICROS.between(Instant.EPOCH, (Instant)value);
}
if (logicalType instanceof LogicalTypes.Date) {
value= ((LocalDate)value).toEpochDay();
}
writeWithoutConversion(fieldSchema, value, out);
} else {
super.writeField(datum, f, out, state);
Expand All @@ -60,4 +70,3 @@ private Object convert(Conversion<?> conversion, Schema fieldSchema, LogicalType
}
}
}