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
20 changes: 10 additions & 10 deletions core/trino-main/src/test/java/io/trino/block/BlockAssertions.java
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,16 @@ public static <T> List<T> generateListWithNulls(int positionCount, float nullRat
return unmodifiableList(result);
}

public static Set<Integer> chooseNullPositions(int positionCount, float nullRate)
{
int nullCount = (int) (positionCount * nullRate);
if (nullCount == 0) {
verify(nullRate == 0 || positionCount == 0, "position count %s too small to have at least one null with rate %s", (Object) positionCount, nullRate);
return ImmutableSet.of();
}
return chooseRandomUnique(positionCount, nullCount);
}

public static Block createStringsBlock(String... values)
{
requireNonNull(values, "values is null");
Expand Down Expand Up @@ -871,16 +881,6 @@ private interface ValueWriter<T>
void write(BlockBuilder builder, T value);
}

private static Set<Integer> chooseNullPositions(int positionCount, float nullRate)
{
int nullCount = (int) (positionCount * nullRate);
if (nullCount == 0) {
verify(nullRate == 0, "position count %s too small to have at least one null with rate %s", (Object) positionCount, nullRate);
return ImmutableSet.of();
}
return chooseRandomUnique(positionCount, nullCount);
}

private static Set<Integer> chooseRandomUnique(int bound, int count)
{
if (count < bound / 10) {
Expand Down
30 changes: 19 additions & 11 deletions core/trino-main/src/test/java/io/trino/operator/PageTestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,24 +75,32 @@ public static Page createRandomPage(
float nullRate,
Optional<Wrapping> wrapping)
{
int channelCount = types.size();
ImmutableList.Builder<Block> blocks = ImmutableList.builder();
List<Block> blocks = types.stream()
.map(type -> {
Block block = createRandomBlockForType(type, positionCount, nullRate);
return wrapping.map(w -> w.wrap(block, positionCount)).orElse(block);
})
.collect(toImmutableList());

for (int i = 0; i < channelCount; i++) {
Block block = createRandomBlockForType(types.get(i), positionCount, nullRate);
blocks.add(wrapping.map(w -> w.wrap(block, positionCount)).orElse(block));
}
return createPage(types, positionCount, hashChannels, blocks);
}

hashChannels.ifPresent(channels -> {
ImmutableList<Block> blocksWithoutHash = blocks.build();
public static Page createPage(
List<Type> types,
int positionCount,
Optional<List<Integer>> hashChannels,
List<Block> blocks)
{
ImmutableList.Builder<Block> finalBlocks = ImmutableList.<Block>builder().addAll(blocks);

blocks.add(getHashBlock(
hashChannels.ifPresent(channels -> {
finalBlocks.add(getHashBlock(
channels.stream()
.map(types::get)
.collect(toImmutableList()),
channels.stream().map(blocksWithoutHash::get).toArray(Block[]::new)));
channels.stream().map(blocks::get).toArray(Block[]::new)));
});

return new Page(positionCount, blocks.build().toArray(Block[]::new));
return new Page(positionCount, finalBlocks.build().toArray(Block[]::new));
}
}
Loading