fbocse commented on a change in pull request #1430:
URL: https://github.com/apache/iceberg/pull/1430#discussion_r485729659
##########
File path: api/src/main/java/org/apache/iceberg/Metrics.java
##########
@@ -120,4 +124,90 @@ public Long recordCount() {
public Map<Integer, ByteBuffer> upperBounds() {
return upperBounds;
}
+
+ /**
+ * Implemented the method to enable serialization of ByteBuffers.
+ * @param out The stream where to write
+ * @throws IOException On serialization error
+ */
+ private void writeObject(ObjectOutputStream out) throws IOException {
+ out.writeObject(rowCount);
+ out.writeObject(columnSizes);
+ out.writeObject(valueCounts);
+ out.writeObject(nullValueCounts);
+
+ writeByteBufferMap(out, lowerBounds);
+ writeByteBufferMap(out, upperBounds);
+ }
+
+ private static void writeByteBufferMap(ObjectOutputStream out, Map<Integer,
ByteBuffer> byteBufferMap)
+ throws IOException {
+ if (byteBufferMap == null) {
+ out.writeInt(-1);
+
+ } else {
+ // Write the size
+ out.writeInt(byteBufferMap.size());
+
+ for (Map.Entry<Integer, ByteBuffer> entry : byteBufferMap.entrySet()) {
+ // Write the key
+ out.writeObject(entry.getKey());
+
+ // Write the value
+ if (entry.getValue() != null) {
+ // Copy the actual values from the buffer
+ ByteBuffer bb = entry.getValue();
+ byte[] bytes = new byte[bb.remaining()];
+ bb.get(bytes);
+ bb.position(bb.position() - bytes.length); // Restores the buffer
position
+
+ // Write out the data
+ out.writeObject(bytes);
+ } else {
+ out.writeObject(null);
+ }
+ }
+ }
+ }
+
+ /**
+ * Implemented the method to enable deserialization of ByteBuffers.
+ * @param in The stream to read from
+ * @throws IOException On serialization error
+ * @throws ClassNotFoundException If the class is not found
+ */
+ private void readObject(ObjectInputStream in) throws IOException,
ClassNotFoundException {
+ rowCount = (Long) in.readObject();
+ columnSizes = (Map<Integer, Long>) in.readObject();
+ valueCounts = (Map<Integer, Long>) in.readObject();
+ nullValueCounts = (Map<Integer, Long>) in.readObject();
+
+ lowerBounds = readByteBufferMap(in);
+ upperBounds = readByteBufferMap(in);
+ }
+
+ private static Map<Integer, ByteBuffer> readByteBufferMap(ObjectInputStream
in)
+ throws IOException, ClassNotFoundException {
+ int size = in.readInt();
+
+ if (size == -1) {
+ return null;
+
+ } else {
+ Map<Integer, ByteBuffer> result = Maps.newHashMap();
Review comment:
Seems like we can probably just get away with a simple `new
java.util.HashMap()`, no need for guava as a dependency for this class.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]