LsomeYeah commented on code in PR #5546:
URL: https://github.com/apache/paimon/pull/5546#discussion_r2062991904


##########
paimon-core/src/main/java/org/apache/paimon/deletionvectors/DeletionVector.java:
##########
@@ -98,40 +100,55 @@ default boolean checkedDelete(long position) {
      * @param bytes The byte array containing the serialized deletion vector.
      * @return A DeletionVector instance that represents the deserialized data.
      */
-    static DeletionVector deserializeFromBytes(byte[] bytes) {
-        try {
-            ByteBuffer buffer = ByteBuffer.wrap(bytes);
-            int magicNum = buffer.getInt();
-            if (magicNum == BitmapDeletionVector.MAGIC_NUMBER) {
-                return BitmapDeletionVector.deserializeFromByteBuffer(buffer);
-            } else {
-                throw new RuntimeException("Invalid magic number: " + 
magicNum);
-            }
-        } catch (IOException e) {
-            throw new RuntimeException("Unable to deserialize deletion 
vector", e);
+    static DeletionVector deserializeFromBytes(byte[] bytes, int version) {
+        if (version == BitmapDeletionVector.VERSION) {
+            return BitmapDeletionVector.deserializeFromBytes(bytes);
+        } else if (version == Bitmap64DeletionVector.VERSION) {
+            return Bitmap64DeletionVector.deserializeFromBytes(bytes);
+        } else {
+            throw new RuntimeException("Invalid deletion vector version: " + 
version);
         }
     }
 
     static DeletionVector read(FileIO fileIO, DeletionFile deletionFile) 
throws IOException {
         Path path = new Path(deletionFile.path());
         try (SeekableInputStream input = fileIO.newInputStream(path)) {
+            // read dv version
+            int version = input.read();
             input.seek(deletionFile.offset());
             DataInputStream dis = new DataInputStream(input);
-            int actualSize = dis.readInt();
-            if (actualSize != deletionFile.length()) {
+
+            if (version == BitmapDeletionVector.VERSION) {
+                // read v1 deletion vector
+                int actualSize = dis.readInt();
+                if (actualSize != deletionFile.length()) {
+                    throw new RuntimeException(
+                            "Size not match, actual size: "
+                                    + actualSize
+                                    + ", expected size: "
+                                    + deletionFile.length()
+                                    + ", file path: "
+                                    + path);
+                }
+
+                byte[] bytes = new byte[actualSize];
+                dis.readFully(bytes);
+                return BitmapDeletionVector.deserializeFromBytes(bytes);
+            } else if (version == Bitmap64DeletionVector.VERSION) {
+                // read v2 deletion vector
+                byte[] bytes = new byte[(int) deletionFile.length()];
+                dis.readFully(bytes);
+
+                return Bitmap64DeletionVector.deserializeFromBytes(bytes);

Review Comment:
   Serialized bytes of v2 dv include the 4 bytes for length, so it don't 
require to read the 4 bytes separately. Instead pass the entire byte array for 
deserialization.



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