2011-10-10 2 views
0
다음

출력을 쓰기는 시나리오 나 다른 파일에 데이터를 기록 할 감속기에서하둡 스트리밍 : 다른 파일

  Reducer1 
     / 
Mapper - - Reducer2 
     \ 
      ReducerN 

입니다

def reduce(): 
    for line in sys.STDIN: 
    if(line == type1): 
     create_type_1_file(line) 
    if(line == type2): 
     create_type_2_file(line) 
    if(line == type3): 
     create_type3_file(line) 
     ... and so on 
def create_type_1_file(line): 
    # writes to file1 
def create_type2_file(line): 
    # writes to file2 
def create_type_3_file(line): 
    # write to file 3 

이 생각처럼 감속기 보이는 말할 수 경로는 다음과 같이 작성하십시오 :

file1 = /home/user/data/file1 
file2 = /home/user/data/file2 
file3 = /home/user/data/file3 

pseudo-distributed mode(machine with one node and hdfs daemons running)에서 실행하면 모든 것이 d aemons는 같은 파일 집합에 글을 쓸 것입니다.

질문 : -이 파일을 1000 대의 컴퓨터 클러스터에서 실행하면 동일한 파일 집합에도 쓸 수 있습니까? 이 경우 writing to local filesystem입니다.
- hadoop streaming에서이 작업을 수행하는 더 좋은 방법이 있습니까? 노드 중 하나가 다음 아래로 그 손실 노드와 관련된 감소 데이터를 이동하는 경우 때문에

, 당신은

+0

이 답변이 도움이 될 수 있습니다 (확실하지, 따라서 코멘트 감속기의

Job job = new Job(); FileInputFormat.setInputPath(job, inDir); //outDir is the root path, in this case, outDir="/home/user/data/" FileOutputFormat.setOutputPath(job, outDir); //You have to assign the output formatclass.Using MultipleOutputs in this way will still create zero-sized default output, eg part-00000. To prevent this use LazyOutputFormat.setOutputFormatClass(job, TextOutputFormat.class); instead of job.setOutputFormatClass(TextOutputFormat.class); in your Hadoop job configuration. LazyOutputFormat.setOutputFormatClass(job, TextOutputFormat.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(Text.class); job.setMapperClass(MOMap.class); job.setReducerClass(MOReduce.class); ... job.waitForCompletion(true); 

사용) http://stackoverflow.com/questions/162 6786/생성 독립 출력 파일 인 하프 스트리밍/1690092 # 1690092 – Nija

답변

0

일반적 감소의 오/피가 HDFS와 같은 신뢰할 수있는 스토리지 시스템에 기록 감사합니다. Hadoop 프레임 워크의 컨텍스트 외부에서 특정 reduce 태스크를 다시 실행할 수 없습니다. 또한 작업이 완료되면 다양한 입력 유형에 대해 1000 노드의 o/p를 통합해야합니다.

동시 기록은 HDFS에서 not supported입니다. 여러 감속기가 HDFS에서 동일한 파일에 쓰고 파일을 손상시킬 수있는 경우가있을 수 있습니다. 단일 노드에서 여러 개의 축소 작업이 실행되는 경우 단일 로컬 파일에 쓰는 경우 동시성이 문제가 될 수 있습니다.

하나의 해결 방법은 reduce task specific file name을 갖고 나중에 특정 입력 유형에 대한 모든 파일을 결합하는 것입니다.

0

출력물은 MultipleOutputs 클래스를 사용하여 Reducer에서 여러 위치로 쓸 수 있습니다. file1, file2 및 file3을 세 개의 폴더로 간주하고 1000 개의 Reducer 출력 데이터를이 폴더에 별도로 쓸 수 있습니다. 작업 제출에 대한


사용 패턴 :

private MultipleOutputs out; 

public void setup(Context context) { 

    out = new MultipleOutputs(context); 

    ... 

} 

public void reduce(Text key, Iterable values, Context context) throws IOException, InterruptedException { 

//'/' characters in baseOutputPath will be translated into directory levels in your file system. Also, append your custom-generated path with "part" or similar, otherwise your output will be -00000, -00001 etc. No call to context.write() is necessary. 
for (Text line : values) { 

    if(line == type1) 
     out.write(key, new Text(line),"file1/part"); 

    else if(line == type2) 
     out.write(key, new Text(line),"file2/part"); 

else if(line == type3) 
     out.write(key, new Text(line),"file3/part"); 
    } 
} 

protected void cleanup(Context context) throws IOException, InterruptedException { 
     out.close(); 
    } 

심판 : https://hadoop.apache.org/docs/r2.6.3/api/org/apache/hadoop/mapreduce/lib/output/MultipleOutputs.html