我有一个 6GB 的大 CSV 文件,以逗号分隔。下面是映射器功能
@Override
public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
String[] tokens = value.toString().split(",");
String crimeType = tokens[5].trim(); // column #5 is the crime type in the CSV file, serving key
// int year = Integer.parseInt(tokens[17].trim()); // the year when the crime happened
int year = 2010;
CrimeTypeKey crimeTypeYearKey = new CrimeTypeKey(crimeType, year);
context.write(crimeTypeYearKey, ONE);
}
如您所见,我使用“.split”来分解每一行(或每一列?)。我想知道在这种情况下如何使用 OpenCSV?请举个例子,非常感谢