Search in sources :

Example 81 with BlockBuilderStatus

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);
}
Also used : Timestamp(java.sql.Timestamp) DateTime(org.joda.time.DateTime) Block(com.facebook.presto.spi.block.Block) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus) Test(org.testng.annotations.Test)

Example 82 with BlockBuilderStatus

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

Example 83 with BlockBuilderStatus

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));
}
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 84 with BlockBuilderStatus

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

Example 85 with BlockBuilderStatus

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);
}
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)

Aggregations

BlockBuilderStatus (com.facebook.presto.spi.block.BlockBuilderStatus)227 BlockBuilder (com.facebook.presto.spi.block.BlockBuilder)210 Block (com.facebook.presto.spi.block.Block)55 Slice (io.airlift.slice.Slice)43 InterleavedBlockBuilder (com.facebook.presto.spi.block.InterleavedBlockBuilder)37 Test (org.testng.annotations.Test)35 Type (com.facebook.presto.spi.type.Type)24 SqlType (com.facebook.presto.spi.function.SqlType)20 UsedByGeneratedCode (com.facebook.presto.annotation.UsedByGeneratedCode)15 ArrayType (com.facebook.presto.type.ArrayType)14 Page (com.facebook.presto.spi.Page)12 TypeJsonUtils.appendToBlockBuilder (com.facebook.presto.type.TypeJsonUtils.appendToBlockBuilder)12 TypeParameter (com.facebook.presto.spi.function.TypeParameter)11 RowType (com.facebook.presto.type.RowType)11 OrcCorruptionException (com.facebook.presto.orc.OrcCorruptionException)10 RunLengthEncodedBlock (com.facebook.presto.spi.block.RunLengthEncodedBlock)10 MapType (com.facebook.presto.type.MapType)10 PrestoException (com.facebook.presto.spi.PrestoException)9 BlockAssertions.createLongsBlock (com.facebook.presto.block.BlockAssertions.createLongsBlock)8 DecimalType (com.facebook.presto.spi.type.DecimalType)8