Skip to content

Commit

Permalink
assert exact estimate in fixed vector builders
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisHegarty committed Oct 2, 2023
1 parent 760a6cf commit d46f1a0
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,14 @@ public BooleanVector build() {
throw new IllegalStateException("expected to write [" + values.length + "] entries but wrote [" + nextIndex + "]");
}
nextIndex = -1;
BooleanVector vector;
if (values.length == 1) {
return blockFactory.newConstantBooleanBlockWith(values[0], 1, preAdjustedBytes).asVector();
vector = blockFactory.newConstantBooleanBlockWith(values[0], 1, preAdjustedBytes).asVector();
} else {
vector = blockFactory.newBooleanArrayVector(values, values.length, preAdjustedBytes);
}
return blockFactory.newBooleanArrayVector(values, values.length, preAdjustedBytes);
assert vector.ramBytesUsed() == preAdjustedBytes : "fixed Builders should estimate the exact ram bytes used";
return vector;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,14 @@ public DoubleVector build() {
throw new IllegalStateException("expected to write [" + values.length + "] entries but wrote [" + nextIndex + "]");
}
nextIndex = -1;
DoubleVector vector;
if (values.length == 1) {
return blockFactory.newConstantDoubleBlockWith(values[0], 1, preAdjustedBytes).asVector();
vector = blockFactory.newConstantDoubleBlockWith(values[0], 1, preAdjustedBytes).asVector();
} else {
vector = blockFactory.newDoubleArrayVector(values, values.length, preAdjustedBytes);
}
return blockFactory.newDoubleArrayVector(values, values.length, preAdjustedBytes);
assert vector.ramBytesUsed() == preAdjustedBytes : "fixed Builders should estimate the exact ram bytes used";
return vector;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,14 @@ public IntVector build() {
throw new IllegalStateException("expected to write [" + values.length + "] entries but wrote [" + nextIndex + "]");
}
nextIndex = -1;
IntVector vector;
if (values.length == 1) {
return blockFactory.newConstantIntBlockWith(values[0], 1, preAdjustedBytes).asVector();
vector = blockFactory.newConstantIntBlockWith(values[0], 1, preAdjustedBytes).asVector();
} else {
vector = blockFactory.newIntArrayVector(values, values.length, preAdjustedBytes);
}
return blockFactory.newIntArrayVector(values, values.length, preAdjustedBytes);
assert vector.ramBytesUsed() == preAdjustedBytes : "fixed Builders should estimate the exact ram bytes used";
return vector;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,14 @@ public LongVector build() {
throw new IllegalStateException("expected to write [" + values.length + "] entries but wrote [" + nextIndex + "]");
}
nextIndex = -1;
LongVector vector;
if (values.length == 1) {
return blockFactory.newConstantLongBlockWith(values[0], 1, preAdjustedBytes).asVector();
vector = blockFactory.newConstantLongBlockWith(values[0], 1, preAdjustedBytes).asVector();
} else {
vector = blockFactory.newLongArrayVector(values, values.length, preAdjustedBytes);
}
return blockFactory.newLongArrayVector(values, values.length, preAdjustedBytes);
assert vector.ramBytesUsed() == preAdjustedBytes : "fixed Builders should estimate the exact ram bytes used";
return vector;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ private IntVector add(BytesRefVector vector) {
}

private IntBlock add(BytesRefBlock block) {
MultivalueDedupe.HashResult result = new MultivalueDedupeBytesRef(Block.Ref.floating(block)).hash(bytesRefHash); // TODO: block
// factory
// TODO: use block factory
MultivalueDedupe.HashResult result = new MultivalueDedupeBytesRef(Block.Ref.floating(block)).hash(bytesRefHash);
seenNull |= result.sawNull();
return result.ords();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,14 @@ final class $Type$VectorFixedBuilder implements $Type$Vector.FixedBuilder {
throw new IllegalStateException("expected to write [" + values.length + "] entries but wrote [" + nextIndex + "]");
}
nextIndex = -1;
$Type$Vector vector;
if (values.length == 1) {
return blockFactory.newConstant$Type$BlockWith(values[0], 1, preAdjustedBytes).asVector();
vector = blockFactory.newConstant$Type$BlockWith(values[0], 1, preAdjustedBytes).asVector();
} else {
vector = blockFactory.new$Type$ArrayVector(values, values.length, preAdjustedBytes);
}
return blockFactory.new$Type$ArrayVector(values, values.length, preAdjustedBytes);
assert vector.ramBytesUsed() == preAdjustedBytes : "fixed Builders should estimate the exact ram bytes used";
return vector;
}

@Override
Expand Down

0 comments on commit d46f1a0

Please sign in to comment.