-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #73 from aarmaane/develop
Fix directories containing spaces
- Loading branch information
Showing
7 changed files
with
63 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Hello World | ||
Bye World |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Hello Hadoop | ||
Goodbye Hadoop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/env python3 | ||
"""Word count mapper.""" | ||
import sys | ||
|
||
|
||
for line in sys.stdin: | ||
words = line.split() | ||
for word in words: | ||
print(f"{word}\t1") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/env python3 | ||
"""Word count reducer.""" | ||
import sys | ||
import itertools | ||
|
||
|
||
def main(): | ||
"""Divide sorted lines into groups that share a key.""" | ||
for key, group in itertools.groupby(sys.stdin, keyfunc): | ||
reduce_one_group(key, group) | ||
|
||
|
||
def keyfunc(line): | ||
"""Return the key from a TAB-delimited key-value pair.""" | ||
return line.partition("\t")[0] | ||
|
||
|
||
def reduce_one_group(key, group): | ||
"""Reduce one group.""" | ||
word_count = 0 | ||
for line in group: | ||
count = line.partition("\t")[2] | ||
word_count += int(count) | ||
print(f"{key} {word_count}") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |