Skip to content

Commit

Permalink
Remove deprecated constant Block APIs (#103723)
Browse files Browse the repository at this point in the history
This PR continues the removal of deprecated Block APIs.
  • Loading branch information
dnhatn committed Dec 27, 2023
1 parent eec1c28 commit eced6aa
Show file tree
Hide file tree
Showing 27 changed files with 34 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -499,22 +499,13 @@ private MethodSpec evaluateFinal() {
private void primitiveStateToResult(MethodSpec.Builder builder) {
switch (stateType.toString()) {
case "org.elasticsearch.compute.aggregation.IntState":
builder.addStatement(
"blocks[offset] = $T.newConstantBlockWith(state.intValue(), 1, driverContext.blockFactory())",
INT_BLOCK
);
builder.addStatement("blocks[offset] = driverContext.blockFactory().newConstantIntBlockWith(state.intValue(), 1)");
return;
case "org.elasticsearch.compute.aggregation.LongState":
builder.addStatement(
"blocks[offset] = $T.newConstantBlockWith(state.longValue(), 1, driverContext.blockFactory())",
LONG_BLOCK
);
builder.addStatement("blocks[offset] = driverContext.blockFactory().newConstantLongBlockWith(state.longValue(), 1)");
return;
case "org.elasticsearch.compute.aggregation.DoubleState":
builder.addStatement(
"blocks[offset] = $T.newConstantBlockWith(state.doubleValue(), 1, driverContext.blockFactory())",
DOUBLE_BLOCK
);
builder.addStatement("blocks[offset] = driverContext.blockFactory().newConstantDoubleBlockWith(state.doubleValue(), 1)");
return;
default:
throw new IllegalArgumentException("don't know how to convert state to result: " + stateType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,6 @@ static Builder newBlockBuilder(int estimatedSize, BlockFactory blockFactory) {
return blockFactory.newBooleanBlockBuilder(estimatedSize);
}

/**
* Returns a constant block.
* @deprecated use {@link BlockFactory#newConstantBooleanBlockWith}
*/
@Deprecated
static BooleanBlock newConstantBlockWith(boolean value, int positions, BlockFactory blockFactory) {
return blockFactory.newConstantBooleanBlockWith(value, positions);
}

/**
* Builder for {@link BooleanBlock}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,6 @@ static Builder newBlockBuilder(int estimatedSize, BlockFactory blockFactory) {
return blockFactory.newBytesRefBlockBuilder(estimatedSize);
}

/**
* Returns a constant block.
* @deprecated use {@link BlockFactory#newConstantBytesRefBlockWith}
*/
@Deprecated
static BytesRefBlock newConstantBlockWith(BytesRef value, int positions, BlockFactory blockFactory) {
return blockFactory.newConstantBytesRefBlockWith(value, positions);
}

/**
* Builder for {@link BytesRefBlock}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,6 @@ static Builder newBlockBuilder(int estimatedSize, BlockFactory blockFactory) {
return blockFactory.newDoubleBlockBuilder(estimatedSize);
}

/**
* Returns a constant block.
* @deprecated use {@link BlockFactory#newConstantDoubleBlockWith}
*/
@Deprecated
static DoubleBlock newConstantBlockWith(double value, int positions, BlockFactory blockFactory) {
return blockFactory.newConstantDoubleBlockWith(value, positions);
}

/**
* Builder for {@link DoubleBlock}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,6 @@ static Builder newBlockBuilder(int estimatedSize, BlockFactory blockFactory) {
return blockFactory.newIntBlockBuilder(estimatedSize);
}

/**
* Returns a constant block.
* @deprecated use {@link BlockFactory#newConstantIntBlockWith}
*/
@Deprecated
static IntBlock newConstantBlockWith(int value, int positions, BlockFactory blockFactory) {
return blockFactory.newConstantIntBlockWith(value, positions);
}

/**
* Builder for {@link IntBlock}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,6 @@ static Builder newBlockBuilder(int estimatedSize, BlockFactory blockFactory) {
return blockFactory.newLongBlockBuilder(estimatedSize);
}

/**
* Returns a constant block.
* @deprecated use {@link BlockFactory#newConstantLongBlockWith}
*/
@Deprecated
static LongBlock newConstantBlockWith(long value, int positions, BlockFactory blockFactory) {
return blockFactory.newConstantLongBlockWith(value, positions);
}

/**
* Builder for {@link LongBlock}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void evaluateFinal(Block[] blocks, int offset, DriverContext driverContex
blocks[offset] = Block.constantNullBlock(1, driverContext.blockFactory());
return;
}
blocks[offset] = DoubleBlock.newConstantBlockWith(state.doubleValue(), 1, driverContext.blockFactory());
blocks[offset] = driverContext.blockFactory().newConstantDoubleBlockWith(state.doubleValue(), 1);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void evaluateFinal(Block[] blocks, int offset, DriverContext driverContex
blocks[offset] = Block.constantNullBlock(1, driverContext.blockFactory());
return;
}
blocks[offset] = IntBlock.newConstantBlockWith(state.intValue(), 1, driverContext.blockFactory());
blocks[offset] = driverContext.blockFactory().newConstantIntBlockWith(state.intValue(), 1);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void evaluateFinal(Block[] blocks, int offset, DriverContext driverContex
blocks[offset] = Block.constantNullBlock(1, driverContext.blockFactory());
return;
}
blocks[offset] = LongBlock.newConstantBlockWith(state.longValue(), 1, driverContext.blockFactory());
blocks[offset] = driverContext.blockFactory().newConstantLongBlockWith(state.longValue(), 1);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void evaluateFinal(Block[] blocks, int offset, DriverContext driverContex
blocks[offset] = Block.constantNullBlock(1, driverContext.blockFactory());
return;
}
blocks[offset] = DoubleBlock.newConstantBlockWith(state.doubleValue(), 1, driverContext.blockFactory());
blocks[offset] = driverContext.blockFactory().newConstantDoubleBlockWith(state.doubleValue(), 1);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void evaluateFinal(Block[] blocks, int offset, DriverContext driverContex
blocks[offset] = Block.constantNullBlock(1, driverContext.blockFactory());
return;
}
blocks[offset] = IntBlock.newConstantBlockWith(state.intValue(), 1, driverContext.blockFactory());
blocks[offset] = driverContext.blockFactory().newConstantIntBlockWith(state.intValue(), 1);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void evaluateFinal(Block[] blocks, int offset, DriverContext driverContex
blocks[offset] = Block.constantNullBlock(1, driverContext.blockFactory());
return;
}
blocks[offset] = LongBlock.newConstantBlockWith(state.longValue(), 1, driverContext.blockFactory());
blocks[offset] = driverContext.blockFactory().newConstantLongBlockWith(state.longValue(), 1);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void evaluateFinal(Block[] blocks, int offset, DriverContext driverContex
blocks[offset] = Block.constantNullBlock(1, driverContext.blockFactory());
return;
}
blocks[offset] = LongBlock.newConstantBlockWith(state.longValue(), 1, driverContext.blockFactory());
blocks[offset] = driverContext.blockFactory().newConstantLongBlockWith(state.longValue(), 1);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void evaluateFinal(Block[] blocks, int offset, DriverContext driverContex
blocks[offset] = Block.constantNullBlock(1, driverContext.blockFactory());
return;
}
blocks[offset] = LongBlock.newConstantBlockWith(state.longValue(), 1, driverContext.blockFactory());
blocks[offset] = driverContext.blockFactory().newConstantLongBlockWith(state.longValue(), 1);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static void combineIntermediate(SingleState current, boolean fbit, boolea

public static Block evaluateFinal(SingleState state, DriverContext driverContext) {
long result = ((state.bits & BIT_TRUE) >> 1) + (state.bits & BIT_FALSE);
return LongBlock.newConstantBlockWith(result, 1, driverContext.blockFactory());
return driverContext.blockFactory().newConstantLongBlockWith(result, 1);
}

public static GroupingState initGrouping(BigArrays bigArrays) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static void combineIntermediate(HllStates.SingleState current, BytesRef i

public static Block evaluateFinal(HllStates.SingleState state, DriverContext driverContext) {
long result = state.cardinality();
return LongBlock.newConstantBlockWith(result, 1, driverContext.blockFactory());
return driverContext.blockFactory().newConstantLongBlockWith(result, 1);
}

public static HllStates.GroupingState initGrouping(BigArrays bigArrays, int precision) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static void combineIntermediate(HllStates.SingleState current, BytesRef i

public static Block evaluateFinal(HllStates.SingleState state, DriverContext driverContext) {
long result = state.cardinality();
return LongBlock.newConstantBlockWith(result, 1, driverContext.blockFactory());
return driverContext.blockFactory().newConstantLongBlockWith(result, 1);
}

public static HllStates.GroupingState initGrouping(BigArrays bigArrays, int precision) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static void combineIntermediate(HllStates.SingleState current, BytesRef i

public static Block evaluateFinal(HllStates.SingleState state, DriverContext driverContext) {
long result = state.cardinality();
return LongBlock.newConstantBlockWith(result, 1, driverContext.blockFactory());
return driverContext.blockFactory().newConstantLongBlockWith(result, 1);
}

public static HllStates.GroupingState initGrouping(BigArrays bigArrays, int precision) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static void combineIntermediate(HllStates.SingleState current, BytesRef i

public static Block evaluateFinal(HllStates.SingleState state, DriverContext driverContext) {
long result = state.cardinality();
return LongBlock.newConstantBlockWith(result, 1, driverContext.blockFactory());
return driverContext.blockFactory().newConstantLongBlockWith(result, 1);
}

public static HllStates.GroupingState initGrouping(BigArrays bigArrays, int precision) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static void evaluateIntermediate(SumState state, DriverContext driverCont

public static Block evaluateFinal(SumState state, DriverContext driverContext) {
double result = state.value();
return DoubleBlock.newConstantBlockWith(result, 1, driverContext.blockFactory());
return driverContext.blockFactory().newConstantDoubleBlockWith(result, 1);
}

public static GroupingSumState initGrouping(BigArrays bigArrays) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,11 @@ public static Block constantBlock(BlockFactory blockFactory, Object val, int siz
private static Block constantBlock(BlockFactory blockFactory, ElementType type, Object val, int size) {
return switch (type) {
case NULL -> blockFactory.newConstantNullBlock(size);
case LONG -> LongBlock.newConstantBlockWith((long) val, size, blockFactory);
case INT -> IntBlock.newConstantBlockWith((int) val, size, blockFactory);
case BYTES_REF -> BytesRefBlock.newConstantBlockWith(toBytesRef(val), size, blockFactory);
case DOUBLE -> DoubleBlock.newConstantBlockWith((double) val, size, blockFactory);
case BOOLEAN -> BooleanBlock.newConstantBlockWith((boolean) val, size, blockFactory);
case LONG -> blockFactory.newConstantLongBlockWith((long) val, size);
case INT -> blockFactory.newConstantIntBlockWith((int) val, size);
case BYTES_REF -> blockFactory.newConstantBytesRefBlockWith(toBytesRef(val), size);
case DOUBLE -> blockFactory.newConstantDoubleBlockWith((double) val, size);
case BOOLEAN -> blockFactory.newConstantBooleanBlockWith((boolean) val, size);
default -> throw new UnsupportedOperationException("unsupported element type [" + type + "]");
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,6 @@ $endif$
return blockFactory.new$Type$BlockBuilder(estimatedSize);
}

/**
* Returns a constant block.
* @deprecated use {@link BlockFactory#newConstant$Type$BlockWith}
*/
@Deprecated
static $Type$Block newConstantBlockWith($type$ value, int positions, BlockFactory blockFactory) {
return blockFactory.newConstant$Type$BlockWith(value, positions);
}

/**
* Builder for {@link $Type$Block}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ public Page getOutput() {
LongBlock count = null;
BooleanBlock seen = null;
try {
count = LongBlock.newConstantBlockWith(totalHits, PAGE_SIZE, blockFactory);
seen = BooleanBlock.newConstantBlockWith(true, PAGE_SIZE, blockFactory);
count = blockFactory.newConstantLongBlockWith(totalHits, PAGE_SIZE);
seen = blockFactory.newConstantBooleanBlockWith(true, PAGE_SIZE);
page = new Page(PAGE_SIZE, count, seen);
} finally {
if (page == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ public Page getOutput() {
IntBlock leaf = null;
IntVector docs = null;
try {
shard = IntBlock.newConstantBlockWith(scorer.shardIndex(), currentPagePos, blockFactory);
leaf = IntBlock.newConstantBlockWith(scorer.leafReaderContext().ord, currentPagePos, blockFactory);
shard = blockFactory.newConstantIntBlockWith(scorer.shardIndex(), currentPagePos);
leaf = blockFactory.newConstantIntBlockWith(scorer.leafReaderContext().ord, currentPagePos);
docs = docsBuilder.build();
docsBuilder = blockFactory.newIntVectorBuilder(Math.min(remainingDocs, maxPageSize));
page = new Page(currentPagePos, new DocVector(shard.asVector(), leaf.asVector(), docs, true).asBlock());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ private Page emit(boolean startEmitting) {
currentDocsBuilder.appendInt(doc - leafContexts.get(segment).docBase); // the offset inside the segment
}

shard = IntBlock.newConstantBlockWith(perShardCollector.shardIndex, size, blockFactory);
shard = blockFactory.newConstantIntBlockWith(perShardCollector.shardIndex, size);
segments = currentSegmentBuilder.build();
docs = currentDocsBuilder.build();
page = new Page(size, new DocVector(shard.asVector(), segments, docs, null).asBlock());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,7 @@ public void testConstantIntBlock() {
assertThat(breaker.getUsed(), is(0L));
int positionCount = randomIntBetween(1, 16 * 1024);
int value = randomInt();
IntBlock block;
if (randomBoolean()) {
block = IntBlock.newConstantBlockWith(value, positionCount, blockFactory);
} else {
block = blockFactory.newConstantIntBlockWith(value, positionCount);
}
IntBlock block = blockFactory.newConstantIntBlockWith(value, positionCount);
assertThat(positionCount, is(block.getPositionCount()));
assertThat(value, is(block.getInt(0)));
assertThat(value, is(block.getInt(positionCount - 1)));
Expand Down Expand Up @@ -295,12 +290,7 @@ public void testConstantLongBlock() {
assertThat(breaker.getUsed(), is(0L));
int positionCount = randomIntBetween(1, 16 * 1024);
long value = randomLong();
LongBlock block;
if (randomBoolean()) {
block = LongBlock.newConstantBlockWith(value, positionCount, blockFactory);
} else {
block = blockFactory.newConstantLongBlockWith(value, positionCount);
}
LongBlock block = blockFactory.newConstantLongBlockWith(value, positionCount);
assertThat(positionCount, is(block.getPositionCount()));
assertThat(value, is(block.getLong(0)));
assertThat(value, is(block.getLong(positionCount - 1)));
Expand Down Expand Up @@ -369,12 +359,7 @@ public void testConstantDoubleBlock() {
for (int i = 0; i < 1000; i++) {
int positionCount = randomIntBetween(1, 16 * 1024);
double value = randomDouble();
DoubleBlock block;
if (randomBoolean()) {
block = DoubleBlock.newConstantBlockWith(value, positionCount, blockFactory);
} else {
block = blockFactory.newConstantDoubleBlockWith(value, positionCount);
}
DoubleBlock block = blockFactory.newConstantDoubleBlockWith(value, positionCount);
assertThat(positionCount, is(block.getPositionCount()));
assertThat(value, is(block.getDouble(0)));
assertThat(value, is(block.getDouble(positionCount - 1)));
Expand Down Expand Up @@ -496,12 +481,7 @@ public void testConstantBytesRefBlock() {
for (int i = 0; i < 1000; i++) {
int positionCount = randomIntBetween(1, 16 * 1024);
BytesRef value = new BytesRef(randomByteArrayOfLength(between(1, 20)));
BytesRefBlock block;
if (randomBoolean()) {
block = BytesRefBlock.newConstantBlockWith(value, positionCount, blockFactory);
} else {
block = blockFactory.newConstantBytesRefBlockWith(value, positionCount);
}
BytesRefBlock block = blockFactory.newConstantBytesRefBlockWith(value, positionCount);
assertThat(block.getPositionCount(), is(positionCount));

BytesRef bytes = new BytesRef();
Expand Down Expand Up @@ -572,12 +552,7 @@ public void testConstantBooleanBlock() {
for (int i = 0; i < 1000; i++) {
int positionCount = randomIntBetween(1, 16 * 1024);
boolean value = randomBoolean();
BooleanBlock block;
if (randomBoolean()) {
block = BooleanBlock.newConstantBlockWith(value, positionCount, blockFactory);
} else {
block = blockFactory.newConstantBooleanBlockWith(value, positionCount);
}
BooleanBlock block = blockFactory.newConstantBooleanBlockWith(value, positionCount);
assertThat(positionCount, is(block.getPositionCount()));
assertThat(block.getBoolean(0), is(value));
assertThat(block.getBoolean(positionCount - 1), is(value));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ record IsNullEvaluator(DriverContext driverContext, EvalOperator.ExpressionEvalu
public Block eval(Page page) {
try (Block fieldBlock = field.eval(page)) {
if (fieldBlock.asVector() != null) {
return BooleanBlock.newConstantBlockWith(false, page.getPositionCount(), driverContext.blockFactory());
return driverContext.blockFactory().newConstantBooleanBlockWith(false, page.getPositionCount());
}
try (var builder = driverContext.blockFactory().newBooleanVectorFixedBuilder(page.getPositionCount())) {
for (int p = 0; p < page.getPositionCount(); p++) {
Expand Down Expand Up @@ -316,7 +316,7 @@ record IsNotNullEvaluator(DriverContext driverContext, EvalOperator.ExpressionEv
public Block eval(Page page) {
try (Block fieldBlock = field.eval(page)) {
if (fieldBlock.asVector() != null) {
return BooleanBlock.newConstantBlockWith(true, page.getPositionCount(), driverContext.blockFactory());
return driverContext.blockFactory().newConstantBooleanBlockWith(true, page.getPositionCount());
}
try (var builder = driverContext.blockFactory().newBooleanVectorFixedBuilder(page.getPositionCount())) {
for (int p = 0; p < page.getPositionCount(); p++) {
Expand Down

0 comments on commit eced6aa

Please sign in to comment.