Search in sources :

Example 6 with BlockBuilder

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();
}
Also used : Slice(io.airlift.slice.Slice) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus)

Example 7 with BlockBuilder

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));
}
Also used : TypeJsonUtils.appendToBlockBuilder(com.facebook.presto.type.TypeJsonUtils.appendToBlockBuilder) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) InterleavedBlockBuilder(com.facebook.presto.spi.block.InterleavedBlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus)

Example 8 with BlockBuilder

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();
}
Also used : Block(com.facebook.presto.spi.block.Block) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus)

Example 9 with BlockBuilder

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);
}
Also used : InterleavedBlockBuilder(com.facebook.presto.spi.block.InterleavedBlockBuilder) TypeJsonUtils.appendToBlockBuilder(com.facebook.presto.type.TypeJsonUtils.appendToBlockBuilder) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) InterleavedBlockBuilder(com.facebook.presto.spi.block.InterleavedBlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus)

Example 10 with BlockBuilder

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();
}
Also used : BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus)

Aggregations

BlockBuilder (com.facebook.presto.spi.block.BlockBuilder)290 BlockBuilderStatus (com.facebook.presto.spi.block.BlockBuilderStatus)211 Block (com.facebook.presto.spi.block.Block)56 Slice (io.airlift.slice.Slice)53 InterleavedBlockBuilder (com.facebook.presto.spi.block.InterleavedBlockBuilder)39 Test (org.testng.annotations.Test)38 Type (com.facebook.presto.spi.type.Type)33 SqlType (com.facebook.presto.spi.function.SqlType)24 ArrayType (com.facebook.presto.type.ArrayType)19 Page (com.facebook.presto.spi.Page)18 UsedByGeneratedCode (com.facebook.presto.annotation.UsedByGeneratedCode)17 TypeParameter (com.facebook.presto.spi.function.TypeParameter)15 MapType (com.facebook.presto.type.MapType)14 RowType (com.facebook.presto.type.RowType)14 TypeJsonUtils.appendToBlockBuilder (com.facebook.presto.type.TypeJsonUtils.appendToBlockBuilder)13 PageBuilder (com.facebook.presto.spi.PageBuilder)12 ImmutableList (com.google.common.collect.ImmutableList)12 PrestoException (com.facebook.presto.spi.PrestoException)11 RunLengthEncodedBlock (com.facebook.presto.spi.block.RunLengthEncodedBlock)11 DictionaryBlock (com.facebook.presto.spi.block.DictionaryBlock)10