{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Simple distributed wordcount with MapReduce" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Check that file `file.txt` exists, view size." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "!ls -hal file.txt" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Copy file to HDFS" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "!hdfs dfs -put -f file.txt " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Erase `result` folder." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "!hdfs dfs -rm -R result 2>/dev/null" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Run the bash wordcount command `wc` in parallel on the distributed file." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "!mapred streaming \\\n", " -input file.txt \\\n", " -output result \\\n", " -mapper /bin/cat \\\n", " -reducer /usr/bin/wc " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Check result of MapReduce job" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "!hdfs dfs -cat result/part*" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Check that the word count is correct by comparing with `wc` on local host (warning: do not try with too large files)." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "!wc file.txt" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.6" } }, "nbformat": 4, "nbformat_minor": 2 }