Search in sources :

Example 11 with Serializer

use of org.apache.hadoop.io.serializer.Serializer in project angel by Tencent.

the class SplitClassification method serialize.

@SuppressWarnings({ "rawtypes", "unchecked" })
public void serialize(DataOutputStream output) throws IOException {
    output.writeBoolean(useNewAPI);
    if (useNewAPI) {
        int size = splitsNewAPI.size();
        output.writeInt(size);
        output.writeInt(locations.length);
        for (int i = 0; i < locations.length; i++) {
            output.writeUTF(locations[i]);
        }
        if (size > 0) {
            output.writeUTF(splitsNewAPI.get(0).getClass().getName());
            SerializationFactory factory = new SerializationFactory(new Configuration());
            Serializer serializer = factory.getSerializer(splitsNewAPI.get(0).getClass());
            serializer.open(output);
            for (int i = 0; i < size; i++) {
                serializer.serialize(splitsNewAPI.get(i));
            }
        }
    } else {
        int size = splitsOldAPI.size();
        output.writeInt(size);
        output.writeInt(locations.length);
        for (int i = 0; i < size; i++) {
            output.writeUTF(locations[i]);
        }
        if (size > 0) {
            output.writeUTF(splitsOldAPI.get(0).getClass().getName());
            SerializationFactory factory = new SerializationFactory(new Configuration());
            Serializer serializer = factory.getSerializer(splitsOldAPI.get(0).getClass());
            serializer.open(output);
            for (int i = 0; i < size; i++) {
                serializer.serialize(splitsOldAPI.get(i));
            }
        }
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) SerializationFactory(org.apache.hadoop.io.serializer.SerializationFactory) Serializer(org.apache.hadoop.io.serializer.Serializer)

Aggregations

SerializationFactory (org.apache.hadoop.io.serializer.SerializationFactory)11 Serializer (org.apache.hadoop.io.serializer.Serializer)11 DataOutputBuffer (org.apache.hadoop.io.DataOutputBuffer)4 Configuration (org.apache.hadoop.conf.Configuration)3 JobConf (org.apache.hadoop.mapred.JobConf)3 SplitInfo (com.tencent.angel.split.SplitInfo)2 IOException (java.io.IOException)2 Map (java.util.Map)2 InputSplit (org.apache.hadoop.mapred.InputSplit)2 DefaultPartition (com.datatorrent.api.DefaultPartition)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 LinkedList (java.util.LinkedList)1 TreeMap (java.util.TreeMap)1 CollectorTestSink (org.apache.apex.malhar.lib.testbench.CollectorTestSink)1 LocalDirAllocator (org.apache.hadoop.fs.LocalDirAllocator)1 Path (org.apache.hadoop.fs.Path)1 BoundedByteArrayOutputStream (org.apache.hadoop.io.BoundedByteArrayOutputStream)1 BytesWritable (org.apache.hadoop.io.BytesWritable)1 DataInputBuffer (org.apache.hadoop.io.DataInputBuffer)1