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;
}
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);
}
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");
}
}
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));
}
}
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());
}
Aggregations