Skip to content

Commit 566dd79

Browse files
committed
Merge remote-tracking branch 'origin/develop'
2 parents b359fd8 + 19b4177 commit 566dd79

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

README_Hadoop_Streaming.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,3 +340,37 @@ def reduce_one_group(key, group):
340340
for line in group:
341341
pass # Do something
342342
```
343+
344+
## Custom partitioner
345+
If you need to specify which key-value pairs are sent to which reducers, you can create a custom partitioner. Here's a sample which works with our word count example.
346+
```python
347+
#!/usr/bin/env -S python3 -u
348+
"""Word count partitioner."""
349+
import sys
350+
351+
352+
num_reducers = int(sys.argv[1])
353+
354+
355+
for line in sys.stdin:
356+
key, value = line.split("\t")
357+
if key[0] <= "G":
358+
print(0 % num_reducers)
359+
else:
360+
print(1 % num_reducers)
361+
```
362+
363+
Each line of output from the mappers is streamed to this partition file, and the number of reducers is set to `sys.argv[1]`. For each line, the partitioner checks whether the first letter of the key is less than or greater than "G". If it's less than "G", the line is sent to the first reducer, and if it's greater, the line is sent to the second reducer.
364+
365+
Use the `-partitioner` command-line argument to tell Madoop to use this partitioner.
366+
367+
```console
368+
$ madoop \
369+
-input example/input \
370+
-output example/output \
371+
-mapper example/map.py \
372+
-reducer example/reduce.py \
373+
-partitioner example/partition.py
374+
```
375+
376+
This feature is similar to Hadoop's [`Partitioner` class](https://hadoop.apache.org/docs/current/api/org/apache/hadoop/mapreduce/Partitioner.html), although it is not directly compatible with Hadoop. The main difference is that Hadoop only allows partitioners to be a Java class, while Madoop allows any executable that reads from `stdin` and writes to `stdout`.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "madoop"
7-
version = "1.2.1"
7+
version = "1.2.2"
88
description="A light weight MapReduce framework for education."
99
license = {file = "LICENSE"}
1010
authors = [

0 commit comments

Comments
 (0)