import java.io.IOException;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.MapReduceBase;
import org.apache.hadoop.mapred.Mapper;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reporter;
public class ADDMapper extends MapReduceBase implements Mapper<LongWritable,
Text,Text,LongWritable>
{ @Override
public void map(LongWritable key, Text value,OutputCollector<Text, LongWritable> output, Reporter r)throws IOException
{
String s=value.toString();
char[] words=s.toCharArray();
int wno=0;
int ino=0;
for(int i=0;i<words.length;i++)
{
String temp="";
for(int j=ino;j<words.length;j++)
{
if(words[j]!=' ')
{ temp+=words[j];
}
else
{
wno=j;
if(temp!="")
{
ino=ino + key; //////POINT OF ERROR
output.collect(new Text(temp),new LongWritable(ino));
}
temp="";
ino=wno+1;
break;
}
}
}
}
我想每個字符串的索引值,通過串排序。
上面的代碼既沒有給出索引值,也沒有對字符串進行混洗。 讓 輸入文件: 嗨,你好嗎 嗨,我是對的。 你的工作情況如何。 你好嗎。
輸出: 上午50 是7.33 喜0,30,44 如何3,14 。 。
你能(a)正確地格式化你的代碼,並且(b)請不要在CAPS中提出問題嗎?另外,請閱讀[我如何問一個好問題](http://stackoverflow.com/help/how-to-ask)瞭解一些更進一步的技巧。你的問題就這樣,將會收到很少的答案。 – 2015-04-05 09:07:10