use of com.facebook.presto.spi.block.BlockBuilderStatus in project presto by prestodb.
the class TestSerDeUtils method testPrimitiveSlice.
@Test
public void testPrimitiveSlice() {
// boolean
Block expectedBoolean = VARBINARY.createBlockBuilder(new BlockBuilderStatus(), 1).writeByte(1).closeEntry().build();
Block actualBoolean = toBinaryBlock(BOOLEAN, true, getInspector(Boolean.class));
assertBlockEquals(actualBoolean, expectedBoolean);
// byte
Block expectedByte = VARBINARY.createBlockBuilder(new BlockBuilderStatus(), 1).writeByte(5).closeEntry().build();
Block actualByte = toBinaryBlock(TINYINT, (byte) 5, getInspector(Byte.class));
assertBlockEquals(actualByte, expectedByte);
// short
Block expectedShort = VARBINARY.createBlockBuilder(new BlockBuilderStatus(), 1).writeShort(2).closeEntry().build();
Block actualShort = toBinaryBlock(SMALLINT, (short) 2, getInspector(Short.class));
assertBlockEquals(actualShort, expectedShort);
// int
Block expectedInt = VARBINARY.createBlockBuilder(new BlockBuilderStatus(), 1).writeInt(1).closeEntry().build();
Block actualInt = toBinaryBlock(INTEGER, 1, getInspector(Integer.class));
assertBlockEquals(actualInt, expectedInt);
// long
Block expectedLong = VARBINARY.createBlockBuilder(new BlockBuilderStatus(), 1).writeLong(10).closeEntry().build();
Block actualLong = toBinaryBlock(BIGINT, 10L, getInspector(Long.class));
assertBlockEquals(actualLong, expectedLong);
// float
Block expectedFloat = VARBINARY.createBlockBuilder(new BlockBuilderStatus(), 1).writeInt(floatToRawIntBits(20.0f)).closeEntry().build();
Block actualFloat = toBinaryBlock(REAL, 20.0f, getInspector(Float.class));
assertBlockEquals(actualFloat, expectedFloat);
// double
Block expectedDouble = VARBINARY.createBlockBuilder(new BlockBuilderStatus(), 1).writeLong(doubleToLongBits(30.12)).closeEntry().build();
Block actualDouble = toBinaryBlock(DOUBLE, 30.12d, getInspector(Double.class));
assertBlockEquals(actualDouble, expectedDouble);
// string
Block expectedString = VARBINARY.createBlockBuilder(new BlockBuilderStatus(), 1).writeBytes(utf8Slice("abdd"), 0, 4).closeEntry().build();
Block actualString = toBinaryBlock(createUnboundedVarcharType(), "abdd", getInspector(String.class));
assertBlockEquals(actualString, expectedString);
// timestamp
DateTime dateTime = new DateTime(2008, 10, 28, 16, 7, 15, 0);
Block expectedTimestamp = VARBINARY.createBlockBuilder(new BlockBuilderStatus(), 1).writeLong(dateTime.getMillis()).closeEntry().build();
Block actualTimestamp = toBinaryBlock(BIGINT, new Timestamp(dateTime.getMillis()), getInspector(Timestamp.class));
assertBlockEquals(actualTimestamp, expectedTimestamp);
// binary
byte[] byteArray = { 81, 82, 84, 85 };
Block expectedBinary = VARBINARY.createBlockBuilder(new BlockBuilderStatus(), 1).writeBytes(Slices.wrappedBuffer(byteArray), 0, 4).closeEntry().build();
Block actualBinary = toBinaryBlock(createUnboundedVarcharType(), byteArray, getInspector(byte[].class));
assertBlockEquals(actualBinary, expectedBinary);
}
use of com.facebook.presto.spi.block.BlockBuilderStatus 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.BlockBuilderStatus 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.BlockBuilderStatus 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.BlockBuilderStatus 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);
}
Aggregations