1)` map (nr, txt)
words = split (txt, ' ')
for(i=0; i< |words| - 1; i++)
emit(words[i]+' '+words[i+1], 1)
reduce(key, vals)
s=0
for v : vals
s += v
if(s = 5)
emit(key,s)`
2)` map (nr, txt)
words = split (txt, ' ')
for(i=0; i < |words|; i++)
emit(txt, length(words[i]))
reduce(key, vals)
s=0
c=0
for v : vals
s += v
c += 1
r = s/c
emit(key,r)`
我是 MapReduce 的新手,当我无法理解“代码 (1) 中的 if 条件是否会满足”时
Q1 我们需要确定这个 MapReduce 函数在两个代码中做了什么? 您能否就上述问题提供任何意见。
最佳答案
第一个代码块发出所有出现超过 5 次的双字母组。 reducer if 条件满足如果一对相邻词至少存在 5 次
第二个 block 发出输入文本的每个单词及其长度。它试图计算每个单词的平均长度,但由于 reducer 只看到一个键,因此该计算不会做任何事情(看到 “foo”
1000 次仍然有 3 的长度)
关于hadoop - MapReduce 基础知识,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55984693/