Search in sources :

Example 1 with VariableWidthBlockBuilder

use of com.facebook.presto.spi.block.VariableWidthBlockBuilder 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 2 with VariableWidthBlockBuilder

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

the class TestLongDecimalType method decimalAsBlock.

private Block decimalAsBlock(String value) {
    Slice slice = encodeScaledValue(new BigDecimal(value));
    BlockBuilder blockBuilder = new VariableWidthBlockBuilder(new BlockBuilderStatus(), 1, slice.length());
    TYPE.writeSlice(blockBuilder, slice);
    return blockBuilder.build();
}
Also used : VariableWidthBlockBuilder(com.facebook.presto.spi.block.VariableWidthBlockBuilder) Slice(io.airlift.slice.Slice) BigDecimal(java.math.BigDecimal) VariableWidthBlockBuilder(com.facebook.presto.spi.block.VariableWidthBlockBuilder) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus)

Example 3 with VariableWidthBlockBuilder

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

the class TestDecimalSumAggregation method testOverflowOnOutput.

@Test(expectedExceptions = ArithmeticException.class)
public void testOverflowOnOutput() {
    addToState(state, TWO.pow(126));
    addToState(state, TWO.pow(126));
    assertEquals(state.getOverflow(), 1);
    DecimalSumAggregation.outputLongDecimal(TYPE, state, new VariableWidthBlockBuilder(new BlockBuilderStatus(), 10, 10));
}
Also used : VariableWidthBlockBuilder(com.facebook.presto.spi.block.VariableWidthBlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus) Test(org.testng.annotations.Test)

Example 4 with VariableWidthBlockBuilder

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

the class TestRunLengthEncodedBlock method createSingleValueBlock.

private static Block createSingleValueBlock(Slice expectedValue) {
    BlockBuilder blockBuilder = new VariableWidthBlockBuilder(new BlockBuilderStatus(), 1, expectedValue.length());
    blockBuilder.writeBytes(expectedValue, 0, expectedValue.length()).closeEntry();
    return blockBuilder.build();
}
Also used : VariableWidthBlockBuilder(com.facebook.presto.spi.block.VariableWidthBlockBuilder) VariableWidthBlockBuilder(com.facebook.presto.spi.block.VariableWidthBlockBuilder) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus)

Aggregations

BlockBuilderStatus (com.facebook.presto.spi.block.BlockBuilderStatus)4 VariableWidthBlockBuilder (com.facebook.presto.spi.block.VariableWidthBlockBuilder)4 BlockBuilder (com.facebook.presto.spi.block.BlockBuilder)2 Test (org.testng.annotations.Test)2 Block (com.facebook.presto.spi.block.Block)1 VarcharType (com.facebook.presto.spi.type.VarcharType)1 VarcharType.createUnboundedVarcharType (com.facebook.presto.spi.type.VarcharType.createUnboundedVarcharType)1 Slice (io.airlift.slice.Slice)1 BigDecimal (java.math.BigDecimal)1