Search in sources :

Example 1 with Deserializer

use of org.apache.hadoop.io.serializer.Deserializer in project hadoop by apache.

the class MapTask method getSplitDetails.

@SuppressWarnings("unchecked")
private <T> T getSplitDetails(Path file, long offset) throws IOException {
    FileSystem fs = file.getFileSystem(conf);
    FSDataInputStream inFile = fs.open(file);
    inFile.seek(offset);
    String className = StringInterner.weakIntern(Text.readString(inFile));
    Class<T> cls;
    try {
        cls = (Class<T>) conf.getClassByName(className);
    } catch (ClassNotFoundException ce) {
        IOException wrap = new IOException("Split class " + className + " not found");
        wrap.initCause(ce);
        throw wrap;
    }
    SerializationFactory factory = new SerializationFactory(conf);
    Deserializer<T> deserializer = (Deserializer<T>) factory.getDeserializer(cls);
    deserializer.open(inFile);
    T split = deserializer.deserialize(null);
    long pos = inFile.getPos();
    getCounters().findCounter(TaskCounter.SPLIT_RAW_BYTES).increment(pos - offset);
    inFile.close();
    return split;
}
Also used : Deserializer(org.apache.hadoop.io.serializer.Deserializer) FileSystem(org.apache.hadoop.fs.FileSystem) RawLocalFileSystem(org.apache.hadoop.fs.RawLocalFileSystem) LocalFileSystem(org.apache.hadoop.fs.LocalFileSystem) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) SerializationFactory(org.apache.hadoop.io.serializer.SerializationFactory) IOException(java.io.IOException)

Example 2 with Deserializer

use of org.apache.hadoop.io.serializer.Deserializer in project hadoop by apache.

the class TaggedInputSplit method readFields.

@SuppressWarnings("unchecked")
public void readFields(DataInput in) throws IOException {
    inputSplitClass = (Class<? extends InputSplit>) readClass(in);
    inputFormatClass = (Class<? extends InputFormat<?, ?>>) readClass(in);
    mapperClass = (Class<? extends Mapper<?, ?, ?, ?>>) 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)

Example 3 with Deserializer

use of org.apache.hadoop.io.serializer.Deserializer 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 4 with Deserializer

use of org.apache.hadoop.io.serializer.Deserializer 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 5 with Deserializer

use of org.apache.hadoop.io.serializer.Deserializer in project ignite by apache.

the class HadoopV2TaskContext method readExternalSplit.

/**
     * @param split External split.
     * @return Native input split.
     * @throws IgniteCheckedException If failed.
     */
@SuppressWarnings("unchecked")
private Object readExternalSplit(HadoopExternalSplit split) throws IgniteCheckedException {
    Path jobDir = new Path(jobConf().get(MRJobConfig.MAPREDUCE_JOB_DIR));
    FileSystem fs;
    try {
        fs = fileSystemForMrUserWithCaching(jobDir.toUri(), jobConf(), fsMap);
    } catch (IOException e) {
        throw new IgniteCheckedException(e);
    }
    try (FSDataInputStream in = fs.open(JobSubmissionFiles.getJobSplitFile(jobDir))) {
        in.seek(split.offset());
        String clsName = Text.readString(in);
        Class<?> cls = jobConf().getClassByName(clsName);
        assert cls != null;
        Serialization serialization = new SerializationFactory(jobConf()).getSerialization(cls);
        Deserializer deserializer = serialization.getDeserializer(cls);
        deserializer.open(in);
        Object res = deserializer.deserialize(null);
        deserializer.close();
        assert res != null;
        return res;
    } catch (IOException | ClassNotFoundException e) {
        throw new IgniteCheckedException(e);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) SerializationFactory(org.apache.hadoop.io.serializer.SerializationFactory) IOException(java.io.IOException) WritableSerialization(org.apache.hadoop.io.serializer.WritableSerialization) HadoopSerialization(org.apache.ignite.internal.processors.hadoop.HadoopSerialization) Serialization(org.apache.hadoop.io.serializer.Serialization) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Deserializer(org.apache.hadoop.io.serializer.Deserializer) FileSystem(org.apache.hadoop.fs.FileSystem) LocalFileSystem(org.apache.hadoop.fs.LocalFileSystem) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream)

Aggregations

Deserializer (org.apache.hadoop.io.serializer.Deserializer)5 SerializationFactory (org.apache.hadoop.io.serializer.SerializationFactory)5 IOException (java.io.IOException)2 FSDataInputStream (org.apache.hadoop.fs.FSDataInputStream)2 FileSystem (org.apache.hadoop.fs.FileSystem)2 LocalFileSystem (org.apache.hadoop.fs.LocalFileSystem)2 InputSplit (org.apache.hadoop.mapreduce.InputSplit)2 Path (org.apache.hadoop.fs.Path)1 RawLocalFileSystem (org.apache.hadoop.fs.RawLocalFileSystem)1 Serialization (org.apache.hadoop.io.serializer.Serialization)1 WritableSerialization (org.apache.hadoop.io.serializer.WritableSerialization)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 HadoopSerialization (org.apache.ignite.internal.processors.hadoop.HadoopSerialization)1