emkornfield commented on code in PR #3680:
URL: https://github.com/apache/parquet-java/pull/3680#discussion_r3633402490


##########
parquet-column/src/main/java/org/apache/parquet/schema/PrimitiveComparator.java:
##########
@@ -278,6 +278,47 @@ public String toString() {
     }
   };
 
+  /**
+   * Comparator for timestamps encoded as 12-byte little-endian 
two's-complement values.
+   */
+  static final PrimitiveComparator<Binary> 
BINARY_AS_SIGNED_TIMESTAMP_COMPARATOR = new BinaryComparator() {
+    @Override
+    int compareBinary(Binary b1, Binary b2) {
+      if (b1.length() != 12 || b2.length() != 12) {
+        throw new IllegalArgumentException(
+            "Timestamp binary length must be 12 bytes, got " + b1.length() + " 
and " + b2.length());
+      }
+
+      ByteBuffer bb1 = b1.toByteBuffer();
+      ByteBuffer bb2 = b2.toByteBuffer();
+      // The buffers may be slices with a non-zero position (e.g. a 
ByteBuffer-backed Binary), so
+      // index relative to position() rather than absolute offset 0. Byte 11 
(position + 11) is the
+      // most significant byte and carries the sign; byte 0 (position) is 
least significant.
+      int p1 = bb1.position();
+      int p2 = bb2.position();
+
+      // If one value is negative and the other is positive, one is trivially 
greater.
+      boolean neg1 = bb1.get(p1 + 11) < 0;
+      boolean neg2 = bb2.get(p2 + 11) < 0;
+      if (neg1 != neg2) {
+        return neg1 ? -1 : 1;
+      }
+
+      for (int i = 11; i >= 0; --i) {

Review Comment:
   Can this be done more efficiently by retrieving int/long values from the 
underlying type and comparing those?



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