Can some one help me in understanding why i am getting this odd behavior of custom data type i am referring this and my mapper code is
public class customDataMapper extends Mapper<LongWritable, Text,Text,customText > {
Text url = new Text();
Text date = new Text();
Text ip = new Text();
customText ctext = new customText();
public void map (LongWritable key , Text value , Context context) throws IOException , InterruptedException{
String words[] = value.toString().split("|");
url.set(words[1]);
date.set(words[2]);
ip.set(words[4]);
ctext.set(date,ip);
context.write(url, ctext);
}
}
and customText data type code is
public class customText implements WritableComparable<customText>{
private Text url , ip;
public customText(){
this.url=new Text();
this.ip=new Text();
}
public customText(Text URL , Text IP){
this.url=URL;
this.ip=IP;
}
public void set (Text URL , Text IP){
this.url=URL;
this.ip=IP;
}
public void readFields(DataInput in) throws IOException{
url.readFields(in);
ip.readFields(in);
}
public void write(DataOutput out ) throws IOException{
url.write(out);
ip.write(out);
}
public int compareTo(customText o){
if(url.compareTo(o.ip)==0){
return (ip.compareTo(o.ip));
}
else return (url.compareTo(o.ip));
}
public boolean equals(Object o){
if (o instanceof customText){
customText other = (customText)o;
return (url.equals(other.ip)) && ip.equals(other.ip);
}
return false;
}
public int hashCode(){
return url.hashCode();
}
and I received my output as
hduser@pradeep-VirtualBox:~/builds$ hadoop fs -cat /user/hadoop/dir8_customData/output/part-m-00000 1 customData.customDataSample1.customText@51 1 customData.customDataSample1.customText@51 1 customData.customDataSample1.customText@51 1 customData.customDataSample1.customText@51 1 customData.customDataSample1.customText@51
and my input file is
127248|/rr.html|2014-03-10|12:32:08|42.416.153.181
12|/rr12.html|2014-03-11|12:00:00|42.416.153.182
127241|/rr3232.html|2014-03-12|13:32:00|42.416.153.183
1272|/rrw33232.html|2014-03-15|14:32:08|42.416.153.184
121|/rr21212.html|2015-12-10|16:32:08|42.416.153.185
Can someone help me in understanding why I received this output and
secondly I am not sure how compareTo
is working , i mean so say when new group is created in reducer. I am new to hadoop and java programming.
Thanks