zhoulii commented on code in PR #7812:
URL: https://github.com/apache/paimon/pull/7812#discussion_r3240531721
##########
paimon-common/src/main/java/org/apache/paimon/globalindex/btree/BTreeIndexMeta.java:
##########
@@ -70,27 +87,59 @@ public byte[] serialize() {
sliceOutput.writeInt(firstKey.length);
sliceOutput.writeBytes(firstKey);
} else {
- sliceOutput.writeInt(0);
+ // -1 represents null in V1 format
+ sliceOutput.writeInt(-1);
}
if (lastKey != null) {
sliceOutput.writeInt(lastKey.length);
sliceOutput.writeBytes(lastKey);
} else {
- sliceOutput.writeInt(0);
+ // -1 represents null in V1 format
+ sliceOutput.writeInt(-1);
}
sliceOutput.writeByte(hasNulls ? 1 : 0);
+ // Append version byte at the end. Must be >= 2 to distinguish from
V0's hasNulls (0 or 1).
+ sliceOutput.writeByte(VERSION);
return sliceOutput.toSlice().getHeapMemory();
}
public static BTreeIndexMeta deserialize(byte[] data) {
- MemorySliceInput sliceInput = MemorySlice.wrap(data).toInput();
- int firstKeyLength = sliceInput.readInt();
- byte[] firstKey =
- firstKeyLength == 0 ? null :
sliceInput.readSlice(firstKeyLength).copyBytes();
- int lastKeyLength = sliceInput.readInt();
- byte[] lastKey =
- lastKeyLength == 0 ? null :
sliceInput.readSlice(lastKeyLength).copyBytes();
- boolean hasNulls = sliceInput.readByte() == 1;
- return new BTreeIndexMeta(firstKey, lastKey, hasNulls);
+ // Detect format version by reading the last byte.
+ // V0 format ends with hasNulls (0 or 1), V1 format ends with VERSION
(>= 2).
+ byte lastByte = data[data.length - 1];
+
+ if (lastByte >= VERSION) {
Review Comment:
Comments addressed. Thanks!
--
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]