use of com.facebook.presto.spi.block.BlockBuilder in project presto by prestodb.
the class TypeUtils method getHashBlock.
public static Block getHashBlock(List<? extends Type> hashTypes, Block... hashBlocks) {
checkArgument(hashTypes.size() == hashBlocks.length);
int[] hashChannels = new int[hashBlocks.length];
for (int i = 0; i < hashBlocks.length; i++) {
hashChannels[i] = i;
}
HashGenerator hashGenerator = new InterpretedHashGenerator(ImmutableList.copyOf(hashTypes), hashChannels);
int positionCount = hashBlocks[0].getPositionCount();
BlockBuilder builder = BIGINT.createFixedSizeBlockBuilder(positionCount);
Page page = new Page(hashBlocks);
for (int i = 0; i < positionCount; i++) {
BIGINT.writeLong(builder, hashGenerator.hashPosition(i, page));
}
return builder.build();
}
use of com.facebook.presto.spi.block.BlockBuilder in project presto by prestodb.
the class MaterializedResult method appendToPage.
private static void appendToPage(PageBuilder pageBuilder, MaterializedRow row) {
for (int field = 0; field < row.getFieldCount(); field++) {
Type type = pageBuilder.getType(field);
Object value = row.getField(field);
BlockBuilder blockBuilder = pageBuilder.getBlockBuilder(field);
writeValue(type, blockBuilder, value);
}
pageBuilder.declarePosition();
}
use of com.facebook.presto.spi.block.BlockBuilder in project presto by prestodb.
the class RowPageBuilder method append.
private void append(int channel, Object element) {
BlockBuilder blockBuilder = builders.get(channel);
Type type = types.get(channel);
appendToBlockBuilder(type, element, blockBuilder);
}
use of com.facebook.presto.spi.block.BlockBuilder in project presto by prestodb.
the class BlockAssertions method createRLEBlock.
public static RunLengthEncodedBlock createRLEBlock(double value, int positionCount) {
BlockBuilder blockBuilder = DOUBLE.createBlockBuilder(new BlockBuilderStatus(), 1);
DOUBLE.writeDouble(blockBuilder, value);
return new RunLengthEncodedBlock(blockBuilder.build(), positionCount);
}
use of com.facebook.presto.spi.block.BlockBuilder in project presto by prestodb.
the class BlockAssertions method createShortDecimalsBlock.
public static Block createShortDecimalsBlock(Iterable<String> values) {
DecimalType shortDecimalType = DecimalType.createDecimalType(1);
BlockBuilder builder = shortDecimalType.createBlockBuilder(new BlockBuilderStatus(), 100);
for (String value : values) {
if (value == null) {
builder.appendNull();
} else {
shortDecimalType.writeLong(builder, new BigDecimal(value).unscaledValue().longValue());
}
}
return builder.build();
}
Aggregations