Search in sources :

Example 16 with SliceOutput

use of io.airlift.slice.SliceOutput in project presto by prestodb.

the class FeatureUnitNormalizer method getSerializedData.

@Override
public byte[] getSerializedData() {
    // Serialization format is (<key:int><min:double><max:double>)*
    SliceOutput output = Slices.allocate((SizeOf.SIZE_OF_INT + 2 * SizeOf.SIZE_OF_DOUBLE) * mins.size()).getOutput();
    for (int key : mins.keySet()) {
        output.appendInt(key);
        output.appendDouble(mins.get(key));
        output.appendDouble(maxs.get(key));
    }
    return output.slice().getBytes();
}
Also used : SliceOutput(io.airlift.slice.SliceOutput)

Example 17 with SliceOutput

use of io.airlift.slice.SliceOutput in project presto by prestodb.

the class VariableWidthBlockBuilder method copyPositions.

@Override
public Block copyPositions(List<Integer> positions) {
    int finalLength = positions.stream().mapToInt(this::getSliceLength).sum();
    SliceOutput newSlice = Slices.allocate(finalLength).getOutput();
    int[] newOffsets = new int[positions.size() + 1];
    boolean[] newValueIsNull = new boolean[positions.size()];
    for (int i = 0; i < positions.size(); i++) {
        int position = positions.get(i);
        if (isEntryNull(position)) {
            newValueIsNull[i] = true;
        } else {
            newSlice.appendBytes(sliceOutput.getUnderlyingSlice().getBytes(getPositionOffset(position), getSliceLength(position)));
        }
        newOffsets[i + 1] = newSlice.size();
    }
    return new VariableWidthBlock(positions.size(), newSlice.slice(), newOffsets, newValueIsNull);
}
Also used : SliceOutput(io.airlift.slice.SliceOutput) DynamicSliceOutput(io.airlift.slice.DynamicSliceOutput)

Example 18 with SliceOutput

use of io.airlift.slice.SliceOutput in project presto by prestodb.

the class FixedWidthBlock method copyPositions.

@Override
public Block copyPositions(List<Integer> positions) {
    checkValidPositions(positions, positionCount);
    SliceOutput newSlice = Slices.allocate(positions.size() * fixedSize).getOutput();
    SliceOutput newValueIsNull = Slices.allocate(positions.size()).getOutput();
    for (int position : positions) {
        newSlice.writeBytes(slice, position * fixedSize, fixedSize);
        newValueIsNull.writeByte(valueIsNull.getByte(position));
    }
    return new FixedWidthBlock(fixedSize, positions.size(), newSlice.slice(), newValueIsNull.slice());
}
Also used : SliceOutput(io.airlift.slice.SliceOutput)

Example 19 with SliceOutput

use of io.airlift.slice.SliceOutput in project presto by prestodb.

the class FixedWidthBlockBuilder method copyPositions.

@Override
public Block copyPositions(List<Integer> positions) {
    checkValidPositions(positions, positionCount);
    SliceOutput newSlice = Slices.allocate(positions.size() * fixedSize).getOutput();
    SliceOutput newValueIsNull = Slices.allocate(positions.size()).getOutput();
    for (int position : positions) {
        newValueIsNull.appendByte(valueIsNull.getUnderlyingSlice().getByte(position));
        newSlice.appendBytes(getRawSlice().getBytes(position * fixedSize, fixedSize));
    }
    return new FixedWidthBlock(fixedSize, positions.size(), newSlice.slice(), newValueIsNull.slice());
}
Also used : SliceOutput(io.airlift.slice.SliceOutput) DynamicSliceOutput(io.airlift.slice.DynamicSliceOutput)

Example 20 with SliceOutput

use of io.airlift.slice.SliceOutput in project presto by prestodb.

the class AbstractTestHiveFileFormats method blockToSlice.

private static Slice blockToSlice(Block block) {
    // This function is strictly for testing use only
    SliceOutput sliceOutput = new DynamicSliceOutput(1000);
    BlockSerdeUtil.writeBlock(sliceOutput, block.copyRegion(0, block.getPositionCount()));
    return sliceOutput.slice();
}
Also used : SliceOutput(io.airlift.slice.SliceOutput) DynamicSliceOutput(io.airlift.slice.DynamicSliceOutput) DynamicSliceOutput(io.airlift.slice.DynamicSliceOutput)

Aggregations

SliceOutput (io.airlift.slice.SliceOutput)21 DynamicSliceOutput (io.airlift.slice.DynamicSliceOutput)11 Slice (io.airlift.slice.Slice)9 Test (org.testng.annotations.Test)3 Block (com.facebook.presto.spi.block.Block)2 LiteralParameters (com.facebook.presto.spi.function.LiteralParameters)2 ScalarFunction (com.facebook.presto.spi.function.ScalarFunction)2 SqlType (com.facebook.presto.spi.function.SqlType)2 BlockSerdeUtil.writeBlock (com.facebook.presto.block.BlockSerdeUtil.writeBlock)1 Signature (com.facebook.presto.metadata.Signature)1 ColumnData (com.facebook.presto.rcfile.ColumnData)1 PrestoException (com.facebook.presto.spi.PrestoException)1 Description (com.facebook.presto.spi.function.Description)1 TypeSignature.parseTypeSignature (com.facebook.presto.spi.type.TypeSignature.parseTypeSignature)1 VarcharType (com.facebook.presto.spi.type.VarcharType)1 ArithmeticUnaryExpression (com.facebook.presto.sql.tree.ArithmeticUnaryExpression)1 BooleanLiteral (com.facebook.presto.sql.tree.BooleanLiteral)1 Cast (com.facebook.presto.sql.tree.Cast)1 DoubleLiteral (com.facebook.presto.sql.tree.DoubleLiteral)1 Expression (com.facebook.presto.sql.tree.Expression)1