很抱歉在hadoop用户邮件列表和此处交叉发布此内容,但这对我来说非常紧迫.
我的问题如下:我有两个输入文件,我想确定
例:
File 1:
a
b
c
File 2:
a
d
Run Code Online (Sandbox Code Playgroud)
每种情况的期望输出:
lines_only_in_1: 2 (b, c)
lines_only_in_2: 1 (d)
lines_in_both: 1 (a)
Run Code Online (Sandbox Code Playgroud)
基本上我的方法如下:我编写了自己的LineRecordReader,以便映射器接收一对由行(文本)和一个指示源文件(0或1)的字节组成的对.映射器只返回该对,所以它实际上什么都不做.然而,副作用是,组合器接收到
Map<Line, Iterable<SourceId>>
Run Code Online (Sandbox Code Playgroud)
(其中SourceId为0或1).
现在,对于每一行,我可以得到它出现的源集.因此,我可以编写一个组合器,计算每种情况(a,b,c)的行数(清单1)
然后组合器仅在清理时输出"摘要"(这是安全吗?).所以这个总结如下:
lines_only_in_1 2531
lines_only_in_2 3190
lines_in_both 901
Run Code Online (Sandbox Code Playgroud)
在减速器中,我只总结了这些摘要的值.(因此减速器的输出看起来与组合器的输出一样).
但是,主要问题是,我需要将两个源文件视为单个虚拟文件,该文件生成表单(line,sourceId)// sourceId 0或1的记录
而且我不确定如何实现这一目标.所以问题是我是否可以事先避免预处理和合并文件,并使用像虚拟合并文件阅读器和自定义记录阅读器这样的东西即时执行.任何代码示例都非常感谢.
最好的问候,克劳斯
清单1:
public static class SourceCombiner
extends Reducer<Text, ByteWritable, Text, LongWritable> {
private long countA = 0;
private long countB = 0;
private long countC = 0; // C = lines (c)ommon to both sources
@Override
public …Run Code Online (Sandbox Code Playgroud)