-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSalesOfTVMapper.java
More file actions
45 lines (35 loc) · 1.35 KB
/
SalesOfTVMapper.java
File metadata and controls
45 lines (35 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import java.io.IOException;
import java.util.StringTokenizer;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
/*
* Input key is the offset of line in file
* Input value format : CompanyName|ProductName|SizeInInches|State|PinCOde|Prize
* Output key is the the name of the company
* Output value is 1
*/
public class SalesOfTVMapper extends Mapper<LongWritable,Text,Text,IntWritable>
{
private final static String DELIMITER = "|";
private final static String NA = "NA";
private final static IntWritable ONE = new IntWritable(1);
Text companyName = new Text();
@Override
public void map(LongWritable key,Text value,Context context) throws IOException, InterruptedException
{
String strValue = value.toString();
System.out.println("Current value is "+strValue);
StringTokenizer tokenizer = new StringTokenizer(strValue, DELIMITER);
String strCompanyName = tokenizer.nextToken();
String strProductName = tokenizer.nextToken();
//Check if CompanyName or Product Name is 'NA'
if(!strCompanyName.equalsIgnoreCase(NA) && !strProductName.equalsIgnoreCase(NA))
{
companyName.set(strCompanyName.trim());
context.write(companyName,ONE);
System.out.println("Putting key : "+strCompanyName+" and value : 1 in context");
}
}
}