Code Monkey home page Code Monkey logo

mapreduce-exercise's Introduction

MapReduce

This repo provides two examples and a script to easily define and run mapper and reducer functions against Hadoop MapReduce.

Generally speaking, on the top level there are folders that must contain:

  • mapper.py
  • reducer.py
  • sample directory with data to be copied in hdfs within docker container

ENSURE THAT .py FILES HAVE chmod +x PERMISSIONS (This is hadoop requirement)

Of course, the idea is to add more folders that demonstrate different aggregations that can be achieved with MapReduce over different datasaets (that are available in the sample folder). The aspiration was to make something reusable quickly and cheaply.

Usage

  1. Download this repo
  2. CD into this repo
  3. Run the following
docker run -v $(pwd):/usr/local/hadoop/py -it sequenceiq/hadoop-docker:2.7.1 /usr/local/hadoop/py/py_runner.sh basic_grep

(notice the grep keyword at the end - corresponds to the folder basic_grep!)

expected output:

foo	6
quux	4

Another example:

docker run -v $(pwd):/usr/local/hadoop/py -it sequenceiq/hadoop-docker:2.7.1 /usr/local/hadoop/py/py_runner.sh count

(notice the count keyword at the end - corresponds to the folder count!)

expected output:

bar	0
foo	6
labs	0
quux	4

Additional Exercises

A) Using Regex:

The sample files were changed from the original one in basic_grep/ count to add some words to test for the given conditions.

1. Check for all the words that have "oo" as part of the string

  • Command
docker run -v $(pwd):/usr/local/hadoop/py -it sequenceiq/hadoop-docker:2.7.1 /usr/local/hadoop/py/py_runner.sh exercise "oo"
  • Output
foo  6

2. Check for all words that have 'k' in the beginning and 'e' at the end of the string

  • Command
docker run -v $(pwd):/usr/local/hadoop/py -it sequenceiq/hadoop-docker:2.7.1 /usr/local/hadoop/py/py_runner.sh exercise "^k[a-zA-Z]*e$"
  • Output
kettle  1
kite    1

3. Check for all words that have only 'one' capital letters positioned anywhere in the string

  • Command
docker run -v $(pwd):/usr/local/hadoop/py -it sequenceiq/hadoop-docker:2.7.1 /usr/local/hadoop/py/py_runner.sh exercise "^[a-z]*[A-Z][a-z]*$"
  • Output
Hello   1
Tanay   1
World   1
hEllo   1
wOrld   1

(notice the exercise keyword at the end of the command corresponds to the folder exercise!)

B) Using SQL Query:

A sample database was created and we inserted some values to test the given conditions by running some queries.

1. Check for all the words that have "oo" as part of the string

  • Query
SELECT str, count(*) FROM word WHERE str LIKE '%oo%'
  • Output
[('FooBar',), ('foobar',), ('bookworm',),(3,)]

2. Check for all words that starts with f/F

  • Query
SELECT Count(*) FROM word WHERE str LIKE 'f%' OR str LIKE 'F%'
  • Output
[(2,)]

3. Check for all words that have capital letters positioned anywhere in the string

  • Command
SELECT str, Count(*) FROM word WHERE LOWER(str) != str
  • Output
[('FooBar', 1)]

References

mapreduce-exercise's People

Contributors

tanaymukherjee avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.