divjotarora commented on code in PR #3680:
URL: https://github.com/apache/parquet-java/pull/3680#discussion_r3638131069
##########
parquet-column/src/main/java/org/apache/parquet/schema/Types.java:
##########
@@ -563,6 +563,9 @@ public Optional<Boolean> visit(
@Override
public Optional<Boolean> visit(
LogicalTypeAnnotation.TimestampLogicalTypeAnnotation
timestampLogicalType) {
+ if (primitiveType == PrimitiveTypeName.FIXED_LEN_BYTE_ARRAY) {
+ return checkFixedPrimitiveType(12, timestampLogicalType);
+ }
return checkInt64PrimitiveType(timestampLogicalType);
Review Comment:
Nice catch, fixed to inline the `Preconditions` check against both INT64 and
FLBA(12) combined rather than using `checkInt64PrimitiveType`
##########
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:
Good idea, changed to signed comparison of higher 4 bytes and unsigned
comparison of lower 8 bytes
--
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]