use of com.facebook.presto.spi.block.BlockBuilder in project presto by prestodb.
the class AbstractTestType method toBlock.
private Block toBlock(Object value) {
BlockBuilder blockBuilder = type.createBlockBuilder(new BlockBuilderStatus(), 1);
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 {
type.writeObject(blockBuilder, value);
}
return blockBuilder.build();
}
use of com.facebook.presto.spi.block.BlockBuilder in project presto by prestodb.
the class TestArrayOperators method assertArrayHashOperator.
private void assertArrayHashOperator(String inputArray, Type elementType, List<Object> elements) {
ArrayType arrayType = new ArrayType(elementType);
BlockBuilder arrayArrayBuilder = arrayType.createBlockBuilder(new BlockBuilderStatus(), 1);
BlockBuilder arrayBuilder = elementType.createBlockBuilder(new BlockBuilderStatus(), elements.size());
for (Object element : elements) {
appendToBlockBuilder(elementType, element, arrayBuilder);
}
arrayType.writeObject(arrayArrayBuilder, arrayBuilder.build());
assertOperator(HASH_CODE, inputArray, BIGINT, arrayType.hash(arrayArrayBuilder.build(), 0));
}
use of com.facebook.presto.spi.block.BlockBuilder in project presto by prestodb.
the class TestBigintArrayType method getGreaterValue.
@Override
protected Object getGreaterValue(Object value) {
Block block = (Block) value;
BlockBuilder blockBuilder = BIGINT.createBlockBuilder(new BlockBuilderStatus(), block.getPositionCount() + 1);
for (int i = 0; i < block.getPositionCount(); i++) {
BIGINT.appendTo(block, i, blockBuilder);
}
BIGINT.writeLong(blockBuilder, 1L);
return blockBuilder.build();
}
use of com.facebook.presto.spi.block.BlockBuilder in project presto by prestodb.
the class TestMapOperators method assertMapHashOperator.
private void assertMapHashOperator(String inputString, Type keyType, Type valueType, List<Object> elements) {
checkArgument(elements.size() % 2 == 0, "the size of elements should be even number");
MapType mapType = new MapType(keyType, valueType);
BlockBuilder mapArrayBuilder = mapType.createBlockBuilder(new BlockBuilderStatus(), 1);
BlockBuilder mapBuilder = new InterleavedBlockBuilder(ImmutableList.of(keyType, valueType), new BlockBuilderStatus(), elements.size());
for (int i = 0; i < elements.size(); i += 2) {
appendToBlockBuilder(keyType, elements.get(i), mapBuilder);
appendToBlockBuilder(valueType, elements.get(i + 1), mapBuilder);
}
mapType.writeObject(mapArrayBuilder, mapBuilder.build());
long hashResult = mapType.hash(mapArrayBuilder.build(), 0);
assertOperator(HASH_CODE, inputString, BIGINT, hashResult);
}
use of com.facebook.presto.spi.block.BlockBuilder in project presto by prestodb.
the class TestRealType method createTestBlock.
public static Block createTestBlock() {
BlockBuilder blockBuilder = REAL.createBlockBuilder(new BlockBuilderStatus(), 30);
REAL.writeLong(blockBuilder, floatToRawIntBits(11.11F));
REAL.writeLong(blockBuilder, floatToRawIntBits(11.11F));
REAL.writeLong(blockBuilder, floatToRawIntBits(11.11F));
REAL.writeLong(blockBuilder, floatToRawIntBits(22.22F));
REAL.writeLong(blockBuilder, floatToRawIntBits(22.22F));
REAL.writeLong(blockBuilder, floatToRawIntBits(22.22F));
REAL.writeLong(blockBuilder, floatToRawIntBits(22.22F));
REAL.writeLong(blockBuilder, floatToRawIntBits(22.22F));
REAL.writeLong(blockBuilder, floatToRawIntBits(33.33F));
REAL.writeLong(blockBuilder, floatToRawIntBits(33.33F));
REAL.writeLong(blockBuilder, floatToRawIntBits(44.44F));
return blockBuilder.build();
}
Aggregations