Skip to content

Commit

Permalink
Merge pull request elastic#461 from nik9000/fix_basic_block_test
Browse files Browse the repository at this point in the history
ESQL: fix basic block tests
  • Loading branch information
nik9000 committed Dec 14, 2022
2 parents 4c46e39 + 91b121f commit e8650eb
Showing 1 changed file with 39 additions and 25 deletions.
Expand Up @@ -18,6 +18,7 @@
import java.util.stream.LongStream;

import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.startsWith;

Expand Down Expand Up @@ -47,11 +48,15 @@ public void testIntBlock() {
assertThat((long) pos, is(block.getLong(pos)));
assertThat((double) pos, is(block.getDouble(pos)));

assertNullValues(
positionCount,
nulls -> new IntArrayBlock(values, positionCount, nulls),
(randomNonNullPosition, b) -> { assertThat((int) randomNonNullPosition, is(b.getInt(randomNonNullPosition.intValue()))); }
);
if (positionCount > 1) {
assertNullValues(
positionCount,
nulls -> new IntArrayBlock(values, positionCount, nulls),
(randomNonNullPosition, b) -> {
assertThat((int) randomNonNullPosition, is(b.getInt(randomNonNullPosition.intValue())));
}
);
}
}
}

Expand Down Expand Up @@ -79,11 +84,15 @@ public void testLongBlock() {
assertThat((long) pos, is(block.getLong(pos)));
assertThat((double) pos, is(block.getDouble(pos)));

assertNullValues(
positionCount,
nulls -> new LongArrayBlock(values, positionCount, nulls),
(randomNonNullPosition, b) -> { assertThat((long) randomNonNullPosition, is(b.getLong(randomNonNullPosition.intValue()))); }
);
if (positionCount > 1) {
assertNullValues(
positionCount,
nulls -> new LongArrayBlock(values, positionCount, nulls),
(randomNonNullPosition, b) -> {
assertThat((long) randomNonNullPosition, is(b.getLong(randomNonNullPosition.intValue())));
}
);
}
}
}

Expand Down Expand Up @@ -112,13 +121,15 @@ public void testDoubleBlock() {
expectThrows(UOE, () -> block.getInt(pos));
expectThrows(UOE, () -> block.getLong(pos));

assertNullValues(
positionCount,
nulls -> new DoubleArrayBlock(values, positionCount, nulls),
(randomNonNullPosition, b) -> {
assertThat((double) randomNonNullPosition, is(b.getDouble(randomNonNullPosition.intValue())));
}
);
if (positionCount > 1) {
assertNullValues(
positionCount,
nulls -> new DoubleArrayBlock(values, positionCount, nulls),
(randomNonNullPosition, b) -> {
assertThat((double) randomNonNullPosition, is(b.getDouble(randomNonNullPosition.intValue())));
}
);
}
}
}

Expand Down Expand Up @@ -167,14 +178,16 @@ public void testBytesRefBlock() {
expectThrows(UOE, () -> block.getDouble(pos));
}

assertNullValues(
positionCount,
nulls -> new BytesRefArrayBlock(positionCount, builder.getBytes(), nulls),
(randomNonNullPosition, b) -> assertThat(
values[randomNonNullPosition],
is(b.getBytesRef(randomNonNullPosition, new BytesRef()))
)
);
if (positionCount > 1) {
assertNullValues(
positionCount,
nulls -> new BytesRefArrayBlock(positionCount, builder.getBytes(), nulls),
(randomNonNullPosition, b) -> assertThat(
values[randomNonNullPosition],
is(b.getBytesRef(randomNonNullPosition, new BytesRef()))
)
);
}
}

public void testBytesRefBlockBuilder() {
Expand Down Expand Up @@ -266,6 +279,7 @@ public void testConstantBytesRefBlock() {
}

private void assertNullValues(int positionCount, Function<BitSet, Block> blockConstructor, BiConsumer<Integer, Block> asserter) {
assertThat("test needs at least two positions", positionCount, greaterThan(1));
int randomNullPosition = randomIntBetween(0, positionCount - 1);
int randomNonNullPosition = randomValueOtherThan(randomNullPosition, () -> randomIntBetween(0, positionCount - 1));
BitSet nullsMask = new BitSet(positionCount);
Expand Down

0 comments on commit e8650eb

Please sign in to comment.