mapper代码如下,需求是将json格式的文件传入hbase,mapper将json转化为key+line的形式,目前定位问题就是在mapper上报以上错误。麻烦帮忙看看
public static class Json2StringMapper extends Mapper<LongWritable, Text, IntWritable, Text>{
private IntWritable mapOutKey;
private Text mapOutValue;
@Override
public void map(LongWritable key, Text value, Context context)
throws IOException, InterruptedException {
String line = value.toString();
//resolve json
String regEx = "[\\{\"\\}]";
Pattern p = Pattern.compile(regEx);
Matcher m = p.matcher(line);
String resovedLine = m.replaceAll("").trim(); //replace {,",}
mapOutValue.set(resovedLine);
//split into array[]
String[] tuples = resovedLine.split(",");
//set rowkey
int id =Integer.valueOf(tuples[0].split(":")[1]);
mapOutKey.set(id);
//mapOutput (key,String[colume:value])
context.write(mapOutKey, mapOutValue);
}
}
|