Skip to content
Merged
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 @@ -11,6 +11,7 @@
import org.elasticsearch.compute.data.Block;
import org.elasticsearch.compute.data.Page;
import org.elasticsearch.core.ReleasableIterator;
import org.elasticsearch.core.Releasables;

/**
* {@link Block#lookup Looks up} values from a provided {@link Block} and
Expand Down Expand Up @@ -44,8 +45,19 @@ public String describe() {
private final int positionsOrd;

public ColumnLoadOperator(Values values, int positionsOrd) {
this.values = values;
this.positionsOrd = positionsOrd;
this.values = clone(values);
}

// FIXME: Since we don't have a thread-safe RefCounted for blocks/vectors, we have to clone the values block to avoid
// data races of reference when sharing blocks/vectors across threads. Remove this when we have a thread-safe RefCounted
// for blocks/vectors.
static Values clone(Values values) {
final Block block = values.block;
try (var builder = block.elementType().newBlockBuilder(block.getPositionCount(), block.blockFactory())) {
builder.copyFrom(block, 0, block.getPositionCount());
return new Values(values.name, builder.build());
}
}

/**
Expand All @@ -67,6 +79,11 @@ protected ReleasableIterator<Page> receive(Page page) {
return appendBlocks(page, values.block.lookup(page.getBlock(positionsOrd), TARGET_BLOCK_SIZE));
}

@Override
public void close() {
Releasables.closeExpectNoException(values.block, super::close);
}

@Override
public String toString() {
return "ColumnLoad[values=" + values + ", positions=" + positionsOrd + "]";
Expand Down