有人可以幫助我瞭解爲什麼我收到的自定義數據類型的這種奇怪的行爲我指this和我的映射器代碼自定義數據的地圖輸出寫入未知的數據
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);
}
}
和 customText數據類型代碼是
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();
}
,我收到了我的輸出
hduser @ PRA深的VirtualBox:〜/構建$ hadoop的FS -cat /用戶/ hadoop的/ dir8_customData /輸出/部分-M-00000 1 [email protected] 1 [email protected] 1 customData.customDataSample1 .customText @ 51 1 [email protected] 1 [email protected]
和我的輸入文件是
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
有人可以幫助我瞭解爲什麼我收到此輸出和 其次我不知道compareTo
是如何工作的,我的意思是說如何在減速機中創建新組。我是hadoop和java編程的新手。
感謝
非常感謝@Binary書呆子,你的評論幫了我很多。 –