Как заставить мой MapReducer выводить несколько строк из моего ввода? - PullRequest
0 голосов
/ 07 мая 2020

Так что здесь происходит то, что я создаю 3 класса. Карта, Уменьшить, Главная. У меня проблемы с редуктором вывода нескольких строк данных из входного файла. Я знаю, что он проходит через каждый ключ и значение, но он просто выводит последние данные из файла. Вот мой входной текст

Класс сопоставителя:

import java.io.IOException;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

public class TemperatureMapper
  extends Mapper<LongWritable, Text, Text, IntWritable> {

  private static final int MISSING = 9999;

  @Override
  public void map(LongWritable key, Text value, Context context)
      throws IOException, InterruptedException {

    String line = value.toString();
    String year = line.substring(15, 19);
    int airTemperature;
    if (line.charAt(87) == '+') {
      airTemperature = Integer.parseInt(line.substring(88, 92));
    } else {
      airTemperature = Integer.parseInt(line.substring(87, 92));
    }
    String quality = line.substring(92, 93);
    if (airTemperature != MISSING) {
      context.write(new Text(year), new IntWritable(airTemperature));
    }
  }
}

Класс редуктора:

import java.io.IOException;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

public class TempReducer
  extends Reducer<Text, IntWritable, Text, IntWritable> {

  @Override
  public void reduce(Text key, Iterable<IntWritable> values,
      Context context)
      throws IOException, InterruptedException {

    int TempValue = Integer.MIN_VALUE;
    for (IntWritable value : values) {
      TempValue = value.get();
    }
    context.write(key, new IntWritable(TempValue));
  }
}

Результат после запуска имел oop cmd:

Выход

...