Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,17 @@ public void updateStats(Binary value) {
min = value.copy();
max = value.copy();
this.markAsNotEmpty();
} else {
if (comparator().compare(min, value) > 0) {
min = value.copy();
} else if (comparator().compare(max, value) < 0) {
max = value.copy();
}
return;
}
// copy() keeps the same instance when the backing bytes are not reused.
// Thus, a value can be the same instance as min or max. That value is equal to the bound, so do not compare it.
if (value == min || value == max) {
return;
}
if (comparator().compare(min, value) > 0) {
min = value.copy();
} else if (comparator().compare(max, value) < 0) {
max = value.copy();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,52 @@ public void testBinaryMinMaxForReusedBackingByteArray() {
assertThat(stats.getMinBytes()).isEqualTo(new byte[] {10});
}

@Test
public void testBinaryMinMaxForRepeatedSingleConstantInstance() {
BinaryStatistics stats = new BinaryStatistics();

Binary value = Binary.fromConstantByteArray(new byte[] {7});
stats.updateStats(value);
stats.updateStats(value);
stats.updateStats(value);

assertThat(stats.genericGetMin()).isSameAs(value);
assertThat(stats.genericGetMax()).isSameAs(value);
}

@Test
public void testBinaryMinMaxKeepsBoundInstancesForConstantValues() {
BinaryStatistics stats = new BinaryStatistics();

Binary low = Binary.fromConstantByteArray(new byte[] {10});
Binary high = Binary.fromConstantByteArray(new byte[] {30});
stats.updateStats(low);
stats.updateStats(high);
// The bounds keep the constant instances. An update with a bound instance does not change the bounds.
assertThat(stats.genericGetMin()).isSameAs(low);
assertThat(stats.genericGetMax()).isSameAs(high);
stats.updateStats(low);
assertThat(stats.genericGetMin()).isSameAs(low);
assertThat(stats.genericGetMax()).isSameAs(high);
stats.updateStats(high);
assertThat(stats.genericGetMin()).isSameAs(low);
assertThat(stats.genericGetMax()).isSameAs(high);
stats.updateStats(Binary.fromConstantByteArray(new byte[] {20}));
assertThat(stats.genericGetMin()).isSameAs(low);
assertThat(stats.genericGetMax()).isSameAs(high);

// A different instance with equal content does not change the bounds. Lower or higher values change them.
stats.updateStats(Binary.fromConstantByteArray(new byte[] {10}));
assertThat(stats.genericGetMin()).isSameAs(low);
assertThat(stats.genericGetMax()).isSameAs(high);
stats.updateStats(Binary.fromConstantByteArray(new byte[] {5}));
assertThat(stats.getMinBytes()).isEqualTo(new byte[] {5});
assertThat(stats.genericGetMax()).isSameAs(high);
stats.updateStats(Binary.fromConstantByteArray(new byte[] {40}));
assertThat(stats.getMinBytes()).isEqualTo(new byte[] {5});
assertThat(stats.getMaxBytes()).isEqualTo(new byte[] {40});
}

@Test
public void testMergingStatistics() {
testMergingIntStats();
Expand Down