2

私はhadoopの初心者です。map reduce 関数の流れを理解したい。ファイルではなくコードを介してマップジョブに入力を与えるにはどうすればよいか、少し混乱しています。どのように設定すればよいですか。親切に私を助けてください。これが私のコードです。

    public class TemperatureMapper : MapperBase
        {
 private static int MISSING = 9999;

            public override void Map(string line, MapperContext context)
            {

                //Extract the namespace declarations in the Csharp files
                string year = line.Substring(15, 4);
                int startIndex = line[87] ==  '+'?88 : 87;

                int airTemp = int.Parse(line.Substring(startIndex, 92 - startIndex));

                string quality = line.Substring(92, 1);

                Regex r = new Regex(quality, RegexOptions.IgnoreCase);
                Match m = r.Match("[01459]");
                if (airTemp != MISSING && r.Match("[01459]").Success)
                {
                    context.EmitKeyValue(year.ToString(), airTemp.ToString());
                }
            }
        }



        //Reducer

        public class TempReducer : ReducerCombinerBase
        {
            //Accepts each key and count the occurrances
            public override void Reduce(string key, IEnumerable<string> values,ReducerCombinerContext context)
            {
                //Write back

                int maxvalue = int.MinValue;
                foreach(string value in values)
                {
                    maxvalue = Math.Max(maxvalue, int.Parse(value));
                }
                context.EmitKeyValue(key, maxvalue.ToString());
            }

        }



static void Main(string[] args)
        {

            try
            {

                string line;
                StreamReader file = new StreamReader("temp.txt");

                ArrayList al = new ArrayList();
                while ((line = file.ReadLine()) != null)
                {
                    al.Add(line);
                }
                file.Close();

                string[] input = (string[])al.ToArray(typeof(string));




                Environment.SetEnvironmentVariable("HADOOP_HOME", @"c:\hadoop");
                Environment.SetEnvironmentVariable("Java_HOME", @"c:\hadoop\jvm");

        var output = StreamingUnit.Execute<TemperatureMapper, TempReducer>(input);//this code is executed successfully


//runnning the job in azure
var hadoop = Hadoop.Connect(); // connected to hadoop successfully
                var config = new HadoopJobConfiguration();
                hadoop.MapReduceJob.Execute<TemperatureMapper, TempReducer>(config);//how to I provide input here... 
                Console.ReadLine();             

            }

ストリーミングユニットを介して正しい結果が得られます。今、私はこの仕事を紺碧で実行したいと思っています。では、ファイルではなくコードを介して入力するにはどうすればよいでしょうか。私はconfig ieを介して入力を与えました

config.AdditionalStreamingArguments.AddRange(input); //input is array of string

しかし、ジョブを実行すると、この例外が発生します:

The argument must not be empty string.
Parameter name: blobName
4

1 に答える 1

3

Hadoop MapReduce は、デフォルトではファイルに対してのみ動作します (ファイル ベースではないストレージ ハンドラーを作成することもできますが、これはあまり一般的ではありません)。

HDFS 上のファイルに存在するものではなく、ストリーム上で生成されたものに MapReduce を適用しようとしている場合は、代わりに YARN 上の Storm などを調べることをお勧めします。

于 2014-05-06T09:01:18.687 に答える