hsingh574 commented on code in PR #12855:
URL: https://github.com/apache/iceberg/pull/12855#discussion_r2064954317
##########
core/src/main/java/org/apache/iceberg/data/GenericRecord.java:
##########
@@ -65,13 +68,36 @@ private GenericRecord(StructType struct) {
this.nameToPos = NAME_MAP_CACHE.get(struct);
}
- private GenericRecord(GenericRecord toCopy) {
+ private GenericRecord(GenericRecord toCopy, boolean deepCopyValues) {
this.struct = toCopy.struct;
this.size = toCopy.size;
- this.values = Arrays.copyOf(toCopy.values, toCopy.values.length);
+ if (deepCopyValues) {
+ this.values = new Object[toCopy.values.length];
+ for (int i = 0; i < toCopy.values.length; i++) {
+ this.values[i] = deepCopyValue(this.struct.fields().get(i).type(),
toCopy.values[i]);
+ }
+ } else {
+ this.values = Arrays.copyOf(toCopy.values, toCopy.values.length);
+ }
this.nameToPos = toCopy.nameToPos;
}
+ private Object deepCopyValue(Type type, Object value) {
Review Comment:
I added a unit test for struct which fails without this change. Map and list
look to have the same problem because they’re also relying on the reused
container (at least in the Parquet impl I checked), but had some trouble unit
testing them.
Happy to scope the change to ByteBuffer for now, but I do think the issue is
broader.
--
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]