有一个文件,正常数据有3个字段(否则为异常数据),'\t'作为分隔符,请补充代码实现一个计数器,用以统计异常数据的条数。异常数据位2条(Tom和Lily)Jim 1 28, Kate 0 26, Tom 1, Lily 0 29 22。public class Counters{public static class MyCounterMapper extends Mapper<LongWritable,Text,Text,Text>{public void map(LongWritable key,Text value,Context context)throws IOException{String line_words=value.toString().split('\t');//请在下方补充代码 }}}}
时间: 2024-04-05 12:29:41 浏览: 59
怎么把数据库表中的数据一行一行的写入文本文件,并且每个字段加上分隔符
4星 · 用户满意度95%
public static enum CountersEnum {
NUM_OF_INVALID_RECORDS
}
public static class MyCounterMapper extends Mapper<LongWritable, Text, Text, Text> {
public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
String[] fields = value.toString().split("\t");
if (fields.length != 3) {
context.getCounter(CountersEnum.NUM_OF_INVALID_RECORDS).increment(1);
}
}
}
阅读全文