Skip to content

Commit

Permalink
Core: Check referencedDataFile existence for DV (#12088)
Browse files Browse the repository at this point in the history
  • Loading branch information
ebyhr authored Jan 28, 2025
1 parent e1d2401 commit 491d906
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions core/src/main/java/org/apache/iceberg/FileMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ public DeleteFile build() {
if (format == FileFormat.PUFFIN) {
Preconditions.checkArgument(contentOffset != null, "Content offset is required for DV");
Preconditions.checkArgument(contentSizeInBytes != null, "Content size is required for DV");
Preconditions.checkArgument(
referencedDataFile != null, "Referenced data file is required for DV");
} else {
Preconditions.checkArgument(contentOffset == null, "Content offset can only be set for DV");
Preconditions.checkArgument(
Expand Down
26 changes: 26 additions & 0 deletions core/src/test/java/org/apache/iceberg/TestDeleteFiles.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.apache.iceberg.relocated.com.google.common.collect.Lists;
import org.apache.iceberg.types.Types;
import org.apache.iceberg.util.StructLikeWrapper;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.api.extension.ExtendWith;

Expand Down Expand Up @@ -443,6 +444,31 @@ public void testDeleteFilesNoValidation() {
assertThat(delete2.removedDataFiles(FILE_IO)).isEmpty();
}

@Test
public void testRequiredFieldsForDV() {
FileMetadata.Builder builder =
FileMetadata.deleteFileBuilder(PartitionSpec.unpartitioned())
.ofPositionDeletes()
.withFormat(FileFormat.PUFFIN)
.withPath("/path/to/data-d-deletes.puffin")
.withFileSizeInBytes(4)
.withRecordCount(4);

assertThatThrownBy(builder::build)
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Content offset is required for DV");

builder.withContentOffset(1);
assertThatThrownBy(builder::build)
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Content size is required for DV");

builder.withContentSizeInBytes(10);
assertThatThrownBy(builder::build)
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Referenced data file is required for DV");
}

private static ByteBuffer longToBuffer(long value) {
return ByteBuffer.allocate(8).order(ByteOrder.LITTLE_ENDIAN).putLong(0, value);
}
Expand Down

0 comments on commit 491d906

Please sign in to comment.