Coder Social home page Coder Social logo

mymr's Introduction

MyMR

master: Build Status develop: Build Status

MapReduce framework using PHP and MySQL.

Currently this application is under heavy development. Some interfaces may change.

Features

Class based MapReduce definition.

<?php
/**
 * Class based word-count example for MyMR.
 *
 * @author Yuya Takeyama
 */
use \MyMR\Base,
    \MyMR\Emitter;

class WordCount extends Base
{
    public function map($record, Emitter $emitter)
    {
        $words = preg_split('/\s+/u', $record['text']);
        foreach ($words as $word) {
            $emitter->emit($word, 1);
        }
    }

    public function reduce($key, $values)
    {
        $sum = 0;
        foreach ($values as $count) {
            $sum += $count;
        }
        return array('count' => $sum);
    }
}

Builder script based MapReduce definition.

<?php
/**
 * Builder script based word-count example for MyMR.
 *
 * @author Yuya Takeyama
 */
use \MyMR\Builder;

$builder = new Builder;

$builder->setInputTable('root@localhost/mymr_wordcount_example/texts');
$builder->setOutputTable('root@localhost/mymr_wordcount_example/word_counts');

$builder->setMapper(function ($record, $emitter) {
    $words = preg_split('/\s+/u', $record['text']);
    foreach ($words as $word) {
        $emitter->emit($word, 1);
    }
});

$builder->setReducer(function ($key, $values) {
    $sum = 0;
    foreach ($values as $count) {
        $sum += $count;
    }
    return array('count' => $sum);
});

return $builder;

Installation

Currently MyMR can be installed from GitHub.

$ git clone [email protected]:yuya-takeyama/mymr.git
$ cd mymr

# Install dependencies using Composer.
$ php composer.phar install

# Display usage.
$ ./bin/mymr

Running examples

Some examples are in ./examples directory.

Test data installation

$ mysql -u USER --database INPUT_DATABASE -p < examples/sql/wordcount_example_db.sql

Running class based example

$ ./bin/mymr class examples/WordCount.php -i USER:PASSWORD@DATABASE/INPUT_DATABASE/texts -o USER:PASSWORD@DATABASE/OUTPUT_DATABASE/word_counts

Running builder script based example

-i and -o parameter is optional if they are defined in builder script.

$ ./bin/mymr builder examples/word_count_script.php

Articles

Author

Yuya Takeyama http://yuyat.jp/

mymr's People

Contributors

sasezaki avatar yuya-takeyama avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

sasezaki x51xxx

mymr's Issues

Map/Reduce with MySQL

MySQL を使ってカジュアルに Map/Reduce するためのフレームワーク.

  • 入力はテーブル (SQL でフィルタ可能)
  • Mapper はレコード 1 行を受け取り, Key/Value のペアを emit する
  • emit すると作業用のテーブルに INSERT される
  • key というカラムに Key が入り, value というカラムに value が JSON で入る
  • Reducer は Key と, Value の配列を受ける
  • Reducer で Value を返すことで, 出力テーブルに INSERT される

これらを, SQL を意識せずに, それでいて最適化のために SQL も使えるようにする.
(GROUP BY を使った finalize とか)

Reducer にデータを渡すための SQL は以下のようなイメージ.

SELECT
  key,
  GROUP_CONCAT(value SEPARATOR '\n') AS values
FROM
  emitted_values
GROUP BY
  key

これで key と改行区切りの JSON のペアが受け取れるので, フレームワーク側で Value を配列にすることができる.

ビッグデータは無くとも, プログラミングモデルとして Map/Reduce を使いたい, というモチベーションがある.

ただし, それ MongoDB でできるよ, という話ではある.

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.