Java – How do I ignore key-value pairs in Map-Reduce if the value is empty?

How do I ignore key-value pairs in Map-Reduce if the value is empty?… here is a solution to the problem.

How do I ignore key-value pairs in Map-Reduce if the value is empty?

I

have a tab-delimited input file and I’m reading 2 columns in Map-Reduce. One column is the key and the other column is the value. So my requirement is that if the value is blank, i.e. it contains spaces or tabs or any other character, even the key should not be handled to reducer. Overall, it should discard the record and get the next record with a value. The following code was written, but it didn’t. It performs all logging. It doesn’t filter anything.

public static class Map extends Mapper<LongWritable, Text, Text,Text> 
    {
        private Text vis = new Text();
        private Text eValue = new Text();
        public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException 
        {
            String line=value.toString();
            String[] arr=line.split("\t");
            vis.set(arr[8]);
            eValue.set(arr[287]);
            if (!eValue.equals("\t") || eValue.equals(" "))
            {
                context.write(vis,eValue);
            }
            } 
    }

Thanks for any help. Thanks in advance.

PS: I’m using Hadoop-2.6.0

Solution

You can use the following statement instead of multiple check conditions.

        if (!( eValue.toString().isEmpty()))
    {
        context.write(vis,eValue);
    }

Related Problems and Solutions