コード例 #1
0
 public void map(LongWritable key, Text value, Mapper.Context context)
     throws IOException, InterruptedException {
   parser.parse(value);
   if (parser.isValidTemperature()) {
     int airTemperature = parser.getAirTemperature();
     if (airTemperature > 1000) {
       System.err.println("Temperature over 100 degrees for input: " + value);
       context.setStatus("Detected possibly corrupt record: see logs.");
       context.getCounter(Temperature.OVER_100).increment(1);
     }
     LOG.info("Map key:" + key);
     if (LOG.isDebugEnabled()) {
       LOG.debug("Map value" + value);
     }
     context.write(new Text(parser.getYear()), new IntWritable(airTemperature));
   }
 }
コード例 #2
0
    @Override
    protected void map(LongWritable key, Text value, Context context)
        throws IOException, InterruptedException {

      parser.parse(value);
      if (parser.isValidTemperature()) {
        int airTemperature = parser.getAirTemperature();
        context.write(new Text(parser.getYear()), new IntWritable(airTemperature));
      } else if (parser.isMalformedTemperature()) {
        System.err.println("Ignoring possibly corrupt input: " + value);
        context.getCounter(Temperature.MALFORMED).increment(1);
      } else if (parser.isMissingTemperature()) {
        context.getCounter(Temperature.MISSING).increment(1);
      }

      // dynamic counter
      context.getCounter("TemperatureQuality", parser.getQuality()).increment(1);
    }