0
我已经编写了Java代码来创建Java中的RowId。但我需要将其转换为mapreduce。我是MapReduce的新手,需要你的帮助。mapreduce中的序列号
输入是在当地
example: Alex 23 M NY
Alex 19 M NJ
Alex 29 M DC
Michael 20 M NY
Michael 24 M DC
计数文件提供为次输入 示例文件:
Alex 3
Michael 2
Desired Output:
1 Alex 23 M NY
2 Alex 19 M NJ
3 Alex 29 M DC
1 Michael 20 M NY
2 Michael 24 M DC
我在Java代码是在这里:
public class RowId
{
public static void main(String [] args) throws IOException
{
BufferReader in = null;
BufferReader cnt = null;
BufferWriter out = null;
String in_line;
String out_line;
int frst_row_ind=1;
int row_cnt=0;
int new_col=0;
try{
in= BufferReader(new FileReader ("file path in local");
File out_file = new File("o/p path in local");
if(!out_file.exists()){
out_file.createNewFile();
}
FileWriter fw = new FileWriter(out_file);
out = new BufferWriter(fw);
while((in_line = in.readLine())! = null)
{
if (in_line!=null)
{
String[] splitData = in_line.split("\\t");
cnt = new BufferReader(new FileReader("file path of countFile")
while((cnt_line=cnt.readLine()) != null)
{
String[] splitCount = cnt_line.split("\\t");
if ((splitCount[0]).equalsIgnoreCase(splitData[0]))
{
if (frst_row_ind==1)
{
row_cnt = Integer.parseInt(splitCount[1]);
}
new_col++
out.write(String.valueOf(new_col));
out.write("\\t");
for(int i= 0; i <splitData.length; i++)
{
if (!(splitData[i] == null) || (splitData[i].length()== 0))
{
out.write(splitData[i].trim());
if (i!=splitData.length-1)
{
out.write("\\t");
}
}
}
row_cnt--;
out.write("\r\n");
if(row_cnt==0)
{
frst_row_ind=1;
new_col=0;
}
else{
frst_row_ind=0;
}
out.flush();
break;
}
}
}
}
}
catch (IOException e)
{
e.printStrackTrace();
}
finally
{
try{
if(in!=null) in.close();
if(cnt !=null) cnt.close();
}
catch (IOException e)
{
e.printStrackTrace();
}
}
}
}
请不要复归与你的想法(S)。
感谢名单依禅您的回复, 但你能解释一下我,这应该是怎样干活的意思是我需要怎么提供计数文件。和其他凭证的主要输入文件。 – pamel
Pamel,我没有看到计数文件的任何角色为您所需的输出。请解释我一样。 –
雅,我找到你了!非常感谢答案。 它帮助我非常。 – pamel