2012-09-25 6 views
0

분산 캐시에 많은 파일이 저장되어 있으며 각 파일은 사용자 ID에 해당합니다. 특정 감축 작업의 특정 사용자 ID (감속기의 키)에 해당하는 특정 파일을 첨부하고 싶습니다. 그러나 필자는 reduce 클래스의 reduce 메소드보다 먼저 오는 configure 메소드를 사용하여 분산 캐시에서 파일을 읽었 기 때문에 그렇게 할 수 없습니다. 그래서 reduce 클래스의 configure 메소드에서 reduce 메소드의 키에 액세스 할 수 없기 때문에 원하는 파일 만 읽을 수는 없습니다. Pls 날 도와 줘요.분산 캐시를 사용하여 파일 읽기

class reduce{ 

void configure(args) 
{ 

/*I can a particular file from the Path[] here. 
I want to select the file corresponding to the key of the reduce method and pass its 
contents to the reduce method. I am not able to do this as I can't access the key of 
the reduce method.*/ 

} 

void reduce(args) 
{ 
} 


} 

답변

1

용액은 DistributedCache javadocs에 기재된 구성 단계 동안 클래스 변수에 DistributedCache에서 Path 배열을 할당하는 것이다. 물론지도 코드를 줄이기 코드로 바꾸십시오.

이것은 이전 API를 사용하고 있습니다.이 API는 코드에서 사용 된 것처럼 보입니다.

public static class MapClass extends MapReduceBase 
implements Mapper<K, V, K, V> { 

    private Path[] localArchives; 
    private Path[] localFiles; 

    public void configure(JobConf job) { 
    // Get the cached archives/files 
    localArchives = DistributedCache.getLocalCacheArchives(job); 
    localFiles = DistributedCache.getLocalCacheFiles(job); 
    } 

    public void map(K key, V value, 
        OutputCollector<K, V> output, Reporter reporter) 
    throws IOException { 
    // Use data from the cached archives/files here 
    // ... 
    // ... 
    output.collect(k, v); 
    } 
} 
+0

감사합니다! 도움이됩니다! –