Search in sources :

Example 31 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 32 with SliceOutput

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

the class TDigest method serializeInternal.

private Slice serializeInternal() {
    Slice result = Slices.allocate(serializedSizeInBytes());
    SliceOutput output = result.getOutput();
    output.writeByte(TDigest.FORMAT_TAG);
    output.writeDouble(min);
    output.writeDouble(max);
    output.writeDouble(compression);
    output.writeDouble(totalWeight);
    output.writeInt(centroidCount);
    for (int i = 0; i < centroidCount; i++) {
        output.writeDouble(means[i]);
    }
    for (int i = 0; i < centroidCount; i++) {
        output.writeDouble(weights[i]);
    }
    checkState(!output.isWritable(), "Expected serialized size doesn't match actual written size");
    return result;
}
Also used : SliceOutput(io.airlift.slice.SliceOutput) Slice(io.airlift.slice.Slice)

Example 33 with SliceOutput

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

the class QuantileDigest method serialize.

public Slice serialize() {
    compress();
    SliceOutput output = new DynamicSliceOutput(estimatedSerializedSizeInBytes());
    output.writeByte(Flags.FORMAT);
    output.writeDouble(maxError);
    output.writeDouble(alpha);
    output.writeLong(landmarkInSeconds);
    output.writeLong(min);
    output.writeLong(max);
    output.writeInt(getNodeCount());
    int[] nodes = new int[getNodeCount()];
    postOrderTraversal(root, new Callback() {

        int index;

        @Override
        public boolean process(int node) {
            nodes[index++] = node;
            return true;
        }
    });
    for (int node : nodes) {
        // The max value for a level is 64.  Non-leaf nodes are decremented by 1
        // to save a bit (so max serialized value is 63 (111111, 6 bits needed)).
        // This is shifted 2 bits to give space for left/right child flags.
        byte nodeStructure = (byte) (Math.max(levels[node] - 1, 0) << 2);
        if (lefts[node] != -1) {
            nodeStructure |= Flags.HAS_LEFT;
        }
        if (rights[node] != -1) {
            nodeStructure |= Flags.HAS_RIGHT;
        }
        output.writeByte(nodeStructure);
        output.writeDouble(counts[node]);
        output.writeLong(values[node]);
    }
    return output.slice();
}
Also used : SliceOutput(io.airlift.slice.SliceOutput) DynamicSliceOutput(io.airlift.slice.DynamicSliceOutput) DynamicSliceOutput(io.airlift.slice.DynamicSliceOutput)

Example 34 with SliceOutput

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

the class TestDenseSerialization method testEmpty.

@Test
public void testEmpty() throws Exception {
    SliceOutput expected = new DynamicSliceOutput(1).appendByte(// format tag
    3).appendByte(// p
    12).appendByte(// baseline
    0);
    for (int i = 0; i < 1 << (12 - 1); i++) {
        expected.appendByte(0);
    }
    // overflows
    expected.appendByte(0).appendByte(0);
    assertSlicesEqual(makeHll(12).serialize(), expected.slice());
}
Also used : DynamicSliceOutput(io.airlift.slice.DynamicSliceOutput) SliceOutput(io.airlift.slice.SliceOutput) DynamicSliceOutput(io.airlift.slice.DynamicSliceOutput) Test(org.testng.annotations.Test)

Example 35 with SliceOutput

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

the class PrecisionRecallStateSerializer method serialize.

@Override
public void serialize(PrecisionRecallState state, BlockBuilder out) {
    // has histograms;
    int requiredBytes = SizeOf.SIZE_OF_BYTE;
    if (state.getTrueWeights() != null) {
        requiredBytes += state.getTrueWeights().getRequiredBytesForSerialization();
        requiredBytes += state.getFalseWeights().getRequiredBytesForSerialization();
    }
    SliceOutput sliceOut = Slices.allocate(requiredBytes).getOutput();
    sliceOut.appendByte(state.getTrueWeights() == null ? 0 : 1);
    if (state.getTrueWeights() != null) {
        state.getTrueWeights().serialize(sliceOut);
        state.getFalseWeights().serialize(sliceOut);
    }
    VARBINARY.writeSlice(out, sliceOut.getUnderlyingSlice());
}
Also used : SliceOutput(io.airlift.slice.SliceOutput)

Aggregations

SliceOutput (io.airlift.slice.SliceOutput)46 DynamicSliceOutput (io.airlift.slice.DynamicSliceOutput)27 Slice (io.airlift.slice.Slice)16 IOException (java.io.IOException)8 Test (org.testng.annotations.Test)6 Block (com.facebook.presto.common.block.Block)5 UncheckedIOException (java.io.UncheckedIOException)5 LiteralParameters (com.facebook.presto.spi.function.LiteralParameters)4 SqlType (com.facebook.presto.spi.function.SqlType)4 UsedByGeneratedCode (com.facebook.presto.annotation.UsedByGeneratedCode)2 Page (com.facebook.presto.common.Page)2 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)2 PrestoException (com.facebook.presto.spi.PrestoException)2 ScalarFunction (com.facebook.presto.spi.function.ScalarFunction)2 SqlNullable (com.facebook.presto.spi.function.SqlNullable)2 ArithmeticUnaryExpression (com.facebook.presto.sql.tree.ArithmeticUnaryExpression)2 BooleanLiteral (com.facebook.presto.sql.tree.BooleanLiteral)2 Cast (com.facebook.presto.sql.tree.Cast)2 JsonUtil.createJsonGenerator (com.facebook.presto.util.JsonUtil.createJsonGenerator)2 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)2