Skip to content

Commit

Permalink
Merge branch 'main' into esql_eval_factory
Browse files Browse the repository at this point in the history
  • Loading branch information
nik9000 committed Oct 28, 2023
2 parents c97534d + 93b620e commit 665551a
Show file tree
Hide file tree
Showing 180 changed files with 108 additions and 1,044 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,7 @@ private MethodSpec intermediateBlockCount() {
private MethodSpec addRawInput() {
MethodSpec.Builder builder = MethodSpec.methodBuilder("addRawInput");
builder.addAnnotation(Override.class).addModifiers(Modifier.PUBLIC).addParameter(PAGE, "page");
builder.addStatement("$T uncastBlock = page.getBlock(channels.get(0))", BLOCK);
builder.beginControlFlow("if (uncastBlock.areAllValuesNull())").addStatement("return").endControlFlow();
builder.addStatement("$T block = ($T) uncastBlock", valueBlockType(init, combine), valueBlockType(init, combine));
builder.addStatement("$T block = page.getBlock(channels.get(0))", valueBlockType(init, combine));
builder.addStatement("$T vector = block.asVector()", valueVectorType(init, combine));
builder.beginControlFlow("if (vector != null)").addStatement("addRawVector(vector)");
builder.nextControlFlow("else").addStatement("addRawBlock(block)").endControlFlow();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,9 +441,6 @@ public String factoryInvocation(MethodSpec.Builder factoryMethodBuilder) {
public void evalToBlock(MethodSpec.Builder builder) {
TypeName blockType = blockType(type);
builder.beginControlFlow("try (Block.Ref $LRef = $L.eval(page))", name, name);
builder.beginControlFlow("if ($LRef.block().areAllValuesNull())", name);
builder.addStatement("return Block.Ref.floating(driverContext.blockFactory().newConstantNullBlock(page.getPositionCount()))");
builder.endControlFlow();
builder.addStatement("$T $LBlock = ($T) $LRef.block()", blockType, name, blockType, name);
}

Expand Down Expand Up @@ -570,13 +567,7 @@ public void evalToBlock(MethodSpec.Builder builder) {
builder.beginControlFlow("for (int i = 0; i < $LBlocks.length; i++)", name);
{
builder.addStatement("$LRefs[i] = $L[i].eval(page)", name, name);
builder.addStatement("Block block = $LRefs[i].block()", name);
builder.beginControlFlow("if (block.areAllValuesNull())");
builder.addStatement(
"return Block.Ref.floating(driverContext.blockFactory().newConstantNullBlock(page.getPositionCount()))"
);
builder.endControlFlow();
builder.addStatement("$LBlocks[i] = ($T) block", name, blockType);
builder.addStatement("$LBlocks[i] = ($T) $LRefs[i].block()", name, blockType, name);
}
builder.endControlFlow();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import static org.elasticsearch.compute.gen.Methods.findMethod;
import static org.elasticsearch.compute.gen.Methods.findRequiredMethod;
import static org.elasticsearch.compute.gen.Methods.vectorAccessorName;
import static org.elasticsearch.compute.gen.Types.BLOCK;
import static org.elasticsearch.compute.gen.Types.BLOCK_ARRAY;
import static org.elasticsearch.compute.gen.Types.BYTES_REF;
import static org.elasticsearch.compute.gen.Types.DRIVER_CONTEXT;
Expand Down Expand Up @@ -250,16 +249,7 @@ private MethodSpec prepareProcessPage() {
builder.addAnnotation(Override.class).addModifiers(Modifier.PUBLIC).returns(GROUPING_AGGREGATOR_FUNCTION_ADD_INPUT);
builder.addParameter(SEEN_GROUP_IDS, "seenGroupIds").addParameter(PAGE, "page");

builder.addStatement("$T uncastValuesBlock = page.getBlock(channels.get(0))", BLOCK);

builder.beginControlFlow("if (uncastValuesBlock.areAllValuesNull())");
{
builder.addStatement("state.enableGroupIdTracking(seenGroupIds)");
builder.addStatement("return $L", addInput(b -> {}));
}
builder.endControlFlow();

builder.addStatement("$T valuesBlock = ($T) uncastValuesBlock", valueBlockType(init, combine), valueBlockType(init, combine));
builder.addStatement("$T valuesBlock = page.getBlock(channels.get(0))", valueBlockType(init, combine));
builder.addStatement("$T valuesVector = valuesBlock.asVector()", valueVectorType(init, combine));
builder.beginControlFlow("if (valuesVector == null)");
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,24 +101,32 @@ default void writeTo(StreamOutput out) throws IOException {
}
}

/** Returns a builder using the {@link BlockFactory#getNonBreakingInstance block factory}. */
/**
* Returns a builder using the {@link BlockFactory#getNonBreakingInstance nonbreaking block factory}.
* @deprecated use {@link BlockFactory#newBooleanVectorBuilder}
*/
// Eventually, we want to remove this entirely, always passing an explicit BlockFactory
@Deprecated
static Builder newVectorBuilder(int estimatedSize) {
return newVectorBuilder(estimatedSize, BlockFactory.getNonBreakingInstance());
}

/**
* Creates a builder that grows as needed. Prefer {@link #newVectorFixedBuilder}
* if you know the size up front because it's faster.
* @deprecated use {@link BlockFactory#newBooleanVectorBuilder}
*/
@Deprecated
static Builder newVectorBuilder(int estimatedSize, BlockFactory blockFactory) {
return blockFactory.newBooleanVectorBuilder(estimatedSize);
}

/**
* Creates a builder that never grows. Prefer this over {@link #newVectorBuilder}
* if you know the size up front because it's faster.
* @deprecated use {@link BlockFactory#newBooleanVectorFixedBuilder}
*/
@Deprecated
static FixedBuilder newVectorFixedBuilder(int size, BlockFactory blockFactory) {
return blockFactory.newBooleanVectorFixedBuilder(size);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,21 @@ default void writeTo(StreamOutput out) throws IOException {
}
}

/** Returns a builder using the {@link BlockFactory#getNonBreakingInstance block factory}. */
/**
* Returns a builder using the {@link BlockFactory#getNonBreakingInstance nonbreaking block factory}.
* @deprecated use {@link BlockFactory#newBytesRefVectorBuilder}
*/
// Eventually, we want to remove this entirely, always passing an explicit BlockFactory
@Deprecated
static Builder newVectorBuilder(int estimatedSize) {
return newVectorBuilder(estimatedSize, BlockFactory.getNonBreakingInstance());
}

/**
* Creates a builder that grows as needed.
* @deprecated use {@link BlockFactory#newBytesRefVectorBuilder}
*/
@Deprecated
static Builder newVectorBuilder(int estimatedSize, BlockFactory blockFactory) {
return blockFactory.newBytesRefVectorBuilder(estimatedSize);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,24 +102,32 @@ default void writeTo(StreamOutput out) throws IOException {
}
}

/** Returns a builder using the {@link BlockFactory#getNonBreakingInstance block factory}. */
/**
* Returns a builder using the {@link BlockFactory#getNonBreakingInstance nonbreaking block factory}.
* @deprecated use {@link BlockFactory#newDoubleVectorBuilder}
*/
// Eventually, we want to remove this entirely, always passing an explicit BlockFactory
@Deprecated
static Builder newVectorBuilder(int estimatedSize) {
return newVectorBuilder(estimatedSize, BlockFactory.getNonBreakingInstance());
}

/**
* Creates a builder that grows as needed. Prefer {@link #newVectorFixedBuilder}
* if you know the size up front because it's faster.
* @deprecated use {@link BlockFactory#newDoubleVectorBuilder}
*/
@Deprecated
static Builder newVectorBuilder(int estimatedSize, BlockFactory blockFactory) {
return blockFactory.newDoubleVectorBuilder(estimatedSize);
}

/**
* Creates a builder that never grows. Prefer this over {@link #newVectorBuilder}
* if you know the size up front because it's faster.
* @deprecated use {@link BlockFactory#newDoubleVectorFixedBuilder}
*/
@Deprecated
static FixedBuilder newVectorFixedBuilder(int size, BlockFactory blockFactory) {
return blockFactory.newDoubleVectorFixedBuilder(size);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,24 +101,32 @@ default void writeTo(StreamOutput out) throws IOException {
}
}

/** Returns a builder using the {@link BlockFactory#getNonBreakingInstance block factory}. */
/**
* Returns a builder using the {@link BlockFactory#getNonBreakingInstance nonbreaking block factory}.
* @deprecated use {@link BlockFactory#newIntVectorBuilder}
*/
// Eventually, we want to remove this entirely, always passing an explicit BlockFactory
@Deprecated
static Builder newVectorBuilder(int estimatedSize) {
return newVectorBuilder(estimatedSize, BlockFactory.getNonBreakingInstance());
}

/**
* Creates a builder that grows as needed. Prefer {@link #newVectorFixedBuilder}
* if you know the size up front because it's faster.
* @deprecated use {@link BlockFactory#newIntVectorBuilder}
*/
@Deprecated
static Builder newVectorBuilder(int estimatedSize, BlockFactory blockFactory) {
return blockFactory.newIntVectorBuilder(estimatedSize);
}

/**
* Creates a builder that never grows. Prefer this over {@link #newVectorBuilder}
* if you know the size up front because it's faster.
* @deprecated use {@link BlockFactory#newIntVectorFixedBuilder}
*/
@Deprecated
static FixedBuilder newVectorFixedBuilder(int size, BlockFactory blockFactory) {
return blockFactory.newIntVectorFixedBuilder(size);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,24 +102,32 @@ default void writeTo(StreamOutput out) throws IOException {
}
}

/** Returns a builder using the {@link BlockFactory#getNonBreakingInstance block factory}. */
/**
* Returns a builder using the {@link BlockFactory#getNonBreakingInstance nonbreaking block factory}.
* @deprecated use {@link BlockFactory#newLongVectorBuilder}
*/
// Eventually, we want to remove this entirely, always passing an explicit BlockFactory
@Deprecated
static Builder newVectorBuilder(int estimatedSize) {
return newVectorBuilder(estimatedSize, BlockFactory.getNonBreakingInstance());
}

/**
* Creates a builder that grows as needed. Prefer {@link #newVectorFixedBuilder}
* if you know the size up front because it's faster.
* @deprecated use {@link BlockFactory#newLongVectorBuilder}
*/
@Deprecated
static Builder newVectorBuilder(int estimatedSize, BlockFactory blockFactory) {
return blockFactory.newLongVectorBuilder(estimatedSize);
}

/**
* Creates a builder that never grows. Prefer this over {@link #newVectorBuilder}
* if you know the size up front because it's faster.
* @deprecated use {@link BlockFactory#newLongVectorFixedBuilder}
*/
@Deprecated
static FixedBuilder newVectorFixedBuilder(int size, BlockFactory blockFactory) {
return blockFactory.newLongVectorFixedBuilder(size);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,7 @@ public int intermediateBlockCount() {

@Override
public void addRawInput(Page page) {
Block uncastBlock = page.getBlock(channels.get(0));
if (uncastBlock.areAllValuesNull()) {
return;
}
BooleanBlock block = (BooleanBlock) uncastBlock;
BooleanBlock block = page.getBlock(channels.get(0));
BooleanVector vector = block.asVector();
if (vector != null) {
addRawVector(vector);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,7 @@ public int intermediateBlockCount() {
@Override
public GroupingAggregatorFunction.AddInput prepareProcessPage(SeenGroupIds seenGroupIds,
Page page) {
Block uncastValuesBlock = page.getBlock(channels.get(0));
if (uncastValuesBlock.areAllValuesNull()) {
state.enableGroupIdTracking(seenGroupIds);
return new GroupingAggregatorFunction.AddInput() {
@Override
public void add(int positionOffset, IntBlock groupIds) {
}

@Override
public void add(int positionOffset, IntVector groupIds) {
}
};
}
BooleanBlock valuesBlock = (BooleanBlock) uncastValuesBlock;
BooleanBlock valuesBlock = page.getBlock(channels.get(0));
BooleanVector valuesVector = valuesBlock.asVector();
if (valuesVector == null) {
if (valuesBlock.mayHaveNulls()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,7 @@ public int intermediateBlockCount() {

@Override
public void addRawInput(Page page) {
Block uncastBlock = page.getBlock(channels.get(0));
if (uncastBlock.areAllValuesNull()) {
return;
}
BytesRefBlock block = (BytesRefBlock) uncastBlock;
BytesRefBlock block = page.getBlock(channels.get(0));
BytesRefVector vector = block.asVector();
if (vector != null) {
addRawVector(vector);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,7 @@ public int intermediateBlockCount() {
@Override
public GroupingAggregatorFunction.AddInput prepareProcessPage(SeenGroupIds seenGroupIds,
Page page) {
Block uncastValuesBlock = page.getBlock(channels.get(0));
if (uncastValuesBlock.areAllValuesNull()) {
state.enableGroupIdTracking(seenGroupIds);
return new GroupingAggregatorFunction.AddInput() {
@Override
public void add(int positionOffset, IntBlock groupIds) {
}

@Override
public void add(int positionOffset, IntVector groupIds) {
}
};
}
BytesRefBlock valuesBlock = (BytesRefBlock) uncastValuesBlock;
BytesRefBlock valuesBlock = page.getBlock(channels.get(0));
BytesRefVector valuesVector = valuesBlock.asVector();
if (valuesVector == null) {
if (valuesBlock.mayHaveNulls()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,7 @@ public int intermediateBlockCount() {

@Override
public void addRawInput(Page page) {
Block uncastBlock = page.getBlock(channels.get(0));
if (uncastBlock.areAllValuesNull()) {
return;
}
DoubleBlock block = (DoubleBlock) uncastBlock;
DoubleBlock block = page.getBlock(channels.get(0));
DoubleVector vector = block.asVector();
if (vector != null) {
addRawVector(vector);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,7 @@ public int intermediateBlockCount() {
@Override
public GroupingAggregatorFunction.AddInput prepareProcessPage(SeenGroupIds seenGroupIds,
Page page) {
Block uncastValuesBlock = page.getBlock(channels.get(0));
if (uncastValuesBlock.areAllValuesNull()) {
state.enableGroupIdTracking(seenGroupIds);
return new GroupingAggregatorFunction.AddInput() {
@Override
public void add(int positionOffset, IntBlock groupIds) {
}

@Override
public void add(int positionOffset, IntVector groupIds) {
}
};
}
DoubleBlock valuesBlock = (DoubleBlock) uncastValuesBlock;
DoubleBlock valuesBlock = page.getBlock(channels.get(0));
DoubleVector valuesVector = valuesBlock.asVector();
if (valuesVector == null) {
if (valuesBlock.mayHaveNulls()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,7 @@ public int intermediateBlockCount() {

@Override
public void addRawInput(Page page) {
Block uncastBlock = page.getBlock(channels.get(0));
if (uncastBlock.areAllValuesNull()) {
return;
}
IntBlock block = (IntBlock) uncastBlock;
IntBlock block = page.getBlock(channels.get(0));
IntVector vector = block.asVector();
if (vector != null) {
addRawVector(vector);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,7 @@ public int intermediateBlockCount() {
@Override
public GroupingAggregatorFunction.AddInput prepareProcessPage(SeenGroupIds seenGroupIds,
Page page) {
Block uncastValuesBlock = page.getBlock(channels.get(0));
if (uncastValuesBlock.areAllValuesNull()) {
state.enableGroupIdTracking(seenGroupIds);
return new GroupingAggregatorFunction.AddInput() {
@Override
public void add(int positionOffset, IntBlock groupIds) {
}

@Override
public void add(int positionOffset, IntVector groupIds) {
}
};
}
IntBlock valuesBlock = (IntBlock) uncastValuesBlock;
IntBlock valuesBlock = page.getBlock(channels.get(0));
IntVector valuesVector = valuesBlock.asVector();
if (valuesVector == null) {
if (valuesBlock.mayHaveNulls()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,7 @@ public int intermediateBlockCount() {

@Override
public void addRawInput(Page page) {
Block uncastBlock = page.getBlock(channels.get(0));
if (uncastBlock.areAllValuesNull()) {
return;
}
LongBlock block = (LongBlock) uncastBlock;
LongBlock block = page.getBlock(channels.get(0));
LongVector vector = block.asVector();
if (vector != null) {
addRawVector(vector);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,7 @@ public int intermediateBlockCount() {
@Override
public GroupingAggregatorFunction.AddInput prepareProcessPage(SeenGroupIds seenGroupIds,
Page page) {
Block uncastValuesBlock = page.getBlock(channels.get(0));
if (uncastValuesBlock.areAllValuesNull()) {
state.enableGroupIdTracking(seenGroupIds);
return new GroupingAggregatorFunction.AddInput() {
@Override
public void add(int positionOffset, IntBlock groupIds) {
}

@Override
public void add(int positionOffset, IntVector groupIds) {
}
};
}
LongBlock valuesBlock = (LongBlock) uncastValuesBlock;
LongBlock valuesBlock = page.getBlock(channels.get(0));
LongVector valuesVector = valuesBlock.asVector();
if (valuesVector == null) {
if (valuesBlock.mayHaveNulls()) {
Expand Down
Loading

0 comments on commit 665551a

Please sign in to comment.