Exemplo n.º 1
0
            /// <summary>Given an output filename, write a bunch of random records to it.</summary>
            /// <exception cref="System.IO.IOException"/>
            /// <exception cref="System.Exception"/>
            protected override void Map(WritableComparable key, Writable value, Mapper.Context
                                        context)
            {
                int itemCount = 0;

                while (numBytesToWrite > 0)
                {
                    int keyLength = minKeySize + (keySizeRange != 0 ? random.Next(keySizeRange) : 0);
                    randomKey.SetSize(keyLength);
                    RandomizeBytes(randomKey.GetBytes(), 0, randomKey.GetLength());
                    int valueLength = minValueSize + (valueSizeRange != 0 ? random.Next(valueSizeRange
                                                                                        ) : 0);
                    randomValue.SetSize(valueLength);
                    RandomizeBytes(randomValue.GetBytes(), 0, randomValue.GetLength());
                    context.Write(randomKey, randomValue);
                    numBytesToWrite -= keyLength + valueLength;
                    context.GetCounter(LargeSorter.Counters.BytesWritten).Increment(keyLength + valueLength
                                                                                    );
                    context.GetCounter(LargeSorter.Counters.RecordsWritten).Increment(1);
                    if (++itemCount % 200 == 0)
                    {
                        context.SetStatus("wrote record " + itemCount + ". " + numBytesToWrite + " bytes left."
                                          );
                    }
                }
                context.SetStatus("done with " + itemCount + " records.");
            }
Exemplo n.º 2
0
            /// <summary>Given an output filename, write a bunch of random records to it.</summary>
            /// <exception cref="System.IO.IOException"/>
            /// <exception cref="System.Exception"/>
            protected override void Map(Text key, Text value, Mapper.Context context)
            {
                int itemCount = 0;

                while (numBytesToWrite > 0)
                {
                    // Generate the key/value
                    int noWordsKey = minWordsInKey + (wordsInKeyRange != 0 ? random.Next(wordsInKeyRange
                                                                                         ) : 0);
                    int noWordsValue = minWordsInValue + (wordsInValueRange != 0 ? random.Next(wordsInValueRange
                                                                                               ) : 0);
                    Text keyWords   = GenerateSentence(noWordsKey);
                    Text valueWords = GenerateSentence(noWordsValue);
                    // Write the sentence
                    context.Write(keyWords, valueWords);
                    numBytesToWrite -= (keyWords.GetLength() + valueWords.GetLength());
                    // Update counters, progress etc.
                    context.GetCounter(RandomTextWriter.Counters.BytesWritten).Increment(keyWords.GetLength
                                                                                             () + valueWords.GetLength());
                    context.GetCounter(RandomTextWriter.Counters.RecordsWritten).Increment(1);
                    if (++itemCount % 200 == 0)
                    {
                        context.SetStatus("wrote record " + itemCount + ". " + numBytesToWrite + " bytes left."
                                          );
                    }
                }
                context.SetStatus("done with " + itemCount + " records.");
            }
Exemplo n.º 3
0
            /// <exception cref="System.IO.IOException"/>
            /// <exception cref="System.Exception"/>
            protected override void Map(Org.Apache.Hadoop.IO.Text key, Org.Apache.Hadoop.IO.Text
                                        val, Mapper.Context context)
            {
                long acc     = 0L;
                long recs    = 0;
                int  keydiff = keymax - keymin;
                int  valdiff = valmax - valmin;

                for (long i = 0L; acc < bytesToWrite; ++i)
                {
                    int recacc = 0;
                    recacc += GenerateSentence(key, keymin + (0 == keydiff ? 0 : r.Next(keydiff)));
                    recacc += GenerateSentence(val, valmin + (0 == valdiff ? 0 : r.Next(valdiff)));
                    context.Write(key, val);
                    ++recs;
                    acc += recacc;
                    context.GetCounter(GenericMRLoadGenerator.Counters.BytesWritten).Increment(recacc
                                                                                               );
                    context.GetCounter(GenericMRLoadGenerator.Counters.RecordsWritten).Increment(1);
                    context.SetStatus(acc + "/" + (bytesToWrite - acc) + " bytes");
                }
                context.SetStatus("Wrote " + recs + " records");
            }