pvary commented on code in PR #14245:
URL: https://github.com/apache/iceberg/pull/14245#discussion_r2611377924


##########
flink/v2.1/flink/src/main/java/org/apache/iceberg/flink/data/StructRowData.java:
##########
@@ -186,8 +186,31 @@ private BigDecimal getDecimalInternal(int pos) {
 
   @Override
   public TimestampData getTimestamp(int pos, int precision) {
-    long timeLong = getLong(pos);
-    return TimestampData.fromEpochMillis(timeLong / 1000, (int) (timeLong % 
1000) * 1000);
+    if (precision == 9) {
+      // Nanosecond precision: get nanoseconds directly from struct
+      Object longVal = struct.get(pos, Object.class);
+      long nanos;
+      if (longVal instanceof Long) {
+        nanos = (long) longVal;
+      } else if (longVal instanceof OffsetDateTime) {
+        nanos = Duration.between(Instant.EPOCH, (OffsetDateTime) 
longVal).toNanos();
+      } else if (longVal instanceof LocalDateTime) {
+        nanos =
+            Duration.between(Instant.EPOCH, ((LocalDateTime) 
longVal).atOffset(ZoneOffset.UTC))
+                .toNanos();
+      } else {

Review Comment:
   We do it here:
   
https://github.com/apache/iceberg/blob/23dc32e5f1130c9d79d71cbf0be5b85162d8976c/flink/v2.1/flink/src/main/java/org/apache/iceberg/flink/data/StructRowData.java#L188-L191
   
   And this is the code behind:
   
https://github.com/apache/iceberg/blob/23dc32e5f1130c9d79d71cbf0be5b85162d8976c/flink/v2.1/flink/src/main/java/org/apache/iceberg/flink/data/StructRowData.java#L142-L145
   
   TBH, the `LocalDate` and the `LocalTime` handling doesn't seem correct to me.
   
   We might want to skip this for now, and might fix this later on in a 
separate PR



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