yuzelin commented on code in PR #897:
URL: https://github.com/apache/incubator-paimon/pull/897#discussion_r1166358848


##########
paimon-format/src/main/java/org/apache/paimon/format/avro/RowDataToAvroConverters.java:
##########
@@ -146,6 +147,21 @@ public Object convert(Schema schema, Object object) {
                             }
                         };
                 break;
+            case TIMESTAMP_WITH_LOCAL_TIME_ZONE:
+                converter =
+                        new RowDataToAvroConverter() {
+                            private static final long serialVersionUID = 1L;
+
+                            @Override
+                            public Object convert(Schema schema, Object 
object) {
+                                return ((Timestamp) object)
+                                        .toInstant()
+                                        .atZone(ZoneId.systemDefault())
+                                        .toInstant()
+                                        .toEpochMilli();

Review Comment:
   I think for `LocalTimestampMillis` and `LocalTimestampMicros`, the returned 
long value is different. Here should check the precision.



##########
paimon-format/src/main/java/org/apache/paimon/format/avro/AvroSchemaConverter.java:
##########
@@ -110,6 +111,23 @@ public static Schema convertToSchema(DataType dataType, 
String rowName) {
                 }
                 Schema timestamp = 
avroLogicalType.addToSchema(SchemaBuilder.builder().longType());
                 return nullable ? nullableSchema(timestamp) : timestamp;
+            case TIMESTAMP_WITH_LOCAL_TIME_ZONE:
+                final LocalZonedTimestampType localTimestampType =
+                        (LocalZonedTimestampType) dataType;
+                precision = localTimestampType.getPrecision();
+                org.apache.avro.LogicalType localTimestampLogicalType;
+                if (precision <= 3) {
+                    localTimestampLogicalType = 
LogicalTypes.localTimestampMillis();
+                } else {
+                    throw new IllegalArgumentException(
+                            "Avro does not support TIMESTAMP type "
+                                    + "with precision: "
+                                    + precision
+                                    + ", it only supports precision less than 
3.");

Review Comment:
   I think Avro's `LocalTimestampMicros` is for precision 4-6.



##########
paimon-format/src/test/java/org/apache/paimon/format/avro/AvroBulkFormatTestUtils.java:
##########
@@ -35,8 +35,12 @@ public class AvroBulkFormatTestUtils {
             (RowType)
                     RowType.builder()
                             .fields(
-                                    new DataType[] {DataTypes.STRING(), 
DataTypes.STRING()},
-                                    new String[] {"a", "b"})
+                                    new DataType[] {
+                                        DataTypes.STRING(),
+                                        DataTypes.STRING(),
+                                        
DataTypes.TIMESTAMP_WITH_LOCAL_TIME_ZONE(3)

Review Comment:
   If take `localTimestampMicros` into consideration, it's better to add a test 
for > 3.



-- 
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: issues-unsubscr...@paimon.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to