我是HBase的新手,我尝试在HBase的帮助下完成map reduce工作。通常我从文件中提取数据并将其输出写入HBase。奇怪的是,当我尝试运行代码时,当我尝试在本地运行代码时,它会在67%的减少阶段停留。 (当我尝试调试模式时,代码的reduce部分确实已触及)。
这是我为reduce编写的代码:
*
这就是我设置作业配置的方式:
public static class RowReducer extends
TableReducer<Text, Text, ImmutableBytesWritable> {
/**
* Generally, the format of my key is:
* FLAG-AIRPORT-INDEX, for the value of FLAG, "0" means invalid,
* "1" means valid. Not valid means the flight is cancelled or
* diverted or is not in the year range.
*/
public void reduce(Text key, Iterable<Text> values, Context context)
throws IOException, InterruptedException {
int index = 0;
for (Text value : values) {
CSVReader reader = new CSVReader(new StringReader(value.toString()));
String[] data = reader.readNext();
reader.close();
index++;
double cancelled = Double.parseDouble(data[INDEX_OF_CANCELED]);
double diverted = Double.parseDouble(data[INDEX_OF_DIVERTED]);
if (cancelled == 1.0 || diverted == 1.0) {
writeRowHelper(NOT_VALID_FLAG, context, index, key, value);
continue;
}
String[] date = data[INDEX_OF_DATE].split("-");
if (!date[0].equals(VALID_YEAR)) {
writeRowHelper(NOT_VALID_FLAG, context, index, key, value);
continue;
}
writeRowHelper(VALID_FLAG, context, index, key, value);
}
}
private void writeRowHelper(String flag, Context context, int index,
Text key, Text value)
throws IOException, InterruptedException {
String keyToWrite = flag + "-" + key.toString() + "-" + index;
Put put = new Put(keyToWrite.getBytes());
put.addColumn(FAMILY_TAG, QUALIFIER_TAG, value.getBytes());
context.write(new ImmutableBytesWritable(keyToWrite.getBytes()), put);
}
}
我不确定我的代码出了什么问题,请给我一些帮助。
答案 0 :(得分:0)
坚持67%的减少阶段表明您可能存在数据偏差。进入减速机时,大量数据可能共享相同的密钥,这意味着它必须由同一个减速机处理。
您可能还想检查并查看一个reducer是否继续重启(这可能表示某些不良数据),当然还要查看启用了调试的reducer日志。