Exp 9 - Merged
Exp 9 - Merged
import java.util.Scanner;
public class Main{
public static void main(String args[]){
int marks[] = new int [6];
int i;
float total = 0, avg;
Scanner scanner = new Scanner (System.in);
for(i=0; i<6; i++) {
System.out.print("Enter Marks of Subject " + (i + 1) + ":");
marks[i] = scanner.nextInt();
total = total + marks[i];
}
scanner.close();
avg = total/6;
System.out.print("The student grade is: ");
if (avg>=80)
System.out.println("A");
else if (avg>=60 && avg<80)
System.out.println("B");
else if(avg>=40 && avg<60)
System.out.println("C");
else
System.out.println("D");
}
}
Loading the dataset and initiating pig:
Filtering & Sorting operation:
Grouping & Splitting operation:
EXPERIMENT NUMBER – 09
Prerequisites:
1. Hadoop setup in Cloudera: Ensure that Hadoop is installed and configured in
Cloudera.
2. Eclipse IDE installed: Eclipse should be installed with the appropriate plugins for
Java development.
3. Hadoop Libraries: Ensure that the Hadoop libraries are added to your project build
path in Eclipse.
o Click Finish.
o Right-click on your project, select New > Class, and name it MatrixMapper.
o Similarly, create a new class named MatrixReducer with the following code:
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
public class MatrixMultiplication {
public static void main(String[] args) throws Exception {
// Ensure the correct number of arguments are passed
if (args.length < 5) {
System.err.println("Usage: MatrixMultiplication <input path> <output path> <m> <n>
<p>");
System.exit(-1);
}
Configuration conf = new Configuration();
conf.setInt("m", Integer.parseInt(args[2])); // rows of A
conf.setInt("n", Integer.parseInt(args[3])); // columns of A (and rows of B)
conf.setInt("p", Integer.parseInt(args[4])); // columns of B
// Validate matrix dimensions
if (conf.getInt("m", 0) <= 0 || conf.getInt("n", 0) <= 0 || conf.getInt("p", 0) <= 0) {
System.err.println("Invalid matrix dimensions: m, n, and p must be positive
integers.");
System.exit(-1);
}
Job job = Job.getInstance(conf, "Matrix Multiplication");
job.setJarByClass(MatrixMultiplication.class);
job.setMapperClass(MatrixMapper.class);
job.setReducerClass(MatrixReducer.class);
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(Text.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
job.setInputFormatClass(TextInputFormat.class);
job.setOutputFormatClass(TextOutputFormat.class);
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
System.exit(job.waitForCompletion(true) ? 0 : 1); } }
o Use the Cloudera terminal to create directories in HDFS and copy the input
matrices:
hadoop fs -mkdir -p /user/matrix/input