Coder Social home page Coder Social logo

hadoopmrexamples's Introduction

HadoopMRExamples

Example of Hadoop Map Reduce program to find in year 2016 what is average volume per stock. Following is the SQL equivalent if the data stored in a database table.

com.example.stock.StockPriceCalculatorV1

Select symbol, avg(volume) from stocks where year(date) = 2016 group by symbol 

com.example.stock.StockPriceCalculatorV2

Select symbol, year, avg(volume), max(open), min(open)  from stocks 
where year(date) = 2016 group by symbol, year(date);

com.example.stock.StockPriceCalculatorV3

Select symbol, avg(volume) from stocks where year(date) = 2016 
group by symbol order by avg(volume) asc;

com.example.stock.StockPriceCalculatorV3

Select symbol, avg(volume) from stocks where year(date) = 2016 
group by symbol order by avg(volume) asc;

com.example.movielens.AverageMovieRating

Select movieId, title, avg(rating), count(*) from movies 
join ratings on movies.movieId = ratings.movieId 
group by movies.movieId, movies.title;

More more instructions on how to build a maven project for Hadoop Map Reduce, look at the following article. https://blog.einext.com/hadoop/creating-a-hadoop-mr-project-using-maven

To run this example

$ mkdir ~/workspaces
$ cd ~/workspaces
$ git clone https://github.com/abulbasar/HadoopMRExamples.git
$ cd HadoopMRExamples

Compile project into a jar file

$ mvn clean package

Download test data and upload to HDFS

$ wget https://raw.githubusercontent.com/abulbasar/data/master/stocks.small.csv
$ hadoop fs -mkdir stocks
$ hadoop fs -put stocks.small.csv stocks/

Run hadoop jar command to execute

$ hadoop jar target/HadoopMRExamples-1.0-SNAPSHOT.jar com.example.stock.StockPriceCalculatorV1 stocks stocks_avg

Once the job is finished, check the output in to HDFS

$ hadoop fs -cat stocks_avg/*

hadoopmrexamples's People

Contributors

abulbasar avatar

Stargazers

Sivagurunathan Venkatachalapathy 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.