
com.yahoo.sketches.pig.frequencies.Util Maven / Gradle / Ivy
/*
* Copyright 2016, Yahoo! Inc.
* Licensed under the terms of the Apache License 2.0. See LICENSE file at the project root for terms.
*/
package com.yahoo.sketches.pig.frequencies;
import org.apache.pig.backend.executionengine.ExecException;
import org.apache.pig.data.DataByteArray;
import org.apache.pig.data.Tuple;
import org.apache.pig.data.TupleFactory;
import com.yahoo.memory.Memory;
import com.yahoo.sketches.ArrayOfItemsSerDe;
import com.yahoo.sketches.frequencies.ItemsSketch;
final class Util {
static final TupleFactory tupleFactory = TupleFactory.getInstance();
static Tuple serializeSketchToTuple(
final ItemsSketch sketch, final ArrayOfItemsSerDe serDe) throws ExecException {
final Tuple outputTuple = Util.tupleFactory.newTuple(1);
outputTuple.set(0, new DataByteArray(sketch.toByteArray(serDe)));
return outputTuple;
}
static ItemsSketch deserializeSketchFromTuple(
final Tuple tuple, final ArrayOfItemsSerDe serDe) throws ExecException {
final byte[] bytes = ((DataByteArray) tuple.get(0)).get();
return ItemsSketch.getInstance(Memory.wrap(bytes), serDe);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy