Search in sources :

Example 1 with SliceInput

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

the class FeatureUnitNormalizer method deserialize.

public static FeatureUnitNormalizer deserialize(byte[] modelData) {
    SliceInput input = Slices.wrappedBuffer(modelData).getInput();
    FeatureUnitNormalizer model = new FeatureUnitNormalizer();
    while (input.isReadable()) {
        int key = input.readInt();
        model.mins.put(key, input.readDouble());
        model.maxs.put(key, input.readDouble());
    }
    return model;
}
Also used : SliceInput(io.airlift.slice.SliceInput)

Example 2 with SliceInput

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

the class KHyperLogLog method newInstance.

public static KHyperLogLog newInstance(Slice serialized) {
    requireNonNull(serialized, "serialized is null");
    SliceInput input = serialized.getInput();
    checkArgument(input.readByte() == VERSION_BYTE, "Unexpected version");
    Long2ObjectRBTreeMap<HyperLogLog> minhash = new Long2ObjectRBTreeMap<>();
    int maxSize = input.readInt();
    int hllBuckets = input.readInt();
    int minhashSize = input.readInt();
    int totalHllSize = input.readInt();
    int[] hllSizes = new int[minhashSize];
    long[] keys = new long[minhashSize];
    input.readBytes(wrappedIntArray(hllSizes));
    input.readBytes(wrappedLongArray(keys));
    Slice allSerializedHlls = input.readSlice(totalHllSize);
    int hllLength;
    int index = 0;
    for (int i = 0; i < minhashSize; i++) {
        Slice serializedHll;
        hllLength = hllSizes[i];
        serializedHll = allSerializedHlls.slice(index, hllLength);
        index += hllLength;
        minhash.put(keys[i], HyperLogLog.newInstance(serializedHll));
    }
    return new KHyperLogLog(maxSize, hllBuckets, minhash);
}
Also used : Long2ObjectRBTreeMap(it.unimi.dsi.fastutil.longs.Long2ObjectRBTreeMap) Slice(io.airlift.slice.Slice) SliceInput(io.airlift.slice.SliceInput) HyperLogLog(com.facebook.airlift.stats.cardinality.HyperLogLog)

Example 3 with SliceInput

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

the class TDigest method createTDigest.

public static TDigest createTDigest(Slice slice) {
    if (slice == null) {
        return null;
    }
    SliceInput sliceInput = new BasicSliceInput(slice);
    try {
        byte format = sliceInput.readByte();
        checkArgument(format == 0 || format == 1, "Invalid serialization format for TDigest; expected '0' or '1'");
        byte type = sliceInput.readByte();
        checkArgument(type == 0, "Invalid type for TDigest; expected '0' (type double)");
        double min = sliceInput.readDouble();
        double max = sliceInput.readDouble();
        double sum = format == 1 ? sliceInput.readDouble() : 0.0;
        double publicCompression = max(10, sliceInput.readDouble());
        TDigest r = new TDigest(publicCompression);
        r.setMinMax(min, max);
        r.setSum(sum);
        r.totalWeight = sliceInput.readDouble();
        r.activeCentroids = sliceInput.readInt();
        r.weight = new double[r.activeCentroids];
        r.mean = new double[r.activeCentroids];
        sliceInput.readBytes(wrappedDoubleArray(r.weight), r.activeCentroids * SIZE_OF_DOUBLE);
        sliceInput.readBytes(wrappedDoubleArray(r.mean), r.activeCentroids * SIZE_OF_DOUBLE);
        sliceInput.close();
        return r;
    } catch (IndexOutOfBoundsException e) {
        throw new IllegalArgumentException("Incorrect slice serialization format");
    }
}
Also used : SliceInput(io.airlift.slice.SliceInput) BasicSliceInput(io.airlift.slice.BasicSliceInput) BasicSliceInput(io.airlift.slice.BasicSliceInput)

Example 4 with SliceInput

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

the class PrecisionRecallStateSerializer method deserialize.

@Override
public void deserialize(Block block, int index, PrecisionRecallState state) {
    final SliceInput input = VARBINARY.getSlice(block, index).getInput();
    final byte hasHistograms = input.readByte();
    checkArgument(hasHistograms == 0 || hasHistograms == 1, "hasHistogram %s should be boolean-convertible", hasHistograms);
    if (hasHistograms == 1) {
        state.setTrueWeights(FixedDoubleHistogram.deserialize(input));
        state.setFalseWeights(FixedDoubleHistogram.deserialize(input));
    }
}
Also used : SliceInput(io.airlift.slice.SliceInput)

Example 5 with SliceInput

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

the class DigestAndPercentileArrayStateSerializer method deserialize.

@Override
public void deserialize(Block block, int index, DigestAndPercentileArrayState state) {
    SliceInput input = VARBINARY.getSlice(block, index).getInput();
    // read number of percentiles
    int numPercentiles = input.readInt();
    ImmutableList.Builder<Double> percentilesListBuilder = ImmutableList.builder();
    for (int i = 0; i < numPercentiles; i++) {
        percentilesListBuilder.add(input.readDouble());
    }
    state.setPercentiles(percentilesListBuilder.build());
    // read digest
    int length = input.readInt();
    state.setDigest(new QuantileDigest(input.readSlice(length)));
    state.addMemoryUsage(state.getDigest().estimatedInMemorySizeInBytes());
}
Also used : QuantileDigest(com.facebook.airlift.stats.QuantileDigest) ImmutableList(com.google.common.collect.ImmutableList) SliceInput(io.airlift.slice.SliceInput)

Aggregations

SliceInput (io.airlift.slice.SliceInput)10 QuantileDigest (com.facebook.airlift.stats.QuantileDigest)2 HyperLogLog (com.facebook.airlift.stats.cardinality.HyperLogLog)2 Slice (io.airlift.slice.Slice)2 PrestoException (com.facebook.presto.spi.PrestoException)1 SerializedPage (com.facebook.presto.spi.page.SerializedPage)1 ImmutableList (com.google.common.collect.ImmutableList)1 BasicSliceInput (io.airlift.slice.BasicSliceInput)1 InputStreamSliceInput (io.airlift.slice.InputStreamSliceInput)1 Long2ObjectRBTreeMap (it.unimi.dsi.fastutil.longs.Long2ObjectRBTreeMap)1 Long2ShortRBTreeMap (it.unimi.dsi.fastutil.longs.Long2ShortRBTreeMap)1 IOException (java.io.IOException)1