Search in sources :

Example 6 with SerializationFactory

use of org.apache.hadoop.io.serializer.SerializationFactory in project crunch by cloudera.

the class CrunchInputSplit method readFields.

public void readFields(DataInput in) throws IOException {
    nodeIndex = in.readInt();
    int extraConfSize = in.readInt();
    if (extraConfSize > 0) {
        for (int i = 0; i < extraConfSize; i++) {
            conf.set(in.readUTF(), in.readUTF());
        }
    }
    inputFormatClass = (Class<? extends InputFormat<?, ?>>) readClass(in);
    Class<? extends InputSplit> inputSplitClass = (Class<? extends InputSplit>) readClass(in);
    inputSplit = (InputSplit) ReflectionUtils.newInstance(inputSplitClass, conf);
    SerializationFactory factory = new SerializationFactory(conf);
    Deserializer deserializer = factory.getDeserializer(inputSplitClass);
    deserializer.open((DataInputStream) in);
    inputSplit = (InputSplit) deserializer.deserialize(inputSplit);
}
Also used : Deserializer(org.apache.hadoop.io.serializer.Deserializer) SerializationFactory(org.apache.hadoop.io.serializer.SerializationFactory) InputSplit(org.apache.hadoop.mapreduce.InputSplit)

Example 7 with SerializationFactory

use of org.apache.hadoop.io.serializer.SerializationFactory in project crunch by cloudera.

the class CrunchInputSplit method write.

public void write(DataOutput out) throws IOException {
    out.writeInt(nodeIndex);
    out.writeInt(extraConf.size());
    for (Map.Entry<String, String> e : extraConf.entrySet()) {
        out.writeUTF(e.getKey());
        out.writeUTF(e.getValue());
    }
    Text.writeString(out, inputFormatClass.getName());
    Text.writeString(out, inputSplit.getClass().getName());
    SerializationFactory factory = new SerializationFactory(conf);
    Serializer serializer = factory.getSerializer(inputSplit.getClass());
    serializer.open((DataOutputStream) out);
    serializer.serialize(inputSplit);
}
Also used : SerializationFactory(org.apache.hadoop.io.serializer.SerializationFactory) Map(java.util.Map) Serializer(org.apache.hadoop.io.serializer.Serializer)

Example 8 with SerializationFactory

use of org.apache.hadoop.io.serializer.SerializationFactory in project gora by apache.

the class IOUtils method deserialize.

/**
   * Deserializes the object in the given data input using
   * available Hadoop serializations.
   *
   * @param conf Hadoop conf.
   * @param in data input stream where serialized content is read.
   * @param <T> object class type.
   * @param obj data object.
   * @param objClass object class type.
   * @throws IOException occurred while deserializing the byte content.
   * @return deserialized object.
   */
public static <T> T deserialize(Configuration conf, DataInput in, T obj, Class<T> objClass) throws IOException {
    SerializationFactory serializationFactory = new SerializationFactory(getOrCreateConf(conf));
    Deserializer<T> deserializer = serializationFactory.getDeserializer(objClass);
    int length = WritableUtils.readVInt(in);
    byte[] arr = new byte[length];
    in.readFully(arr);
    List<ByteBuffer> list = new ArrayList<>();
    list.add(ByteBuffer.wrap(arr));
    try (ByteBufferInputStream is = new ByteBufferInputStream(list)) {
        deserializer.open(is);
        T newObj = deserializer.deserialize(obj);
        return newObj;
    } finally {
        if (deserializer != null)
            deserializer.close();
    }
}
Also used : ArrayList(java.util.ArrayList) ByteBufferInputStream(org.apache.avro.util.ByteBufferInputStream) SerializationFactory(org.apache.hadoop.io.serializer.SerializationFactory) ByteBuffer(java.nio.ByteBuffer)

Example 9 with SerializationFactory

use of org.apache.hadoop.io.serializer.SerializationFactory in project cdap by caskdata.

the class TaggedInputSplit method readFields.

@SuppressWarnings("unchecked")
@Override
public final void readFields(DataInput in) throws IOException {
    Class<? extends InputSplit> inputSplitClass = (Class<? extends InputSplit>) readClass(in);
    readAdditionalFields(in);
    inputSplit = ReflectionUtils.newInstance(inputSplitClass, conf);
    SerializationFactory factory = new SerializationFactory(conf);
    Deserializer deserializer = factory.getDeserializer(inputSplitClass);
    deserializer.open((DataInputStream) in);
    inputSplit = (InputSplit) deserializer.deserialize(inputSplit);
}
Also used : Deserializer(org.apache.hadoop.io.serializer.Deserializer) SerializationFactory(org.apache.hadoop.io.serializer.SerializationFactory) InputSplit(org.apache.hadoop.mapreduce.InputSplit)

Example 10 with SerializationFactory

use of org.apache.hadoop.io.serializer.SerializationFactory in project cdap by caskdata.

the class TaggedInputSplit method write.

@SuppressWarnings("unchecked")
@Override
public final void write(DataOutput out) throws IOException {
    Class<? extends InputSplit> inputSplitClass = inputSplit.getClass();
    Text.writeString(out, inputSplitClass.getName());
    writeAdditionalFields(out);
    SerializationFactory factory = new SerializationFactory(conf);
    Serializer serializer = factory.getSerializer(inputSplitClass);
    serializer.open((DataOutputStream) out);
    serializer.serialize(inputSplit);
}
Also used : SerializationFactory(org.apache.hadoop.io.serializer.SerializationFactory) Serializer(org.apache.hadoop.io.serializer.Serializer)

Aggregations

SerializationFactory (org.apache.hadoop.io.serializer.SerializationFactory)20 Deserializer (org.apache.hadoop.io.serializer.Deserializer)5 IOException (java.io.IOException)4 Serializer (org.apache.hadoop.io.serializer.Serializer)4 ByteBuffer (java.nio.ByteBuffer)2 FSDataInputStream (org.apache.hadoop.fs.FSDataInputStream)2 FileSystem (org.apache.hadoop.fs.FileSystem)2 LocalFileSystem (org.apache.hadoop.fs.LocalFileSystem)2 DataInputBuffer (org.apache.hadoop.io.DataInputBuffer)2 DataOutputBuffer (org.apache.hadoop.io.DataOutputBuffer)2 JobConf (org.apache.hadoop.mapred.JobConf)2 InputSplit (org.apache.hadoop.mapreduce.InputSplit)2 JobContext (org.apache.hadoop.mapreduce.JobContext)2 JobID (org.apache.hadoop.mapreduce.JobID)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 ByteBufferInputStream (org.apache.avro.util.ByteBufferInputStream)1 ByteBufferOutputStream (org.apache.avro.util.ByteBufferOutputStream)1 Configuration (org.apache.hadoop.conf.Configuration)1