use of com.facebook.presto.spi.block.BlockBuilder in project presto by prestodb.
the class TestPagesSerde method testVarcharSerializedSize.
@Test
public void testVarcharSerializedSize() {
BlockBuilder builder = VARCHAR.createBlockBuilder(new BlockBuilderStatus(), 5);
// empty page
Page page = new Page(builder.build());
int pageSize = serializedSize(ImmutableList.of(VARCHAR), page);
// page overhead
assertEquals(pageSize, 43);
// page with one value
VARCHAR.writeString(builder, "alice");
page = new Page(builder.build());
int firstValueSize = serializedSize(ImmutableList.of(VARCHAR), page) - pageSize;
// length + "alice" + null
assertEquals(firstValueSize, 4 + 5 + 1);
// page with two values
VARCHAR.writeString(builder, "bob");
page = new Page(builder.build());
int secondValueSize = serializedSize(ImmutableList.of(VARCHAR), page) - (pageSize + firstValueSize);
// length + "bob" (null shared with first entry)
assertEquals(secondValueSize, 4 + 3);
}
use of com.facebook.presto.spi.block.BlockBuilder in project presto by prestodb.
the class OperatorAssertion method toRow.
public static Block toRow(List<Type> parameterTypes, Object... values) {
checkArgument(parameterTypes.size() == values.length, "parameterTypes.size(" + parameterTypes.size() + ") does not equal to values.length(" + values.length + ")");
BlockBuilder blockBuilder = new InterleavedBlockBuilder(parameterTypes, new BlockBuilderStatus(), parameterTypes.size());
for (int i = 0; i < values.length; i++) {
appendToBlockBuilder(parameterTypes.get(i), values[i], blockBuilder);
}
return blockBuilder.build();
}
use of com.facebook.presto.spi.block.BlockBuilder in project presto by prestodb.
the class TestHashAggregationOperator method testHashBuilderResize.
@Test(dataProvider = "hashEnabledAndMemoryLimitBeforeSpillValues")
public void testHashBuilderResize(boolean hashEnabled, long memoryLimitBeforeSpill, long memoryLimitForMergeWithMemory) {
BlockBuilder builder = VARCHAR.createBlockBuilder(new BlockBuilderStatus(), 1, DEFAULT_MAX_BLOCK_SIZE_IN_BYTES);
// this must be larger than DEFAULT_MAX_BLOCK_SIZE, 64K
VARCHAR.writeSlice(builder, Slices.allocate(200_000));
builder.build();
List<Integer> hashChannels = Ints.asList(0);
RowPagesBuilder rowPagesBuilder = rowPagesBuilder(hashEnabled, hashChannels, VARCHAR);
List<Page> input = rowPagesBuilder.addSequencePage(10, 100).addBlocksPage(builder.build()).addSequencePage(10, 100).build();
DriverContext driverContext = createTaskContext(executor, TEST_SESSION, new DataSize(10, MEGABYTE)).addPipelineContext(0, true, true).addDriverContext();
HashAggregationOperatorFactory operatorFactory = new HashAggregationOperatorFactory(0, new PlanNodeId("test"), ImmutableList.of(VARCHAR), hashChannels, ImmutableList.of(), Step.SINGLE, ImmutableList.of(COUNT.bind(ImmutableList.of(0), Optional.empty())), rowPagesBuilder.getHashChannel(), Optional.empty(), 100_000, new DataSize(16, MEGABYTE), memoryLimitBeforeSpill > 0, succinctBytes(memoryLimitBeforeSpill), succinctBytes(memoryLimitForMergeWithMemory), spillerFactory, joinCompiler);
toPages(operatorFactory, driverContext, input);
}
use of com.facebook.presto.spi.block.BlockBuilder in project presto by prestodb.
the class AbstractTestApproximateCountDistinct method createBlock.
/**
* Produce a block with the given values in the last field.
*/
private static Block createBlock(Type type, List<Object> values) {
BlockBuilder blockBuilder = type.createBlockBuilder(new BlockBuilderStatus(), values.size());
for (Object value : values) {
Class<?> javaType = type.getJavaType();
if (value == null) {
blockBuilder.appendNull();
} else if (javaType == boolean.class) {
type.writeBoolean(blockBuilder, (Boolean) value);
} else if (javaType == long.class) {
type.writeLong(blockBuilder, (Long) value);
} else if (javaType == double.class) {
type.writeDouble(blockBuilder, (Double) value);
} else if (javaType == Slice.class) {
Slice slice = (Slice) value;
type.writeSlice(blockBuilder, slice, 0, slice.length());
} else {
throw new UnsupportedOperationException("not yet implemented: " + javaType);
}
}
return blockBuilder.build();
}
use of com.facebook.presto.spi.block.BlockBuilder in project presto by prestodb.
the class AggregationTestUtils method getIntermediateBlock.
public static Block getIntermediateBlock(GroupedAccumulator accumulator) {
BlockBuilder blockBuilder = accumulator.getIntermediateType().createBlockBuilder(new BlockBuilderStatus(), 1000);
accumulator.evaluateIntermediate(0, blockBuilder);
return blockBuilder.build();
}
Aggregations