RussellSpitzer opened a new issue, #6685:
URL: https://github.com/apache/iceberg/issues/6685
### Apache Iceberg version
None
### Query engine
None
### Please describe the bug 🐞
Fanout writer, and several other pieces of code. Use StructCopy to copy
partition data. The implementation accidentally copies Array references for
Fixed data types which will lead to errors when containers are re-used and a
Fixed type column is in use.
Discovered while reviewing #6680
The underlying issue PartitionData should be copied like
```java
case FIXED:
byte[] buffer = (byte[]) data[i];
copy[i] = Arrays.copyOf(buffer, buffer.length);
break;
```
but instead the StructCopy code always does this
```java
if (value instanceof StructLike) {
values[i] = copy((StructLike) value);
} else {
values[i] = value;
}
```
Here is a reproduction
```java
public void testCopyFixed() {
Types.StructType fixed =
Types.StructType.of(Types.NestedField.required(0, "fix",
Types.FixedType.ofLength(4)));
byte[] originalBytes = "2468".getBytes();
PartitionData p = new PartitionData(fixed);
p.set(0, originalBytes);
PartitionData pdCopy = p.copy();
StructLike sLcopy = StructCopy.copy(p);
Assert.assertArrayEquals(
pdCopy.get(0, ByteBuffer.class).array(),
sLcopy.get(0, ByteBuffer.class).array());
originalBytes[0] = '8';
Assert.assertArrayEquals(
pdCopy.get(0, ByteBuffer.class).array(),
"2468".getBytes()
);
// Fails because the sLCopy incorrectly refers to the originalBytes
object which was modified.
Assert.assertArrayEquals(
pdCopy.get(0, ByteBuffer.class).array(),
sLcopy.get(0, ByteBuffer.class).array());
}
```
--
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]