Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions core/src/main/java/org/apache/iceberg/DeletionVectorStruct.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package org.apache.iceberg;

import java.io.Serializable;
import java.util.Objects;
import org.apache.iceberg.avro.SupportsIndexProjection;
import org.apache.iceberg.relocated.com.google.common.base.MoreObjects;
import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
Expand Down Expand Up @@ -129,26 +128,6 @@ static Builder builder() {
return new Builder();
}

@Override
public boolean equals(Object other) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No comment documents the intended equality contract after this change. Equality is now identity-based, and the safety of that choice rests on the invariant that no caller puts DeletionVectorStruct in a Set/Map key or calls .equals() for value comparison. As key_metadata (#17438) and further V4 fields land, a future reader writing dedup/caching code could reasonably assume value equality is in place. A single class-level sentence; e.g. "Equality and hash code are identity-based; DeletionVectorStruct is a projection-backed view, not a value type" would protect this invariant. This is the same documentation gap present in none of the sibling structs (TrackedFileStruct etc.), so adding it here sets a useful precedent for the whole V4 family.

if (this == other) {
return true;
} else if (!(other instanceof DeletionVectorStruct)) {
return false;
}

DeletionVectorStruct that = (DeletionVectorStruct) other;
return Objects.equals(location, that.location)
&& offset == that.offset
&& sizeInBytes == that.sizeInBytes
&& cardinality == that.cardinality;
}

@Override
public int hashCode() {
return Objects.hash(location, offset, sizeInBytes, cardinality);
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,64 +163,6 @@ void builderMissingRequiredFields() {
.hasMessage("Missing required value: cardinality");
}

@Test
void dvEquality() {
DeletionVectorStruct dv =
DeletionVectorStruct.builder()
.location("s3://bucket/data/dv.puffin")
.offset(256L)
.sizeInBytes(128L)
.cardinality(42L)
.build();

DeletionVectorStruct sameDv =
DeletionVectorStruct.builder()
.location("s3://bucket/data/dv.puffin")
.offset(256L)
.sizeInBytes(128L)
.cardinality(42L)
.build();

DeletionVectorStruct dvWithDifferentLocation =
DeletionVectorStruct.builder()
.location("s3://bucket/data/dv2.puffin")
.offset(256L)
.sizeInBytes(128L)
.cardinality(42L)
.build();

DeletionVectorStruct dvWithDifferentOffset =
DeletionVectorStruct.builder()
.location("s3://bucket/data/dv.puffin")
.offset(1L)
.sizeInBytes(128L)
.cardinality(42L)
.build();

DeletionVectorStruct dvWithDifferentSize =
DeletionVectorStruct.builder()
.location("s3://bucket/data/dv.puffin")
.offset(256L)
.sizeInBytes(8L)
.cardinality(42L)
.build();

DeletionVectorStruct dvWithDifferentCardinality =
DeletionVectorStruct.builder()
.location("s3://bucket/data/dv.puffin")
.offset(256L)
.sizeInBytes(128L)
.cardinality(2L)
.build();

assertThat(dv).isEqualTo(dv);
assertThat(dv).isEqualTo(sameDv);
assertThat(dv).isNotEqualTo(dvWithDifferentLocation);
assertThat(dv).isNotEqualTo(dvWithDifferentOffset);
assertThat(dv).isNotEqualTo(dvWithDifferentSize);
assertThat(dv).isNotEqualTo(dvWithDifferentCardinality);
}

@Test
void builderRejectsInvalidValuesAtSetter() {
assertThatThrownBy(() -> DeletionVectorStruct.builder().location(null))
Expand Down
Loading