Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESQL: Use blockFactory more in aggs #100017

Merged
merged 38 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
1ab53c8
use driver context in more places
ChrisHegarty Sep 26, 2023
734f5a9
Merge branch 'main' into blkfac_internal_aggs
ChrisHegarty Sep 27, 2023
388874a
Merge branch 'main' into blkfac_internal_aggs
ChrisHegarty Sep 28, 2023
5becc68
more updates
ChrisHegarty Sep 28, 2023
4896ab7
Merge branch 'main' into blkfac_internal_aggs
ChrisHegarty Sep 29, 2023
b27bafa
more fixes and tests
ChrisHegarty Sep 29, 2023
ae9138a
more updates
ChrisHegarty Oct 1, 2023
120f014
more fixes and rework
ChrisHegarty Oct 1, 2023
7b9d459
fix build
ChrisHegarty Oct 2, 2023
9238dfe
Merge branch 'main' into blkfac_internal_aggs
ChrisHegarty Oct 2, 2023
5179a22
fix benchmark compile
ChrisHegarty Oct 2, 2023
ef147c8
update BlockHashRandomizedTests
ChrisHegarty Oct 2, 2023
77c6e59
fixes
ChrisHegarty Oct 2, 2023
7192bc0
builders and tests
ChrisHegarty Oct 2, 2023
c3f54fc
Merge branch 'main' into blkfac_internal_aggs
ChrisHegarty Oct 2, 2023
67ba979
post merge fixes
ChrisHegarty Oct 2, 2023
b1b13a6
fix test
ChrisHegarty Oct 2, 2023
2ab12a1
block vector
ChrisHegarty Oct 2, 2023
052b3f6
awaits fix
ChrisHegarty Oct 2, 2023
4e83282
Merge branch 'main' into blkfac_internal_aggs
ChrisHegarty Oct 2, 2023
084c6ee
remove no longer needed Awaits
ChrisHegarty Oct 2, 2023
760a6cf
awaits fix url
ChrisHegarty Oct 2, 2023
d46f1a0
assert exact estimate in fixed vector builders
ChrisHegarty Oct 2, 2023
a9b531d
remove leftover
ChrisHegarty Oct 2, 2023
b0ddbc8
comment for mock block factory
ChrisHegarty Oct 2, 2023
a2043d8
spotless and stray leftover
ChrisHegarty Oct 2, 2023
f7e65bd
Merge branch 'main' into blkfac_internal_aggs
ChrisHegarty Oct 3, 2023
d69ab66
Merge branch 'main' into blkfac_internal_aggs
ChrisHegarty Oct 3, 2023
bf5b5bb
remove some awaits fixes
ChrisHegarty Oct 3, 2023
9e064fb
clean up and releases
ChrisHegarty Oct 3, 2023
c80880e
imports
ChrisHegarty Oct 3, 2023
9824280
revert Driver changes
ChrisHegarty Oct 3, 2023
cdc1779
spotless
ChrisHegarty Oct 3, 2023
c548bbc
remove superfluous close, now that drive releases pages
ChrisHegarty Oct 3, 2023
1845826
reverts and cleanup in tests
ChrisHegarty Oct 3, 2023
c746ab7
remove awaits fix
ChrisHegarty Oct 3, 2023
6fcd702
import
ChrisHegarty Oct 3, 2023
9c390d9
javadoc
ChrisHegarty Oct 3, 2023
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 @@ -144,7 +144,7 @@ private static Operator operator(String grouping, String op, String dataType) {
DriverContext driverContext = driverContext();
return new HashAggregationOperator(
List.of(supplier(op, dataType, groups.size()).groupingAggregatorFactory(AggregatorMode.SINGLE)),
() -> BlockHash.build(groups, BIG_ARRAYS, 16 * 1024, false),
() -> BlockHash.build(groups, driverContext, 16 * 1024, false),
driverContext
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,21 @@ public final class BooleanArrayVector extends AbstractVector implements BooleanV

private final boolean[] values;

private final BooleanBlock block;

public BooleanArrayVector(boolean[] values, int positionCount) {
this(values, positionCount, BlockFactory.getNonBreakingInstance());
}

public BooleanArrayVector(boolean[] values, int positionCount, BlockFactory blockFactory) {
super(positionCount, blockFactory);
this.values = values;
this.block = new BooleanVectorBlock(this);
}

@Override
public BooleanBlock asBlock() {
return new BooleanVectorBlock(this);
return block;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,21 @@ public final class BooleanBigArrayVector extends AbstractVector implements Boole

private final BitArray values;

private final BooleanBlock block;

public BooleanBigArrayVector(BitArray values, int positionCount) {
this(values, positionCount, BlockFactory.getNonBreakingInstance());
}

public BooleanBigArrayVector(BitArray values, int positionCount, BlockFactory blockFactory) {
super(positionCount, blockFactory);
this.values = values;
this.block = new BooleanVectorBlock(this);
}

@Override
public BooleanBlock asBlock() {
return new BooleanVectorBlock(this);
return block;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,26 +183,17 @@ public BooleanBlock build() {
finish();
BooleanBlock block;
if (hasNonNullValue && positionCount == 1 && valueCount == 1) {
block = new ConstantBooleanVector(values[0], 1, blockFactory).asBlock();
block = blockFactory.newConstantBooleanBlockWith(values[0], 1, estimatedBytes);
} else {
if (values.length - valueCount > 1024 || valueCount < (values.length / 2)) {
values = Arrays.copyOf(values, valueCount);
}
if (isDense() && singleValued()) {
block = new BooleanArrayVector(values, positionCount, blockFactory).asBlock();
block = blockFactory.newBooleanArrayVector(values, positionCount, estimatedBytes).asBlock();
} else {
block = new BooleanArrayBlock(values, positionCount, firstValueIndexes, nullsMask, mvOrdering, blockFactory);
block = blockFactory.newBooleanArrayBlock(values, positionCount, firstValueIndexes, nullsMask, mvOrdering, estimatedBytes);
}
}
/*
* Update the breaker with the actual bytes used.
* We pass false below even though we've used the bytes. That's weird,
* but if we break here we will throw away the used memory, letting
* it be deallocated. The exception will bubble up and the builder will
* still technically be open, meaning the calling code should close it
* which will return all used memory to the breaker.
*/
blockFactory.adjustBreaker(block.ramBytesUsed() - estimatedBytes, false);
built();
return block;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,13 @@ public BooleanVector build() {
finish();
BooleanVector vector;
if (valueCount == 1) {
vector = new ConstantBooleanVector(values[0], 1, blockFactory);
vector = blockFactory.newConstantBooleanBlockWith(values[0], 1, estimatedBytes).asVector();
} else {
if (values.length - valueCount > 1024 || valueCount < (values.length / 2)) {
values = Arrays.copyOf(values, valueCount);
}
vector = new BooleanArrayVector(values, valueCount, blockFactory);
vector = blockFactory.newBooleanArrayVector(values, valueCount, estimatedBytes);
}
/*
* Update the breaker with the actual bytes used.
* We pass false below even though we've used the bytes. That's weird,
* but if we break here we will throw away the used memory, letting
* it be deallocated. The exception will bubble up and the builder will
* still technically be open, meaning the calling code should close it
* which will return all used memory to the breaker.
*/
blockFactory.adjustBreaker(vector.ramBytesUsed() - estimatedBytes, false);
built();
return vector;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@
final class BooleanVectorFixedBuilder implements BooleanVector.FixedBuilder {
private final BlockFactory blockFactory;
private final boolean[] values;
private final long preAdjustedBytes;
/**
* The next value to write into. {@code -1} means the vector has already
* been built.
*/
private int nextIndex;

BooleanVectorFixedBuilder(int size, BlockFactory blockFactory) {
blockFactory.adjustBreaker(ramBytesUsed(size), false);
preAdjustedBytes = ramBytesUsed(size);
blockFactory.adjustBreaker(preAdjustedBytes, false);
this.blockFactory = blockFactory;
this.values = new boolean[size];
}
Expand Down Expand Up @@ -54,16 +56,20 @@ public BooleanVector build() {
}
nextIndex = -1;
if (values.length == 1) {
return new ConstantBooleanVector(values[0], 1, blockFactory);
return blockFactory.newConstantBooleanBlockWith(values[0], 1, preAdjustedBytes).asVector();
}
return new BooleanArrayVector(values, values.length, blockFactory);
return blockFactory.newBooleanArrayVector(values, values.length, preAdjustedBytes);
}

@Override
public void close() {
if (nextIndex >= 0) {
// If nextIndex < 0 we've already built the vector
blockFactory.adjustBreaker(-ramBytesUsed(values.length), false);
blockFactory.adjustBreaker(-preAdjustedBytes, false);
}
}

boolean isReleased() {
return nextIndex < 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,21 @@ public final class BytesRefArrayVector extends AbstractVector implements BytesRe

private final BytesRefArray values;

private final BytesRefBlock block;

public BytesRefArrayVector(BytesRefArray values, int positionCount) {
this(values, positionCount, BlockFactory.getNonBreakingInstance());
}

public BytesRefArrayVector(BytesRefArray values, int positionCount, BlockFactory blockFactory) {
super(positionCount, blockFactory);
this.values = values;
this.block = new BytesRefVectorBlock(this);
}

@Override
public BytesRefBlock asBlock() {
return new BytesRefVectorBlock(this);
return block;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ public final class ConstantBooleanVector extends AbstractVector implements Boole

private final boolean value;

private final BooleanBlock block;

public ConstantBooleanVector(boolean value, int positionCount) {
this(value, positionCount, BlockFactory.getNonBreakingInstance());
}

public ConstantBooleanVector(boolean value, int positionCount, BlockFactory blockFactory) {
super(positionCount, blockFactory);
this.value = value;
this.block = new BooleanVectorBlock(this);
}

@Override
Expand All @@ -35,7 +38,7 @@ public boolean getBoolean(int position) {

@Override
public BooleanBlock asBlock() {
return new BooleanVectorBlock(this);
return block;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ public final class ConstantBytesRefVector extends AbstractVector implements Byte
.shallowSizeOfInstance(BytesRef.class);
private final BytesRef value;

private final BytesRefBlock block;

public ConstantBytesRefVector(BytesRef value, int positionCount) {
this(value, positionCount, BlockFactory.getNonBreakingInstance());
}

public ConstantBytesRefVector(BytesRef value, int positionCount, BlockFactory blockFactory) {
super(positionCount, blockFactory);
this.value = value;
this.block = new BytesRefVectorBlock(this);
}

@Override
Expand All @@ -36,7 +39,7 @@ public BytesRef getBytesRef(int position, BytesRef ignore) {

@Override
public BytesRefBlock asBlock() {
return new BytesRefVectorBlock(this);
return block;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ public final class ConstantDoubleVector extends AbstractVector implements Double

private final double value;

private final DoubleBlock block;

public ConstantDoubleVector(double value, int positionCount) {
this(value, positionCount, BlockFactory.getNonBreakingInstance());
}

public ConstantDoubleVector(double value, int positionCount, BlockFactory blockFactory) {
super(positionCount, blockFactory);
this.value = value;
this.block = new DoubleVectorBlock(this);
}

@Override
Expand All @@ -35,7 +38,7 @@ public double getDouble(int position) {

@Override
public DoubleBlock asBlock() {
return new DoubleVectorBlock(this);
return block;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ public final class ConstantIntVector extends AbstractVector implements IntVector

private final int value;

private final IntBlock block;

public ConstantIntVector(int value, int positionCount) {
this(value, positionCount, BlockFactory.getNonBreakingInstance());
}

public ConstantIntVector(int value, int positionCount, BlockFactory blockFactory) {
super(positionCount, blockFactory);
this.value = value;
this.block = new IntVectorBlock(this);
}

@Override
Expand All @@ -35,7 +38,7 @@ public int getInt(int position) {

@Override
public IntBlock asBlock() {
return new IntVectorBlock(this);
return block;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ public final class ConstantLongVector extends AbstractVector implements LongVect

private final long value;

private final LongBlock block;

public ConstantLongVector(long value, int positionCount) {
this(value, positionCount, BlockFactory.getNonBreakingInstance());
}

public ConstantLongVector(long value, int positionCount, BlockFactory blockFactory) {
super(positionCount, blockFactory);
this.value = value;
this.block = new LongVectorBlock(this);
}

@Override
Expand All @@ -35,7 +38,7 @@ public long getLong(int position) {

@Override
public LongBlock asBlock() {
return new LongVectorBlock(this);
return block;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,21 @@ public final class DoubleArrayVector extends AbstractVector implements DoubleVec

private final double[] values;

private final DoubleBlock block;

public DoubleArrayVector(double[] values, int positionCount) {
this(values, positionCount, BlockFactory.getNonBreakingInstance());
}

public DoubleArrayVector(double[] values, int positionCount, BlockFactory blockFactory) {
super(positionCount, blockFactory);
this.values = values;
this.block = new DoubleVectorBlock(this);
}

@Override
public DoubleBlock asBlock() {
return new DoubleVectorBlock(this);
return block;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,21 @@ public final class DoubleBigArrayVector extends AbstractVector implements Double

private final DoubleArray values;

private final DoubleBlock block;

public DoubleBigArrayVector(DoubleArray values, int positionCount) {
this(values, positionCount, BlockFactory.getNonBreakingInstance());
}

public DoubleBigArrayVector(DoubleArray values, int positionCount, BlockFactory blockFactory) {
super(positionCount, blockFactory);
this.values = values;
this.block = new DoubleVectorBlock(this);
}

@Override
public DoubleBlock asBlock() {
return new DoubleVectorBlock(this);
return block;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,26 +183,17 @@ public DoubleBlock build() {
finish();
DoubleBlock block;
if (hasNonNullValue && positionCount == 1 && valueCount == 1) {
block = new ConstantDoubleVector(values[0], 1, blockFactory).asBlock();
block = blockFactory.newConstantDoubleBlockWith(values[0], 1, estimatedBytes);
} else {
if (values.length - valueCount > 1024 || valueCount < (values.length / 2)) {
values = Arrays.copyOf(values, valueCount);
}
if (isDense() && singleValued()) {
block = new DoubleArrayVector(values, positionCount, blockFactory).asBlock();
block = blockFactory.newDoubleArrayVector(values, positionCount, estimatedBytes).asBlock();
} else {
block = new DoubleArrayBlock(values, positionCount, firstValueIndexes, nullsMask, mvOrdering, blockFactory);
block = blockFactory.newDoubleArrayBlock(values, positionCount, firstValueIndexes, nullsMask, mvOrdering, estimatedBytes);
}
}
/*
* Update the breaker with the actual bytes used.
* We pass false below even though we've used the bytes. That's weird,
* but if we break here we will throw away the used memory, letting
* it be deallocated. The exception will bubble up and the builder will
* still technically be open, meaning the calling code should close it
* which will return all used memory to the breaker.
*/
blockFactory.adjustBreaker(block.ramBytesUsed() - estimatedBytes, false);
built();
return block;
}
Expand Down
Loading