atsky123 发表于 2016-4-21 22:25 谢谢~指点~我再研究下~确实认识不深····惭愧··· |
lanxueren121 发表于 2016-4-21 15:06 楼主对mapreduce理解还不太深,建议按照/t和空格来分。 mapreduce默认是对行分割的。所以楼主的按行是不对的 |
protected void map(Object key, Text value, Context context)throws IOException, InterruptedException { String total=value.toString(); StringTokenizer st = new StringTokenizer(total,"\n"); Num=Integer.valueOf(st.nextToken()); id = new int[Num]; x = new double[Num]; y = new double[Num]; z = new double[Num]; while(st.hasMoreTokens()){ StringTokenizer str = new StringTokenizer(st.nextToken()); countTokens = str.countTokens(); while(str.hasMoreTokens()){ String line=str.nextToken(); if (countTokens == 4) { int ID=Integer.valueOf(line.trim()); id= ID; double X=Double.valueOf(str.nextToken()); x = X; double Y=Double.valueOf(str.nextToken()); y = Y; double Z=Double.valueOf(str.nextToken()); z = Z; } } } for (int j=0;j<Num-1;j++){ for(int k=1;k<Num;k++){ distance =(double) Math.sqrt((x[k]-x[j])*(x[k]-x[j])+(y[k]-y[j])*(y[k]-y[j])+(z[k]-z[j])*(z[k]-z[j])); if (distance<=1.8){ angle=Math.abs(Math.atan((y[k]-y[j])/(x[k]-x[j]))); IntWritable outID=new IntWritable(id[j]); outTuple.setantrID(id[k]); outTuple.settangent(angle); context.write(outID, outTuple); } } } } } 分隔符不对造成认为是字符串。 先弄清楚,输入文件中,每行的分隔符是什么?? \n,肯定是不对的。确认是空格,还是\t |