}
}
private void addInputWithSampling(Page page, int sampleWeightChannel)
{
Block sampleWeightBlock = page.getBlock(sampleWeightChannel);
BlockBuilder builder = BIGINT.createBlockBuilder(new BlockBuilderStatus());
int rowsToCopy = 0;
// Build the sample weight block, and count how many rows of data to copy
for (int position = 0; position < sampleWeightBlock.getPositionCount() && remainingLimit > 0; position++) {
rowsToCopy++;
long sampleWeight = sampleWeightBlock.getLong(position);
if (sampleWeight <= remainingLimit) {
builder.appendLong(sampleWeight);
}
else {
builder.appendLong(remainingLimit);
}
remainingLimit -= sampleWeight;
}
if (remainingLimit >= 0 && rowsToCopy == page.getPositionCount()) {
nextPage = page;
}
else {
Block[] blocks = new Block[page.getChannelCount()];
blocks[sampleWeightChannel] = builder.build();
for (int channel = 0; channel < page.getChannelCount(); channel++) {
if (channel == sampleWeightChannel) {
continue;
}
Block block = page.getBlock(channel);
blocks[channel] = block.getRegion(0, rowsToCopy);
}
nextPage = new Page(rowsToCopy, blocks);
remainingLimit = 0;
}
}