파이썬 스크립트만 짜고 더 빠른 싱글 노드에서 돌리는게 좋을 것 같아 빠르게 코딩을 했다.
mapper.py
#!/usr/bin/python3
import re
import sys
for line in sys.stdin:
line = line.strip()
words = re.findall(r'[a-z]+', line.lower())
for word in words:
print(f"{word}\\t1")
reducer.py
#!/usr/bin/python3
import sys
current_word = None
current_count = 0
for line in sys.stdin:
line = line.strip()
word, count = line.split('\\t')
count = int(count)
if current_word == word:
current_count += count
else:
if current_word is not None:
print(f"{current_word}\\t{current_count}")
current_word = word
current_count = count
if current_count > 0:
print(f"{current_word}\\t{current_count}")
mapreduce 작업 명령어 순서
# input 파일 (모비딕 e북)이 들어갈 경로 생성 및 파일 첨부
bin/hdfs dfs -mkdir -p input
bin/hdfs dfs -put MobyDick.txt input
# python script 실행권한 부여
chmod +x Mapper.py Reducer.py
# map reduce 작업 실행
bin/mapred streaming \\
-input input/MobyDick.txt \\
-output result \\
-file Mapper.py \\
-file Reducer.py \\
-mapper Mapper.py \\
-reducer Reducer.py
얼마 안걸려서 다행이다..
docker run --name softeer_w3m3 \\
-p 8088:8088 \\
-p 9870:9870 \\
-it -d softeer:w3m3