I)
1001,25,23000,IT,clerk
1004,27,27000,HR,Manager
1002,23,21000, IT, Assistant
1003,28,33000,IT,Clerk
1006,31,29000,sales, Manager
1007,41,38000, HR, Clerk
1009, 27, 21000, Sales, Manager
II)
<k: employee name, v:salary>
dept1=the department treated for increment of salary
Actualsal1=salary consider for dept1
if(v(dept1)==IT).salary=(Actualsal*10/100)+Actualsal1
elseif:
dept2=the department treated for increment of salary
Actualsal2=salary consider for dept2
if(v(dept1)==HR).salary=(Actualsal2*12/100)+Actualsal2
elseif:
dept=the department treated for increment of salary
Actualsal=salary consider for dept
if(v(dept)==sales).salary=(Actualsal*5/100)+Actualsal
III)
MAPPER CLASS FOR AVERAGE SAL OF EMPLOYEE IN EACH DEPARTMENT
import [Link];
import [Link];
import [Link];
public class AverageSalaryPerDepartmentMapper extends Mapper<Object, Text, Text,
CustomAverageTuple> {
private CustomAverageTuple averageTuple = new CustomAverageTuple();
private Text departmentName = new Text();
@Override
public void map(Object key, Text value, Context context) throws IOException,
InterruptedException {
String data = [Link]();
String[] field = [Link](",", -1);
double salary = 0;
if (null != field && [Link] == 9 && field[7].length() >0) {
salary=[Link](field[7]);
[Link](salary);
[Link](1);
[Link](field[3]);
[Link](departmentName, averageTuple);
}
}
}
IV)
import [Link];
import [Link];
import [Link];
import [Link];
import [Link]
format;
import
[Link]
putFormat;
public final class empmain{
public static void main(string[] args)throws
illegalArgumentException, IOException,
ClassNotFoundException, InterruptedException
{
Configuration conf= new Configuration();
Job job=[Link](conf,"emain");
[Link]([Link]);
[Link]([Link]);
//[Link](0);
[Link]([Link]);
//[Link]([Link]);
////[Link]([Link]);
//[Link]([Link]);
[Link]([Link]);
[Link](job,newpath(args[0]));
[Link](job,newpath(args[1]));
[Link]([Link](true)?0:1);
}
}
V)
mport [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public static class MapperClass extends
Mapper<LongWritable, Text, Text, FloatWritable> {
public void map(LongWritable key, Text empRecord, Context con)
throws IOException, InterruptedException {
String[] word = [Link]().split("\\t");
String ename = word[3];
try {
Float salary = [Link](word[8]);
[Link](new Text(ename), new FloatWritable(salary));
} catch (Exception e) {
[Link]();
}
}
}
public static class ReducerClass extends
Reducer<Text, FloatWritable, Text, Text> {
public void reduce(Text key, Iterable<FloatWritable> valueList,
Context con) throws IOException, InterruptedException {
try {
Float total = (float) 0;
int count = 0;
for (FloatWritable var : valueList) {
total += [Link]();
[Link]("reducer " + [Link]());
count++;
}
}
}
}
public static void main(String[] args) {
Configuration conf = new Configuration();
try {
Job job = [Link](conf, "FindTotalSalary");
[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
// Path p1 = new Path(args[0]);
// Path p2 = new Path(args[1]);
// [Link](job, p1);
// [Link](job, p2);
Path pathInput = new Path(
"hdfs://[Link]:54310/user/hduser1/employee_records.txt");
Path pathOutputDir = new Path(
"hdfs://[Link]:54310/user/hduser1/testfs/output_mapred00");
[Link](job, pathInput);
[Link](job, pathOutputDir);
[Link]([Link](true) ? 0 : 1);
} catch (IOException e) {
[Link]();
} catch (ClassNotFoundException e) {
[Link]();
} catch (InterruptedException e) {
[Link]();
}
}
}
VI)
mport [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public static class MapperClass extends
Mapper<LongWritable, Text, Text, FloatWritable> {
public void map(LongWritable key, Text empRecord, Context con)
throws IOException, InterruptedException {
String[] word = [Link]().split("\\t");
String dept = word[3];
try {
Float salary = [Link](word[8]);
[Link](new Text(dept), new FloatWritable(salary));
} catch (Exception e) {
[Link]();
}
}
}
public static class ReducerClass extends
Reducer<Text, FloatWritable, Text, Text> {
public void reduce(Text key, Iterable<FloatWritable> valueList,
Context con) throws IOException, InterruptedException {
try {
Float total = (float) 0;
int count = 0;
for (FloatWritable var : valueList) {
total += [Link]();
[Link]("reducer " + [Link]());
count++;
}
Float avg = (Float) total / count;
String out = "Total: " + total + " :: " + "Average: " + avg;
[Link](key, new Text(out));
} catch (Exception e) {
[Link]();
}
}
}
public static void main(String[] args) {
Configuration conf = new Configuration();
try {
Job job = [Link](conf, "FindAverageAndSalary");
[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
// Path p1 = new Path(args[0]);
// Path p2 = new Path(args[1]);
// [Link](job, p1);
// [Link](job, p2);
Path pathInput = new Path(
"hdfs://[Link]:54310/user/hduser1/employee_records.txt");
Path pathOutputDir = new Path(
"hdfs://[Link]:54310/user/hduser1/testfs/output_mapred00");
[Link](job, pathInput);
[Link](job, pathOutputDir);
[Link]([Link](true) ? 0 : 1);
} catch (IOException e) {
[Link]();
} catch (ClassNotFoundException e) {
[Link]();
} catch (InterruptedException e) {
[Link]();
}
}
}