Last active
October 18, 2016 17:32
-
-
Save NewFuture/fd0a03b8698f9ed569c70682e00a372b to your computer and use it in GitHub Desktop.
yes! hadoop
This file contains hidden or 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
| #!/usr/bin/env bash | |
| # 模拟单个mapper和reducer | |
| SORT='-k1,1' | |
| if [ $# -lt 2 ] ; then | |
| echo "USAGE:" | |
| echo " $0 inputfile mapper"; #双参数 | |
| echo " $0 inputfile mapper reducer ";#三参数 | |
| echo " $0 inputfile mapper reducer SORT_ARGS";#多参数 | |
| echo " -default [SORT_ARGS]: '$SORT'"; | |
| exit 1; | |
| fi | |
| command -v realpath >/dev/null 2>&1 || realpath() { [[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}";}; | |
| echostd() { cat <<< "$@" 1>&2;}; | |
| inputfile="$(realpath $1)" && \ | |
| mapper="$(realpath $2)" && \ | |
| chmod +x "$mapper"; | |
| if [ $# -eq 2 ] ; then | |
| echostd "[input --> mapper --> sort]"; | |
| cat "$inputfile" | "$mapper" | sort -t $'\t' $SORT | |
| else | |
| echostd "[input --> mapper --> sort --> reducer]"; | |
| reducer="$(realpath $3)" && \ | |
| chmod +x "$reducer"; | |
| [ $# -gt 3 ] && SORT="${@:4}" | |
| cat "$inputfile" | "$mapper" | sort -t $'\t' "$SORT" | "$reducer" | |
| fi | |
This file contains hidden or 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
| #!/usr/bin/env python | |
| import sys | |
| print(max([len(l.strip()) for l in sys.stdin])) |
This file contains hidden or 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
| #!/usr/bin/env python | |
| import sys | |
| print(max(map(int, sys.stdin))) |
This file contains hidden or 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
| #!/usr/bin/env python | |
| import sys | |
| for line in sys.stdin: | |
| print(max(map(len, line.split()))) |
This file contains hidden or 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
| #!/usr/bin/env python | |
| import sys | |
| print(max(map(int, sys.stdin))) |
Author
Author
for current user
curl -#SL https://gist.github.com/NewFuture/fd0a03b8698f9ed569c70682e00a372b/raw/mapreduce -o ~/bin/mapreduce && chmod +x ~/bin/mapreduce
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sudo curl -#SL https://gist.githubusercontent.com/NewFuture/fd0a03b8698f9ed569c70682e00a372b/raw/mapreduce -o /usr/local/bin/mapreduce && sudo chmod +x /usr/local/bin/mapreduce