use of com.facebook.presto.spi.block.InterleavedBlockBuilder in project presto by prestodb.
the class MapConstructor method createMap.
@UsedByGeneratedCode
public static Block createMap(MapType mapType, Block keyBlock, Block valueBlock) {
BlockBuilder blockBuilder = new InterleavedBlockBuilder(mapType.getTypeParameters(), new BlockBuilderStatus(), keyBlock.getPositionCount() * 2);
checkCondition(keyBlock.getPositionCount() == valueBlock.getPositionCount(), INVALID_FUNCTION_ARGUMENT, "Key and value arrays must be the same length");
for (int i = 0; i < keyBlock.getPositionCount(); i++) {
if (keyBlock.isNull(i)) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "map key cannot be null");
}
mapType.getKeyType().appendTo(keyBlock, i, blockBuilder);
mapType.getValueType().appendTo(valueBlock, i, blockBuilder);
}
return blockBuilder.build();
}
use of com.facebook.presto.spi.block.InterleavedBlockBuilder in project presto by prestodb.
the class TestInterleavedBlock method assertValues.
private void assertValues(Slice[] expectedValues) {
InterleavedBlockBuilder blockBuilder = createBlockBuilderWithValues(expectedValues);
assertBlock(blockBuilder, expectedValues);
assertBlock(blockBuilder.build(), expectedValues);
}
use of com.facebook.presto.spi.block.InterleavedBlockBuilder in project presto by prestodb.
the class TestInterleavedBlock method testCopyPositions.
@Test
public void testCopyPositions() {
Slice[] expectedValues = createExpectedValues();
InterleavedBlockBuilder blockBuilder = createBlockBuilderWithValues(expectedValues);
assertBlockFilteredPositions(expectedValues, blockBuilder, Ints.asList(0, 1, 4, 5, 6, 7, 14, 15));
assertBlockFilteredPositions(expectedValues, blockBuilder.build(), Ints.asList(0, 1, 4, 5, 6, 7, 14, 15));
assertBlockFilteredPositions(expectedValues, blockBuilder.build(), Ints.asList(2, 3, 4, 5, 8, 9, 12, 13));
}
use of com.facebook.presto.spi.block.InterleavedBlockBuilder 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.InterleavedBlockBuilder in project presto by prestodb.
the class TestStateCompiler method testComplexSerialization.
@Test
public void testComplexSerialization() {
Type arrayType = new ArrayType(BIGINT);
Type mapType = new MapType(BIGINT, VARCHAR);
Map<String, Type> fieldMap = ImmutableMap.of("Block", arrayType, "AnotherBlock", mapType);
AccumulatorStateFactory<TestComplexState> factory = StateCompiler.generateStateFactory(TestComplexState.class, fieldMap, new DynamicClassLoader(TestComplexState.class.getClassLoader()));
AccumulatorStateSerializer<TestComplexState> serializer = StateCompiler.generateStateSerializer(TestComplexState.class, fieldMap, new DynamicClassLoader(TestComplexState.class.getClassLoader()));
TestComplexState singleState = factory.createSingleState();
TestComplexState deserializedState = factory.createSingleState();
singleState.setBoolean(true);
singleState.setLong(1);
singleState.setDouble(2.0);
singleState.setByte((byte) 3);
singleState.setSlice(utf8Slice("test"));
singleState.setAnotherSlice(wrappedDoubleArray(1.0, 2.0, 3.0));
singleState.setYetAnotherSlice(null);
Block array = createLongsBlock(45);
singleState.setBlock(array);
BlockBuilder mapBlockBuilder = new InterleavedBlockBuilder(ImmutableList.of(BIGINT, VARCHAR), new BlockBuilderStatus(), 1);
BIGINT.writeLong(mapBlockBuilder, 123L);
VARCHAR.writeSlice(mapBlockBuilder, utf8Slice("testBlock"));
Block map = mapBlockBuilder.build();
singleState.setAnotherBlock(map);
BlockBuilder builder = new RowType(ImmutableList.of(BOOLEAN, TINYINT, DOUBLE, BIGINT, mapType, VARBINARY, arrayType, VARBINARY, VARBINARY), Optional.empty()).createBlockBuilder(new BlockBuilderStatus(), 1);
serializer.serialize(singleState, builder);
Block block = builder.build();
serializer.deserialize(block, 0, deserializedState);
assertEquals(deserializedState.getBoolean(), singleState.getBoolean());
assertEquals(deserializedState.getLong(), singleState.getLong());
assertEquals(deserializedState.getDouble(), singleState.getDouble());
assertEquals(deserializedState.getByte(), singleState.getByte());
assertEquals(deserializedState.getSlice(), singleState.getSlice());
assertEquals(deserializedState.getAnotherSlice(), singleState.getAnotherSlice());
assertEquals(deserializedState.getYetAnotherSlice(), singleState.getYetAnotherSlice());
assertEquals(deserializedState.getBlock().getLong(0, 0), singleState.getBlock().getLong(0, 0));
assertEquals(deserializedState.getAnotherBlock().getLong(0, 0), singleState.getAnotherBlock().getLong(0, 0));
assertEquals(deserializedState.getAnotherBlock().getSlice(1, 0, 9), singleState.getAnotherBlock().getSlice(1, 0, 9));
}
Aggregations