Skip to content

Instantly share code, notes, and snippets.

@NewFuture
Last active October 18, 2016 17:32
Show Gist options
  • Select an option

  • Save NewFuture/fd0a03b8698f9ed569c70682e00a372b to your computer and use it in GitHub Desktop.

Select an option

Save NewFuture/fd0a03b8698f9ed569c70682e00a372b to your computer and use it in GitHub Desktop.
yes! hadoop
#!/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
#!/usr/bin/env python
import sys
print(max([len(l.strip()) for l in sys.stdin]))
#!/usr/bin/env python
import sys
print(max(map(int, sys.stdin)))
#!/usr/bin/env python
import sys
for line in sys.stdin:
print(max(map(len, line.split())))
#!/usr/bin/env python
import sys
print(max(map(int, sys.stdin)))
@NewFuture
Copy link
Copy Markdown
Author

NewFuture commented Oct 15, 2016

sudo curl -#SL https://gist.githubusercontent.com/NewFuture/fd0a03b8698f9ed569c70682e00a372b/raw/mapreduce -o /usr/local/bin/mapreduce && sudo chmod +x /usr/local/bin/mapreduce

@NewFuture
Copy link
Copy Markdown
Author

NewFuture commented Oct 15, 2016

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