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


##########
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 {
+        throw new IllegalStateException(
+            "Unknown type for nanosecond timestamp field. Type name: "
+                + longVal.getClass().getName());
+      }

Review Comment:
   nit: newline



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