This repository has been archived by the owner on Jul 23, 2024. It is now read-only.
forked from bcolloran/deorphaning_mrjob
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinkDocsAndParts.py
62 lines (42 loc) · 2.11 KB
/
linkDocsAndParts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from mrjob.job import MRJob
import mrjob
import sys, codecs
sys.stdout = codecs.getwriter('utf-8')(sys.stdout)
#partSet is conceptually a set, but will be implemented as a "|" separated set of strings for compatibility reasons
class linkDocsAndPartsJob(MRJob):
HADOOP_INPUT_FORMAT="org.apache.hadoop.mapred.TextInputFormat"
# HADOOP_INPUT_FORMAT="org.apache.hadoop.mapred.SequenceFileAsTextInputFormat"
# HADOOP_INPUT_FORMAT="org.apache.hadoop.mapred.KeyValueTextInputFormat"
INPUT_PROTOCOL = mrjob.protocol.RawProtocol
INTERNAL_PROTOCOL = mrjob.protocol.RawProtocol
OUTPUT_PROTOCOL = mrjob.protocol.RawProtocol
# def mapper(self,docId, partId):
# self.increment_counter("MAPPER", "(docId,partId) in")
# yield docId, partId
# def combiner(self,docId, partIdStringsIter):
# # partIdStringsIter should always reach the combiner as an iter of strings like:
# # ["pId1","pId2|pId3|...|pId(N)",...]
# # need to join these with pipes.
# # partSetOut = set()
# # for partIdList in partIdIter:
# # partSetOut |= set(partIdList)
# yield docId, "|".join(partIdStringsIter)
def reducer(self,docId, partIdIter):
# partIdIter should always reach the reducer as an iter of strings like:
# ["pId1","pId2",...]
linkedParts = set(partIdIter)
# for partSetStr in partIdIter:
# linkedParts |= set(partSetStr.split("|"))
lowPart = min(linkedParts)
yield(lowPart,docId)
self.increment_counter("REDUCER", "(lowPart,docId) out")
self.increment_counter("REDUCER", "docs in OVERLAPPING_PARTS",0)
if len(linkedParts)==1:
#if there is only one part linked to this docId, there are no overlaps here, so no part-to-part touches are emitted
self.increment_counter("REDUCER", "docs in only 1 part")
else:
#otherwise, return all the overlaps
yield(lowPart,"|".join(linkedParts))
self.increment_counter("REDUCER", "docs in OVERLAPPING_PARTS")
if __name__ == '__main__':
linkDocsAndPartsJob.run()