我是hadoop编程的新手,我尝试在map-side-join上编写代码,但是得到了空指针异常。请帮忙,让我知道问题的原因。
package mapreduce.mapSideJoin;
import java.io.IOException;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.mapreduce.Mapper;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.HashMap;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.filecache.DistributedCache;
import org.apache.hadoop.io.LongWritable;
public class mapSideJoinUserMapper extends Mapper<LongWritable,Text,Text,Text > {
private HashMap<String, String> cacheMap = new HashMap<String , String>();
private BufferedReader br ;
protected void setup (Context context)throws IOException, InterruptedException{
Path[] pathArray = DistributedCache.getLocalCacheFiles(context.getConfiguration());
try {
for ( Path eachPath : pathArray){
//System.out.pritn(eachPath.toString());
if(eachPath.getName().toString().trim().equals("custData.txt"));
LoadHashMap(eachPath,context);
}
}
catch(IOException e){
System.err.println("An IOException was caught!");
}
}
private void LoadHashMap(Path filePath, Context context) throws IOException{
String strReadLine="";
br = new BufferedReader(new FileReader(filePath.toString()));
while((strReadLine=br.readLine())!= null){
String[] wordArray = strReadLine.split(",");
cacheMap.put(wordArray[0].trim(),wordArray[1].trim());
}
br.close();
}
public void map(LongWritable key, Text value , Context context ) throws IOException, InterruptedException{
String [] word = value.toString().split(",");
String name =cacheMap.get(word[0]);
context.write(new Text(name), new Text(word[1]));
//context.write(new Text("jdewdeded"), new Text("dededededede"));
}
}
这是我的Map代码和数据文件
0001,Zunil Kumar , Mumbai,India
0002,vikas mandal, Haryana, India
0003,Karan, JFK,France
0004,manish,banglore,India
0005,devesh,meerut,India
0001,crax,2,300
0002,munch,1,10
0003,lays,1,20
0004,ship,1,200
0005,barOne,3,400
0002,crax,2,300
0001,kurkure,3,101
0003,milk,1,20
0004,butter,2,30
0005,meat,1,1220
0002,color,1,230
0003,dailrymilk,1,20
我
谢谢
1条答案
按热度按时间qmb5sa221#
我尝试实现与你尝试的相同的逻辑并得到了输出。
}
如果有用的话请告诉我!!!