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


##########
flink/v2.1/flink/src/main/java/org/apache/iceberg/flink/data/StructRowData.java:
##########
@@ -186,8 +186,34 @@ 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);
+    Object timestampVal = struct.get(pos, Object.class);
+
+    // Convert all timestamp types to nanoseconds (smallest unit)
+    long nanos;
+    if (timestampVal instanceof Long) {
+      // Long values: nanoseconds for timestamp_ns (precision 9), microseconds 
otherwise
+      nanos = precision == 9 ? (Long) timestampVal : ((Long) timestampVal) * 
1000;
+    } else if (timestampVal instanceof OffsetDateTime) {
+      nanos = Duration.between(Instant.EPOCH, (OffsetDateTime) 
timestampVal).toNanos();
+    } else if (timestampVal instanceof LocalDateTime) {
+      nanos =
+          Duration.between(Instant.EPOCH, ((LocalDateTime) 
timestampVal).atOffset(ZoneOffset.UTC))
+              .toNanos();
+    } else {

Review Comment:
   Is it intentional that we left out `LocalDate` and `LocalTime`? - They were 
implemented in the `getLong` method



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