JingsongLi commented on code in PR #1171:
URL: https://github.com/apache/incubator-paimon/pull/1171#discussion_r1198671163
##########
paimon-format/src/main/java/org/apache/paimon/format/avro/RowDataToAvroConverters.java:
##########
@@ -142,7 +145,48 @@ public Object convert(Schema schema, Object object) {
@Override
public Object convert(Schema schema, Object
object) {
- return ((Timestamp)
object).toInstant().toEpochMilli();
+ LogicalType logicalType =
schema.getLogicalType();
+
+ if (logicalType instanceof
LogicalTypes.TimestampMillis) {
+ return ((Timestamp)
object).toInstant().toEpochMilli();
+ } else if (logicalType instanceof
LogicalTypes.TimestampMicros) {
+ return ((Timestamp)
object).toInstant().toEpochMilli() * 1000
+ + ((Timestamp)
object).getNanoOfMillisecond() / 1000;
+ } else {
+ throw new UnsupportedOperationException(
+ "Unsupported timestamp type: " +
logicalType);
+ }
+ }
+ };
+ break;
+ case TIMESTAMP_WITH_LOCAL_TIME_ZONE:
+ converter =
+ new RowDataToAvroConverter() {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public Object convert(Schema schema, Object
object) {
+ LogicalType logicalType =
schema.getLogicalType();
+
+ if (logicalType instanceof
LogicalTypes.LocalTimestampMillis) {
+ return ((Timestamp) object)
+ .toInstant()
+ .atZone(ZoneId.systemDefault())
Review Comment:
Can we just store mills instead time zone conversion?
Because `Timestamp` class already is an epoch mills now.
In this way, Timestamp with local time zone and without time zone can have
same converters.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]