Search in sources :

Example 1 with VariableWidthBlockBuilder

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

the class TestSegmentedSliceBlockBuilder method testEqualsAndHashCode.

@Test
public void testEqualsAndHashCode() {
    SegmentedSliceBlockBuilder blockBuilder = new SegmentedSliceBlockBuilder(10, 10);
    VariableWidthBlockBuilder variableBlockBuilder = new VariableWidthBlockBuilder(null, 10, 10);
    for (int i = 0; i < SLICE.length(); i++) {
        blockBuilder.writeBytes(SLICE, i, 1);
        blockBuilder.closeEntry();
        variableBlockBuilder.writeBytes(SLICE, i, 1);
        variableBlockBuilder.closeEntry();
    }
    Block block = variableBlockBuilder.build();
    for (int i = 0; i < SLICE.length(); i++) {
        assertTrue(blockBuilder.equals(i, block, i, 1));
        assertTrue(blockBuilder.equals(i, 0, block, i, 0, 1));
        assertEquals(blockBuilder.hash(i), variableBlockBuilder.hash(i, 0, 1));
    }
}
Also used : VariableWidthBlockBuilder(com.facebook.presto.common.block.VariableWidthBlockBuilder) Block(com.facebook.presto.common.block.Block) Test(org.testng.annotations.Test)

Example 2 with VariableWidthBlockBuilder

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

the class MapFlatBatchStreamReader method getSliceKeysBlockTemplate.

private Block getSliceKeysBlockTemplate(Collection<DwrfSequenceEncoding> sequenceEncodings) {
    int bytes = 0;
    for (DwrfSequenceEncoding sequenceEncoding : sequenceEncodings) {
        bytes += sequenceEncoding.getKey().getBytesKey().size();
    }
    VariableWidthBlockBuilder builder = new VariableWidthBlockBuilder(null, sequenceEncodings.size(), bytes);
    for (DwrfSequenceEncoding sequenceEncoding : sequenceEncodings) {
        Slice key = Slices.wrappedBuffer(sequenceEncoding.getKey().getBytesKey().toByteArray());
        builder.writeBytes(key, 0, key.length());
        builder.closeEntry();
    }
    return builder.build();
}
Also used : VariableWidthBlockBuilder(com.facebook.presto.common.block.VariableWidthBlockBuilder) Slice(io.airlift.slice.Slice) DwrfSequenceEncoding(com.facebook.presto.orc.metadata.DwrfSequenceEncoding)

Example 3 with VariableWidthBlockBuilder

use of com.facebook.presto.common.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(null, 1, slice.length());
    TYPE.writeSlice(blockBuilder, slice);
    return blockBuilder.build();
}
Also used : VariableWidthBlockBuilder(com.facebook.presto.common.block.VariableWidthBlockBuilder) Slice(io.airlift.slice.Slice) BigDecimal(java.math.BigDecimal) BlockBuilder(com.facebook.presto.common.block.BlockBuilder) VariableWidthBlockBuilder(com.facebook.presto.common.block.VariableWidthBlockBuilder)

Example 4 with VariableWidthBlockBuilder

use of com.facebook.presto.common.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(null, numEntries, 20 * numEntries);
    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);
    long sizeInBytes = block.getSizeInBytes();
    long quarter1size = splitQuarter.get(0).getSizeInBytes();
    long quarter2size = splitQuarter.get(1).getSizeInBytes();
    long quarter3size = splitQuarter.get(2).getSizeInBytes();
    long 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.common.block.VariableWidthBlockBuilder) VarcharType.createUnboundedVarcharType(com.facebook.presto.common.type.VarcharType.createUnboundedVarcharType) VarcharType(com.facebook.presto.common.type.VarcharType) VariableWidthBlock(com.facebook.presto.common.block.VariableWidthBlock) Block(com.facebook.presto.common.block.Block) Test(org.testng.annotations.Test)

Example 5 with VariableWidthBlockBuilder

use of com.facebook.presto.common.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(state, new VariableWidthBlockBuilder(null, 10, 100));
}
Also used : VariableWidthBlockBuilder(com.facebook.presto.common.block.VariableWidthBlockBuilder) Test(org.testng.annotations.Test)

Aggregations

VariableWidthBlockBuilder (com.facebook.presto.common.block.VariableWidthBlockBuilder)10 Slice (io.airlift.slice.Slice)6 Test (org.testng.annotations.Test)6 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)5 Block (com.facebook.presto.common.block.Block)2 LongArrayBlockBuilder (com.facebook.presto.common.block.LongArrayBlockBuilder)2 DwrfSequenceEncoding (com.facebook.presto.orc.metadata.DwrfSequenceEncoding)2 ByteArrayBlockBuilder (com.facebook.presto.common.block.ByteArrayBlockBuilder)1 Int128ArrayBlockBuilder (com.facebook.presto.common.block.Int128ArrayBlockBuilder)1 IntArrayBlockBuilder (com.facebook.presto.common.block.IntArrayBlockBuilder)1 ShortArrayBlockBuilder (com.facebook.presto.common.block.ShortArrayBlockBuilder)1 VariableWidthBlock (com.facebook.presto.common.block.VariableWidthBlock)1 VarcharType (com.facebook.presto.common.type.VarcharType)1 VarcharType.createUnboundedVarcharType (com.facebook.presto.common.type.VarcharType.createUnboundedVarcharType)1 BigDecimal (java.math.BigDecimal)1