0

そこで、Map Reduce を実践するために 2 つの Perl スクリプトを作成しました。このプログラムは、ディレクトリに配置した一連のテキスト ファイル内のすべての単語をカウントすることになっています。

これは私のmapper.plです

#!/usr/bin/perl

use 5.010;
use strict;
use warnings;

while(my $line = <>) {
    my @words = split(' ', $line);

    foreach my $word(@words) {
        print "$word \t 1\n";
    }
}

これは私のreducer.plです

#!/bin/usr/perl

use 5.010;
use warnings;

my $currentWord = "";
my $currentCount = 0;

##Use this block for testing the reduce script with some test data.
#Open the test file
#open(my $fh, "<", "testdata.txt");
#while(!eof $fh) {}

while(my $line = <>) {
    #Remove the \n
    chomp $line;

    #Index 0 is the word, index 1 is the count value
    my @lineData = split('\t', $line);
    my $word = $lineData[0];
    my $count = $lineData[1];

    if($currentWord eq $word) {
        $currentCount = $currentCount + $count;
    } else {
        if($currentWord ne "") {
            #Output the key we're finished working with
            print "$currentWord \t $currentCount \n";
        }
        #Switch the current variables over to the next key
        $currentCount = $count;
        $currentWord = $word;
    }
}

#deal with the last loop 
print "$currentWord \t $currentCount \n";

したがって、hadoop ストリーミング コマンドを使用してこれらを実行すると、次のようになります。

bin/hadoop jar contrib/streaming/hadoop-streaming-1.1.2.jar -file /home/hduser/countWords/mapper.pl -mapper /home/hduser/countWords/mapper.pl -file /home/hduser/countWords/reducer.pl -reducer /home/hduser/countWords/reducer.pl -input /user/hduser/testData/* -output /user/hduser/testData/output/*

次のエラーが表示されます。

13/07/19 11:36:33 INFO streaming.StreamJob:  map 0%  reduce 0%
13/07/19 11:36:39 INFO streaming.StreamJob:  map 9%  reduce 0%
13/07/19 11:36:40 INFO streaming.StreamJob:  map 64%  reduce 0%
13/07/19 11:36:41 INFO streaming.StreamJob:  map 73%  reduce 0%
13/07/19 11:36:44 INFO streaming.StreamJob:  map 82%  reduce 0%
13/07/19 11:36:45 INFO streaming.StreamJob:  map 100%  reduce 0%
13/07/19 11:36:49 INFO streaming.StreamJob:  map 100%  reduce 11%
13/07/19 11:36:53 INFO streaming.StreamJob:  map 100%  reduce 0%
13/07/19 11:37:02 INFO streaming.StreamJob:  map 100%  reduce 17%
13/07/19 11:37:03 INFO streaming.StreamJob:  map 100%  reduce 33%
13/07/19 11:37:06 INFO streaming.StreamJob:  map 100%  reduce 17%
13/07/19 11:37:08 INFO streaming.StreamJob:  map 100%  reduce 0%
13/07/19 11:37:16 INFO streaming.StreamJob:  map 100%  reduce 33%
13/07/19 11:37:21 INFO streaming.StreamJob:  map 100%  reduce 0%
13/07/19 11:37:31 INFO streaming.StreamJob:  map 100%  reduce 33%
13/07/19 11:37:35 INFO streaming.StreamJob:  map 100%  reduce 17%
13/07/19 11:37:38 INFO streaming.StreamJob:  map 100%  reduce 100%
13/07/19 11:37:38 INFO streaming.StreamJob: To kill this job, run:
13/07/19 11:37:38 INFO streaming.StreamJob: /usr/local/hadoop/libexec/../bin/hadoop job  -Dmapred.job.tracker=shiv0:54311 -kill job_201307031312_0065
13/07/19 11:37:38 INFO streaming.StreamJob: Tracking URL: http://shiv0:50030/jobdetails.jsp?jobid=job_201307031312_0065
13/07/19 11:37:38 ERROR streaming.StreamJob: Job not successful. Error: # of failed Reduce Tasks exceeded allowed limit. FailedCount: 1. LastFailedTask: task_201307031312_0065_r_000001
13/07/19 11:37:38 INFO streaming.StreamJob: killJob... Streaming Command Failed!

私はしばらくの間、何が間違っているのかを理解しようとしてきましたが、頭をかき続けています。これを診断する方法についてアドバイスはありますか?

4

2 に答える 2

0

私の側の非常にばかげた間違い.. reducer.pl の shbang 行が正しくありませんでした。私が持っていた

#!/bin/usr/perl

それ以外の

#!/usr/bin/perl
于 2013-07-22T20:08:48.500 に答える