hudi-agent commented on code in PR #18773:
URL: https://github.com/apache/hudi/pull/18773#discussion_r3262485936


##########
hudi-common/src/main/java/org/apache/hudi/avro/HoodieAvroUtils.java:
##########
@@ -700,6 +721,62 @@ public static Object 
convertValueForAvroLogicalTypes(Schema fieldSchema, Object
     return fieldValue;
   }
 
+  // The extract* helpers below accept either the Avro 1.11.x primitive form 
(Integer / Long) or the
+  // Avro 1.12 java.time form, and return the canonical primitive that Avro 
1.11.x would have produced
+  // for the same underlying bytes. See the javadoc on 
convertValueForAvroLogicalTypes for context.
+
+  private static long extractEpochDay(Object fieldValue) {
+    if (fieldValue instanceof LocalDate) {
+      return ((LocalDate) fieldValue).toEpochDay();
+    }
+    if (fieldValue instanceof Number) {
+      return ((Number) fieldValue).longValue();
+    }
+    return Long.parseLong(fieldValue.toString());
+  }
+
+  private static long extractEpochMillis(Object fieldValue) {
+    if (fieldValue instanceof Instant) {
+      return ((Instant) fieldValue).toEpochMilli();
+    }
+    if (fieldValue instanceof Number) {
+      return ((Number) fieldValue).longValue();
+    }
+    return Long.parseLong(fieldValue.toString());
+  }
+
+  private static long extractEpochMicros(Object fieldValue) {
+    if (fieldValue instanceof Instant) {
+      Instant instant = (Instant) fieldValue;
+      return Math.addExact(Math.multiplyExact(instant.getEpochSecond(), 
1_000_000L), instant.getNano() / 1000L);

Review Comment:
   πŸ€– nit: the `Instant`β†’epoch-micros formula 
(`Math.addExact(Math.multiplyExact(...))`) is identical in `extractEpochMicros` 
and `extractLocalEpochMicros` (line 772). Could you pull it into a small 
private `instantToEpochMicros(Instant)` helper so the arithmetic only lives in 
one place?
   
   <sub><i>- AI-generated; verify before applying. React πŸ‘/πŸ‘Ž to flag 
quality.</i></sub>



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

Reply via email to