0
아래 예제 데이터 input.txt에는 2 열 키 & 값이 있습니다. 매퍼에 의해 처리 된 각각의 레코드에 대해,지도의 출력매퍼에서 여러 출력 쓰기
1)에 기록 할 HDFS => 새로운 파일 키 컬럼
2) 컨텍스트 개체 아래
기반으로 생성하는 데 필요한 코드 키 열을 기준으로 4 개의 파일을 만들어야하지만 파일이 만들어지지 않습니다. 출력이 잘못되었습니다. 단어 수를 예상했지만 문자 수를 출력하고 있습니다.
input.txt
------------
key value
HelloWorld1|ID1
HelloWorld2|ID2
HelloWorld3|ID3
HelloWorld4|ID4
public static class MapForWordCount extends Mapper<LongWritable, Text, Text, IntWritable> {
public void map(LongWritable key, Text value, Context con) throws IOException, InterruptedException {
String line = value.toString();
String[] fileContent = line.split("|");
Path hdfsPath = new Path("/filelocation/" + fileContent[0]);
System.out.println("FilePath : " +hdfsPath);
Configuration configuration = con.getConfiguration();
writeFile(fileContent[1], hdfsPath, configuration);
for (String word : fileContent) {
Text outputKey = new Text(word.toUpperCase().trim());
IntWritable outputValue = new IntWritable(1);
con.write(outputKey, outputValue);
}
}
static void writeFile(String fileContent, Path hdfsPath, Configuration configuration) throws IOException {
FileSystem fs = FileSystem.get(configuration);
FSDataOutputStream fin = fs.create(hdfsPath);
fin.writeUTF(fileContent);
fin.close();
}
}
그것은 위와 같이 변경하여, 일 : 당신은 여기에
'|'
.split("\\|");
같은 참조 문서를 탈출해야합니다 –