Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESQL: Ensure pages contain no duplicate blocks #100061

Closed
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 @@ -74,6 +74,7 @@ private Page(boolean copyBlocks, int positionCount, Block[] blocks) {
throw new IllegalArgumentException("can't build page out of released blocks but [" + b + "] was released");
}
}
assert hasNoEqualBlocks() : "contains two equal blocks";
}

public Page(StreamInput in) throws IOException {
Expand All @@ -85,6 +86,19 @@ public Page(StreamInput in) throws IOException {
}
this.positionCount = positionCount;
this.blocks = blocks;
assert hasNoEqualBlocks() : "contains two equal blocks";
}

private boolean hasNoEqualBlocks() {
for (int i = 0; i < blocks.length - 1; i++) {
for (int j = i + 1; j < blocks.length; j++) {
if (blocks[i] == blocks[j]) {
return false;
}
}
}

return true;
}

private static int determinePositionCount(Block... blocks) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ public void testEqualityAndHashCodeSmallInput() {
);
}

public void testZeAssertion() {
var block = IntBlock.newConstantBlockWith(1, 1);
expectThrows(AssertionError.class, () -> new Page(1, new Block[] { block, block }));
}

public void testEqualityAndHashCode() throws IOException {
final EqualsHashCodeTestUtils.CopyFunction<Page> copyPageFunction = page -> {
Block[] blocks = new Block[page.getBlockCount()];
Expand Down