Пример #1
0
 /// <exception cref="System.Exception"/>
 /// <exception cref="System.IO.IOException"/>
 public ReduceContextImpl(Configuration conf, TaskAttemptID taskid, RawKeyValueIterator
                          input, Counter inputKeyCounter, Counter inputValueCounter, RecordWriter <KEYOUT,
                                                                                                   VALUEOUT> output, OutputCommitter committer, StatusReporter reporter, RawComparator
                          <KEYIN> comparator, Type keyClass, Type valueClass)
     : base(conf, taskid, output, committer, reporter)
 {
     iterable = new ReduceContextImpl.ValueIterable(this);
     // current key
     // current value
     // first value in key
     // more w/ this key
     // more in file
     this.input                = input;
     this.inputKeyCounter      = inputKeyCounter;
     this.inputValueCounter    = inputValueCounter;
     this.comparator           = comparator;
     this.serializationFactory = new SerializationFactory(conf);
     this.keyDeserializer      = serializationFactory.GetDeserializer(keyClass);
     this.keyDeserializer.Open(buffer);
     this.valueDeserializer = serializationFactory.GetDeserializer(valueClass);
     this.valueDeserializer.Open(buffer);
     hasMore         = input.Next();
     this.keyClass   = keyClass;
     this.valueClass = valueClass;
     this.conf       = conf;
     this.taskid     = taskid;
 }
            /// <summary>
            /// Restores the storage entity to a strongly typed in-memory array representation with element type <typeparamref name="T"/> by deserializing state that was loaded by <see cref="LoadCore(IStateReader)"/>.
            /// If the entity has not been persisted before, this methods returns a new array instance with default values of type <typeparamref name="T"/> for each of its elements.
            /// </summary>
            /// <typeparam name="T">The type of the elements stored in the array.</typeparam>
            /// <returns>An instance of type <typeparamref name="T"/>[] containing the data represented by the storage entity.</returns>
            private T[] Restore <T>()
            {
                //
                // If the state was loaded by LoadCore, we have a eventual objects to deserialize array elements from. Otherwise, return a fresh array instance.
                //

                if (_data != null)
                {
                    //
                    // Obtain the deserializer once to reduce overhead.
                    //

                    var deserializer = SerializationFactory.GetDeserializer <T>();

                    //
                    // Deserialize all the array elements.
                    //

                    var res = new T[_data.Length];

                    for (var i = 0; i < _data.Length; i++)
                    {
                        res[i] = _data[i].Deserialize(deserializer);
                    }

                    _data = null;

                    return(res);
                }
                else
                {
                    return(new T[_length]);
                }
            }
Пример #3
0
        /// <summary><inheritDoc/></summary>
        /// <exception cref="System.IO.IOException">
        /// If the child InputSplit cannot be read, typically
        /// for failing access checks.
        /// </exception>
        public virtual void ReadFields(DataInput @in)
        {
            // Generic array assignment
            int card = WritableUtils.ReadVInt(@in);

            if (splits == null || splits.Length != card)
            {
                splits = new InputSplit[card];
            }
            Type[] cls = new Type[card];
            try
            {
                for (int i = 0; i < card; ++i)
                {
                    cls[i] = Sharpen.Runtime.GetType(Text.ReadString(@in)).AsSubclass <InputSplit>();
                }
                for (int i_1 = 0; i_1 < card; ++i_1)
                {
                    splits[i_1] = ReflectionUtils.NewInstance(cls[i_1], null);
                    SerializationFactory factory      = new SerializationFactory(conf);
                    Deserializer         deserializer = factory.GetDeserializer(cls[i_1]);
                    deserializer.Open((DataInputStream)@in);
                    splits[i_1] = (InputSplit)deserializer.Deserialize(splits[i_1]);
                }
            }
            catch (TypeLoadException e)
            {
                throw new IOException("Failed split init", e);
            }
        }
Пример #4
0
        /// <exception cref="System.IO.IOException"/>
        public virtual void ReadFields(DataInput @in)
        {
            inputSplitClass  = (Type)ReadClass(@in);
            inputFormatClass = (Type)ReadClass(@in);
            mapperClass      = (Type)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);
        }
Пример #5
0
        /// <summary>Make a copy of the writable object using serialization to a buffer</summary>
        /// <param name="src">the object to copy from</param>
        /// <param name="dst">the object to copy into, which is destroyed</param>
        /// <returns>dst param (the copy)</returns>
        /// <exception cref="System.IO.IOException"/>
        public static T Copy <T>(Configuration conf, T src, T dst)
        {
            ReflectionUtils.CopyInCopyOutBuffer buffer = cloneBuffers.Get();
            buffer.outBuffer.Reset();
            SerializationFactory factory = GetFactory(conf);
            Type cls = (Type)src.GetType();

            Org.Apache.Hadoop.IO.Serializer.Serializer <T> serializer = factory.GetSerializer(
                cls);
            serializer.Open(buffer.outBuffer);
            serializer.Serialize(src);
            buffer.MoveData();
            Deserializer <T> deserializer = factory.GetDeserializer(cls);

            deserializer.Open(buffer.inBuffer);
            dst = deserializer.Deserialize(dst);
            return(dst);
        }
Пример #6
0
        public DefaultStringifier(Configuration conf, Type c)
        {
            SerializationFactory factory = new SerializationFactory(conf);

            this.serializer   = factory.GetSerializer(c);
            this.deserializer = factory.GetDeserializer(c);
            this.inBuf        = new DataInputBuffer();
            this.outBuf       = new DataOutputBuffer();
            try
            {
                serializer.Open(outBuf);
                deserializer.Open(inBuf);
            }
            catch (IOException ex)
            {
                throw new RuntimeException(ex);
            }
        }
Пример #7
0
        /// <exception cref="System.Exception"/>
        private K SerDeser <K>(K conf)
        {
            SerializationFactory factory = new SerializationFactory(Conf);

            Org.Apache.Hadoop.IO.Serializer.Serializer <K> serializer = factory.GetSerializer(
                GenericsUtil.GetClass(conf));
            Deserializer <K> deserializer = factory.GetDeserializer(GenericsUtil.GetClass(conf
                                                                                          ));
            DataOutputBuffer @out = new DataOutputBuffer();

            serializer.Open(@out);
            serializer.Serialize(conf);
            serializer.Close();
            DataInputBuffer @in = new DataInputBuffer();

            @in.Reset(@out.GetData(), @out.GetLength());
            deserializer.Open(@in);
            K after = deserializer.Deserialize(null);

            deserializer.Close();
            return(after);
        }
            /// <summary>
            /// Restores the storage entity to a strongly typed in-memory stack representation with element type <typeparamref name="T"/> by deserializing state that was loaded by <see cref="LoadCore(IStateReader)"/>.
            /// If the entity has not been persisted before, this methods returns a new empty stack instance.
            /// </summary>
            /// <typeparam name="T">The type of the elements stored in the stack.</typeparam>
            /// <returns>An instance of type Stack{<typeparamref name="T"/>} containing the data represented by the storage entity.</returns>
            private Stack <T> Restore <T>()
            {
                //
                // If the state was loaded by LoadCore, we have a eventual objects to deserialize stack elements from. Otherwise, return a fresh stack instance.
                //

                if (_data != null)
                {
                    //
                    // Obtain the deserializer once to reduce overhead.
                    //

                    var deserializer = SerializationFactory.GetDeserializer <T>();

                    //
                    // Deserialize all the stack elements.
                    //

                    var res = new Stack <T>(_data.Length);

                    //
                    // NB: The eventual objects loaded by LoadCore occur in the push order.
                    //

                    for (var i = 0; i < _data.Length; i++)
                    {
                        res.Push(_data[i].Deserialize(deserializer));
                    }

                    _data = null;

                    return(res);
                }
                else
                {
                    return(new Stack <T>());
                }
            }