Search in sources :

Example 11 with BlockBuilderStatus

use of com.facebook.presto.spi.block.BlockBuilderStatus in project presto by prestodb.

the class BlockAssertions method createArrayBigintBlock.

public static Block createArrayBigintBlock(Iterable<? extends Iterable<Long>> values) {
    ArrayType arrayType = new ArrayType(BIGINT);
    BlockBuilder builder = arrayType.createBlockBuilder(new BlockBuilderStatus(), 100);
    for (Iterable<Long> value : values) {
        if (value == null) {
            builder.appendNull();
        } else {
            arrayType.writeObject(builder, createLongsBlock(value));
        }
    }
    return builder.build();
}
Also used : ArrayType(com.facebook.presto.type.ArrayType) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus)

Example 12 with BlockBuilderStatus

use of com.facebook.presto.spi.block.BlockBuilderStatus in project presto by prestodb.

the class TestArrayBlock method createBlockBuilderWithValues.

private static BlockBuilder createBlockBuilderWithValues(Slice[][] expectedValues) {
    BlockBuilder blockBuilder = new ArrayBlockBuilder(VARCHAR, new BlockBuilderStatus(), 100, 100);
    for (Slice[] expectedValue : expectedValues) {
        if (expectedValue == null) {
            blockBuilder.appendNull();
        } else {
            BlockBuilder elementBlockBuilder = VARCHAR.createBlockBuilder(new BlockBuilderStatus(), expectedValue.length);
            for (Slice v : expectedValue) {
                VARCHAR.writeSlice(elementBlockBuilder, v);
            }
            blockBuilder.writeObject(elementBlockBuilder.build()).closeEntry();
        }
    }
    return blockBuilder;
}
Also used : ArrayBlockBuilder(com.facebook.presto.spi.block.ArrayBlockBuilder) Slice(io.airlift.slice.Slice) ArrayBlockBuilder(com.facebook.presto.spi.block.ArrayBlockBuilder) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus)

Example 13 with BlockBuilderStatus

use of com.facebook.presto.spi.block.BlockBuilderStatus in project presto by prestodb.

the class TestArrayBlock method createBlockBuilderWithValues.

private static BlockBuilder createBlockBuilderWithValues(long[][][] expectedValues) {
    BlockBuilder blockBuilder = new ArrayBlockBuilder(new ArrayBlockBuilder(BIGINT, new BlockBuilderStatus(), 100, 100), new BlockBuilderStatus(), 100);
    for (long[][] expectedValue : expectedValues) {
        if (expectedValue == null) {
            blockBuilder.appendNull();
        } else {
            BlockBuilder intermediateBlockBuilder = new ArrayBlockBuilder(BIGINT, new BlockBuilderStatus(), 100, 100);
            for (int j = 0; j < expectedValue.length; j++) {
                if (expectedValue[j] == null) {
                    intermediateBlockBuilder.appendNull();
                } else {
                    BlockBuilder innerMostBlockBuilder = BIGINT.createBlockBuilder(new BlockBuilderStatus(), expectedValue.length);
                    for (long v : expectedValue[j]) {
                        BIGINT.writeLong(innerMostBlockBuilder, v);
                    }
                    intermediateBlockBuilder.writeObject(innerMostBlockBuilder.build()).closeEntry();
                }
            }
            blockBuilder.writeObject(intermediateBlockBuilder.build()).closeEntry();
        }
    }
    return blockBuilder;
}
Also used : ArrayBlockBuilder(com.facebook.presto.spi.block.ArrayBlockBuilder) ArrayBlockBuilder(com.facebook.presto.spi.block.ArrayBlockBuilder) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus)

Example 14 with BlockBuilderStatus

use of com.facebook.presto.spi.block.BlockBuilderStatus in project presto by prestodb.

the class TestVariableWidthBlock method testGetSizeInBytes.

@Test
private void testGetSizeInBytes() {
    int numEntries = 1000;
    VarcharType unboundedVarcharType = createUnboundedVarcharType();
    VariableWidthBlockBuilder blockBuilder = new VariableWidthBlockBuilder(new BlockBuilderStatus(), numEntries, 20);
    for (int i = 0; i < numEntries; i++) {
        unboundedVarcharType.writeString(blockBuilder, String.valueOf(ThreadLocalRandom.current().nextLong()));
    }
    Block block = blockBuilder.build();
    List<Block> splitQuarter = splitBlock(block, 4);
    int sizeInBytes = block.getSizeInBytes();
    int quarter1size = splitQuarter.get(0).getSizeInBytes();
    int quarter2size = splitQuarter.get(1).getSizeInBytes();
    int quarter3size = splitQuarter.get(2).getSizeInBytes();
    int quarter4size = splitQuarter.get(3).getSizeInBytes();
    double expectedQuarterSizeMin = sizeInBytes * 0.2;
    double expectedQuarterSizeMax = sizeInBytes * 0.3;
    assertTrue(quarter1size > expectedQuarterSizeMin && quarter1size < expectedQuarterSizeMax, format("quarter1size is %s, should be between %s and %s", quarter1size, expectedQuarterSizeMin, expectedQuarterSizeMax));
    assertTrue(quarter2size > expectedQuarterSizeMin && quarter2size < expectedQuarterSizeMax, format("quarter2size is %s, should be between %s and %s", quarter2size, expectedQuarterSizeMin, expectedQuarterSizeMax));
    assertTrue(quarter3size > expectedQuarterSizeMin && quarter3size < expectedQuarterSizeMax, format("quarter3size is %s, should be between %s and %s", quarter3size, expectedQuarterSizeMin, expectedQuarterSizeMax));
    assertTrue(quarter4size > expectedQuarterSizeMin && quarter4size < expectedQuarterSizeMax, format("quarter4size is %s, should be between %s and %s", quarter4size, expectedQuarterSizeMin, expectedQuarterSizeMax));
    assertEquals(quarter1size + quarter2size + quarter3size + quarter4size, sizeInBytes);
}
Also used : VariableWidthBlockBuilder(com.facebook.presto.spi.block.VariableWidthBlockBuilder) VarcharType.createUnboundedVarcharType(com.facebook.presto.spi.type.VarcharType.createUnboundedVarcharType) VarcharType(com.facebook.presto.spi.type.VarcharType) Block(com.facebook.presto.spi.block.Block) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus) Test(org.testng.annotations.Test)

Example 15 with BlockBuilderStatus

use of com.facebook.presto.spi.block.BlockBuilderStatus in project presto by prestodb.

the class TestBlockBuilder method testMultipleValuesWithNull.

@Test
public void testMultipleValuesWithNull() {
    BlockBuilder blockBuilder = BIGINT.createBlockBuilder(new BlockBuilderStatus(), 10);
    blockBuilder.appendNull();
    BIGINT.writeLong(blockBuilder, 42);
    blockBuilder.appendNull();
    BIGINT.writeLong(blockBuilder, 42);
    Block block = blockBuilder.build();
    assertTrue(block.isNull(0));
    assertEquals(BIGINT.getLong(block, 1), 42L);
    assertTrue(block.isNull(2));
    assertEquals(BIGINT.getLong(block, 3), 42L);
}
Also used : Block(com.facebook.presto.spi.block.Block) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus) Test(org.testng.annotations.Test)

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