You are on page 1of 6

below hospitalbill.

txt you can add records for big


textfile like 10TB

one thing hear your system hard disk size is 500gb
but you need to put the data 10TB?,
solution: cluster setup , there distribution cache is it
will share the data to all data nodes in a cluster
configuration.


date customer name roomno doctorbill mediceinebill
roombill other allowences

input file : hospitalbill.txt
26/03/2012 RangaSwamy 1 2000 3000 2500 3000
26/03/2012 lakshmi 3 2000 2500 3500 2000
26/03/2012 sailaja 2 5000 1000 2000 500
26/03/2012 chamandi 4 7000 4000 3000 3000
26/03/2012 aruna 6 3000 1000 2000 3000
26/03/2012 swapna 5 3000 2000 5000 500
27/03/2012 RangaSwamy 1 1000 3000 2500 3000
27/03/2012 lakshmi 3 1000 2500 3500 2000
27/03/2012 sailaja 2 4000 1000 2000 500
27/03/2012 chamandi 4 6000 4000 3000 3000
27/03/2012 aruna 6 2000 1000 2000 3000
27/03/2012 swapna 5 2000 2050 1000 500
28/03/2012 RangaSwamy 1 2000 3000 2500 3000
28/03/2012 lakshmi 3 2000 2500 3500 2000
28/03/2012 sailaja 2 5000 1000 2000 500
28/03/2012 chamandi 4 7000 4000 3000 3000
28/03/2012 aruna 6 3000 1000 2000 3000
28/03/2012 swapna 5 3000 2000 5000 500
29/03/2012 RangaSwamy 1 1000 3000 2500 3000
29/03/2012 lakshmi 3 1000 2500 3500 2000
29/03/2012 sailaja 2 4000 1000 2000 500
29/03/2012 chamandi 4 6000 4000 3000 3000
29/03/2012 aruna 6 2000 1000 2000 3000
29/03/2012 swapna 5 2000 2050 1000 500
30/03/2012 RangaSwamy 1 2000 3000 2500 3000
30/03/2012 lakshmi 3 2000 2500 3500 2000
30/03/2012 sailaja 2 5000 1000 2000 500
30/03/2012 chamandi 4 7000 4000 3000 3000
30/03/2012 aruna 6 3000 1000 2000 3000
30/03/2012 swapna 5 3000 2000 5000 500

custemer name room no final bill
output :
RangaSwamy 1 50500
aruna 6 43000
chamandi 4 83000
lakshmi 3 48000
sailaja 2 40500
swapna 5 42600

mapreduce code:
import org.apache.hadoop.fs.FileSystem;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;

import org.apache.hadoop.fs.Path;
import org.apache.hadoop.conf.*;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapred.*;
import org.apache.hadoop.util.*;

public class healthcare1 {

public static final String DATE_FORMAT_NOW = "dd-mm-yy HH-
mm-ss";

public static String system_date() {
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new
SimpleDateFormat(DATE_FORMAT_NOW);
return sdf.format(cal.getTime());

}
public static class Map extends MapReduceBase implements
Mapper<LongWritable, Text, Text, IntWritable> {

private Text word = new Text();

public void map(LongWritable key, Text value, OutputCollector<Text,
IntWritable> output, Reporter reporter) throws IOException {

String line = value.toString();

StringTokenizer tokenizer = new StringTokenizer(line);

while (tokenizer.hasMoreTokens()) {
int doctor_bill=0;
int medicine_bill=0;
int room_bill=0;
int other_allowences=0;
String cust_name=" ";
String room_no=" ";

tokenizer.nextToken() ;
if(tokenizer.hasMoreElements())
{
cust_name =tokenizer.nextToken();
}
if(tokenizer.hasMoreElements())
{
room_no=tokenizer.nextToken();
}
if(tokenizer.hasMoreElements())
{
doctor_bill = Integer.parseInt(tokenizer.nextToken());
}
if(tokenizer.hasMoreElements())
{
medicine_bill = Integer.parseInt(tokenizer.nextToken());
}
if(tokenizer.hasMoreElements())
{
room_bill = Integer.parseInt(tokenizer.nextToken());
}
if(tokenizer.hasMoreElements())
{
other_allowences = Integer.parseInt(tokenizer.nextToken());
}
int total_bill= doctor_bill+medicine_bill+room_bill+other_allowences;
String l =cust_name+" "+room_no;

word.set(l);
IntWritable tbill = new IntWritable(total_bill);
output.collect(word, tbill);
}
}
}

public static class Reduce extends MapReduceBase implements
Reducer<Text, IntWritable, Text, IntWritable> {
public void reduce(Text key, Iterator<IntWritable> values,
OutputCollector<Text, IntWritable> output, Reporter reporter) throws
IOException {

int final_bill = 0;
while (values.hasNext()) {
final_bill += values.next().get();
}
output.collect(key, new IntWritable(final_bill));
}
}





public static void main(String[] args) throws Exception {


JobConf conf = new JobConf(healthcare1.class);
conf.setJobName("healthcare1");

conf.setOutputKeyClass(Text.class);
conf.setOutputValueClass(IntWritable.class);

conf.setMapperClass(Map.class);
conf.setCombinerClass(Reduce.class);
conf.setReducerClass(Reduce.class);

conf.setInputFormat(TextInputFormat.class);
conf.setOutputFormat(TextOutputFormat.class);

FileInputFormat.setInputPaths(conf, new
Path("/home/ranga/ranga_input_and_output/hospitalbill.txt"));
FileOutputFormat.setOutputPath(conf, new
Path("/home/ranga/ranga_input_and_output/"+healthcare1.system_date(
)+"helthcare_0utput"));

JobClient.runJob(conf);

}
}

You might also like