This is an automated email from the ASF dual-hosted git repository.
blue pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-iceberg.git
The following commit(s) were added to refs/heads/master by this push:
new 36631d1 Properly serialize key metadata in GenericDataFile (#172)
36631d1 is described below
commit 36631d14a3290a6a08375420e63e6982a9597567
Author: mccheah <[email protected]>
AuthorDate: Wed May 1 08:53:18 2019 -0700
Properly serialize key metadata in GenericDataFile (#172)
Required since ByteBuffer itself isn't serializable. Override Java
serialization to convert to byte array first before pushing to object streams.
---
.../java/org/apache/iceberg/GenericDataFile.java | 30 +++++++++++++++++++++-
1 file changed, 29 insertions(+), 1 deletion(-)
diff --git a/core/src/main/java/org/apache/iceberg/GenericDataFile.java
b/core/src/main/java/org/apache/iceberg/GenericDataFile.java
index b0b9299..5341a46 100644
--- a/core/src/main/java/org/apache/iceberg/GenericDataFile.java
+++ b/core/src/main/java/org/apache/iceberg/GenericDataFile.java
@@ -22,6 +22,9 @@ package org.apache.iceberg;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.nio.ByteBuffer;
import java.util.List;
@@ -61,7 +64,7 @@ class GenericDataFile
private Map<Integer, Long> nullValueCounts = null;
private Map<Integer, ByteBuffer> lowerBounds = null;
private Map<Integer, ByteBuffer> upperBounds = null;
- private ByteBuffer keyMetadata = null;
+ private transient ByteBuffer keyMetadata = null;
// cached schema
private transient org.apache.avro.Schema avroSchema = null;
@@ -439,4 +442,29 @@ class GenericDataFile
}
return null;
}
+
+ private void writeObject(ObjectOutputStream output) throws IOException {
+ output.defaultWriteObject();
+ if (keyMetadata != null) {
+ output.writeBoolean(true);
+ byte[] keyMetadataArray = ByteBuffers.toByteArray(keyMetadata);
+ output.writeInt(keyMetadataArray.length);
+ output.write(keyMetadataArray);
+ } else {
+ output.writeBoolean(false);
+ }
+ }
+
+ private void readObject(ObjectInputStream input) throws IOException,
ClassNotFoundException {
+ input.defaultReadObject();
+ boolean hasKeyMetadata = input.readBoolean();
+ if (hasKeyMetadata) {
+ int keyMetadataLength = input.readInt();
+ byte[] keyMetadataArray = new byte[keyMetadataLength];
+ input.read(keyMetadataArray);
+ this.keyMetadata = ByteBuffer.wrap(keyMetadataArray);
+ } else {
+ this.keyMetadata = null;
+ }
+ }
}