map reduce将Map器的输出作为字典中的字典传递给reducer

6tqwzwtp  于 2021-06-03  发布在  Hadoop
关注(0)|答案(0)|浏览(219)

​我的mapperpython脚本生成如下输出 [2323223,[{'word':'hi'},{'charcount':'2'}] 在输出中, 2323223 是键,其余都是键的值 2323223 但在值中,字典中有多个键值对。
Map器脚本的一部分​​:

analysis = {}
 wordanalysis = {}
 found = True

 for line in sys.stdin:
 (n1,n6) = re.split("\t+",line.strip())
 #n6 are the words and n1 is id
 words= re.split("\s+", n6.strip().lower())

 for i in range(0, len(words)):
  #adding id to a dictionary
   #n1 is id
    analysis[n1] = wordanalysis
    wordanalysis["word"] = words[i]
    wordanalysis["charcount"]= len(words[i])

    if len(words[i]) > 7:
       wordanalysis["longword"] = found
    else:
       wordanalysis["longword"] = not(found)

差不多吧。我的减速机应该像数数单词的数目等,但它将如何解释已经存在的词典。。类似于减速机:对于sys.stdin中的行:
Map器输出:

['34324242'] [{'word': 'hi','charcount': 2}]
['897924242'] [{'word': 'hello','charcount': 5}]

这是我的输出。我将这个值从mapper脚本传递到reducer脚本。减速机以上述o/p为输入,进行字符总数等数据分析。你知道怎么做吗?
主要的挑战是从Map器输出中获取dict值,以及如何根据dict中的键检索它们。
谢谢。​

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题