在Map中跳过.csv的第一行会减少java

Kun*_*nal 5 java mapreduce bigdata

由于映射器函数针对每一行运行,我是否可以知道如何跳过第一行.对于某些文件,它包含我想忽略的列标题

ViK*_*KiG 8

在映射器中,在读取文件时,数据作为键值对读入.关键是下一行开始的字节偏移量.对于第1行,它始终为零.所以在mapper函数中执行以下操作

    @Override
    public void map(LongWritable key, Text value, Context context) throws IOException {
        try {
            if (key.get() == 0 && value.toString().contains("header") /*Some condition satisfying it is header*/)
                return;
            else {
                // For rest of data it goes here
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }     
Run Code Online (Sandbox Code Playgroud)