RussellSpitzer commented on code in PR #17196:
URL: https://github.com/apache/iceberg/pull/17196#discussion_r3590712355


##########
core/src/main/java/org/apache/iceberg/avro/SchemaToType.java:
##########
@@ -193,19 +196,30 @@ public Type logicalType(Schema primitive, LogicalType 
logical) {
 
     } else if (logical instanceof LogicalTypes.TimestampMillis
         || logical instanceof LogicalTypes.TimestampMicros) {
-      if (AvroSchemaUtil.isTimestamptz(primitive)) {
+      if (AvroSchemaUtil.isTimestamptz(primitive, legacyTimestampMapping)) {
         return Types.TimestampType.withZone();
       } else {
         return Types.TimestampType.withoutZone();
       }
 
     } else if (logical instanceof LogicalTypes.TimestampNanos) {
-      if (AvroSchemaUtil.isTimestamptz(primitive)) {
+      if (AvroSchemaUtil.isTimestamptz(primitive, legacyTimestampMapping)) {
         return Types.TimestampNanoType.withZone();
       } else {
         return Types.TimestampNanoType.withoutZone();
       }
 
+    } else if (logical instanceof LogicalTypes.LocalTimestampMillis

Review Comment:
   These branches will fall through and return null if legacyTimeMapping is 
true. I think the assumption was that the reader is assuming legacy status of 
the writer, but i'm not sure you can do that. For example if my writer is set 
to "non-legacy" but my reader is set to "legacy" then it will break.
   
   Consider the following test which would currently fail
   ```java
   @Test
   public void testLocalTimestampWithLegacyMapping() {
       Schema localTsMicros =
           
LogicalTypes.localTimestampMicros().addToSchema(Schema.create(Schema.Type.LONG));
       Schema localTsNanos =
           
LogicalTypes.localTimestampNanos().addToSchema(Schema.create(Schema.Type.LONG));
   
       // local-timestamp-* types are semantically unambiguous — always no 
timezone.
       // legacyTimestampMapping should have no effect on them.
       assertThat(AvroSchemaUtil.convert(localTsMicros))
           .isEqualTo(Types.TimestampType.withoutZone());
       assertThat(AvroSchemaUtil.convert(localTsNanos))
           .isEqualTo(Types.TimestampNanoType.withoutZone());
   }
   ```
   
   I Think this is fixed by just dropping the condition here (if !legacy)



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to