Recommended
PDF
PHP と MySQL でカジュアルに MapReduce する (Short Version)
PDF
PHP と MySQL で 1 カチャカチャカチャ...ッターン! MapReduce (@ニコニコ超会議)
PDF
20170923 excelユーザーのためのr入門
PPTX
Hadoop Streamingを使って お好きな言語でMap☆Reduce!
KEY
Big data and APIs for PHP developers - SXSW 2011
PDF
PDF
PPTX
PPTX
PDF
PPTX
PDF
Data-Intensive Text Processing with MapReduce ch4
PDF
"Programming Hive" Reading #1
PDF
OSC2011 Tokyo/Spring Hadoop入門
PDF
PDF
PDF
Random partionerのデータモデリング
PDF
MapReduceによる大規模データ処理 at Yahoo! JAPAN
PDF
EucalyptusのHadoopクラスタとJaqlでBasket解析をしてHiveとの違いを味わってみました
PDF
PDF
PDF
PDF
20110517 okuyama ソーシャルメディアが育てた技術勉強会
PDF
PDF
B33 Super HadoopでRockなR&D by 平間大輔
PDF
Apache Drill: Rethinking SQL for Big data – Don’t Compromise on Flexibility o...
PDF
Programming in Scala Chapter 17 Collections
KEY
PDF
PDF
Good Parts of PHP and the UNIX Philosophy
More Related Content
PDF
PHP と MySQL でカジュアルに MapReduce する (Short Version)
PDF
PHP と MySQL で 1 カチャカチャカチャ...ッターン! MapReduce (@ニコニコ超会議)
PDF
20170923 excelユーザーのためのr入門
PPTX
Hadoop Streamingを使って お好きな言語でMap☆Reduce!
KEY
Big data and APIs for PHP developers - SXSW 2011
PDF
PDF
PPTX
Similar to PHP と MySQL でカジュアルに MapReduce する
PPTX
PDF
PPTX
PDF
Data-Intensive Text Processing with MapReduce ch4
PDF
"Programming Hive" Reading #1
PDF
OSC2011 Tokyo/Spring Hadoop入門
PDF
PDF
PDF
Random partionerのデータモデリング
PDF
MapReduceによる大規模データ処理 at Yahoo! JAPAN
PDF
EucalyptusのHadoopクラスタとJaqlでBasket解析をしてHiveとの違いを味わってみました
PDF
PDF
PDF
PDF
20110517 okuyama ソーシャルメディアが育てた技術勉強会
PDF
PDF
B33 Super HadoopでRockなR&D by 平間大輔
PDF
Apache Drill: Rethinking SQL for Big data – Don’t Compromise on Flexibility o...
PDF
Programming in Scala Chapter 17 Collections
KEY
More from Yuya Takeyama
PDF
PDF
Good Parts of PHP and the UNIX Philosophy
PDF
Reactor Pattern and React
PDF
PDF
PDF
PDF
Proposal for xSpep BDD Framework for PHP
PDF
Building Development Environment with php-build and phpenv
PDF
PDF
PDF
LIMIT 付きで UPDATE を行うと何故怒られるか
PDF
PDF
ODP
第一回 社内勉強会 PHP Application Security Checklist に学ぶ PHP セキュリティ (Excerpt)
Recently uploaded
PDF
論文紹介:Simultaneous Detection and Interaction Reasoning for Object-Centric Acti...
PDF
ReflecTrace: Hover Interface using Corneal Reflection Images Captured by Smar...
PDF
論文紹介:"MM-Tracker: Motion Mamba for UAV-platform Multiple Object Tracking", "M...
PDF
論文紹介:"Reflexion: language agents with verbal reinforcement learning", "MA-LMM...
PDF
歴史好きのスクラム話 JBUG名古屋#5 AI時代のデータドリブンなプロジェクト管理
PDF
手軽に広範囲でプライバシーを守りながら人数カウントできる ~ LoRaWAN AI人流カウンター PF52 日本語カタログ
PDF
論文紹介: "Locality-Aware Zero-Shot Human-Object Interaction Detection" "Disentan...
PDF
How We Operated Ticket-Driven Development in JIRA.pdf
PHP と MySQL でカジュアルに MapReduce する 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. やや厳密な 入力
処理の流れ ↓
Map
↓
Shuffle
↓
Reduce
より厳密には ↓
もっと複雑らしいです
出力
11. 12. 13. 14. 15. 16. 17. Map •<"to", 1>
•<"be", 1>
•<"or", 1>
•<"not", 1>
•<"to", 1>
•<"be", 1>
18. Shuffle
•<"be", [1, 1]>
•<"not", [1]>
•<"or", [1]>
•<"to", [1, 1]>
19. Reduce
• <"be", 2>
• <"not", 1>
• <"or", 1>
• <"to", 2>
20. MapReduce の利点
•Map も Reduce も並列化
すればスケールする
•関数型っぽい考え方が活きる
※ただし, Hadoop や MongoDB の MapReduce の Map と Reduce は
関数型言語のそれとはやや異なる (参照透過でなかったり)
• パターンとして共有しやすい
※手続き型のバッチ処理と比較して
21. 22. 23. 24. 25. MyMR
https://github.com/yuya-takeyama/mymr
•MySQL を入出力とする
• PHP で Map/Reduce を書く
• コマンドラインで実行
26. 27. に よ る
yM R
M
文章中の
単語の数を数える例
(word count)
28. use MyMRBuilder;
Map/Reduce の定義
$builder = new Builder;
$builder->setInputTable('root@localhost/db/texts');
$builder->setOutputTable('root@localhost/db/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;
29. use MyMRBuilder;
Map/Reduce の定義
$builder = new Builder;
$builder->setInputTable('root@localhost/db/texts');
$builder->setOutputTable('root@localhost/db/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;
30. use MyMRBuilder;
Map/Reduce の定義
$builder = new Builder;
$builder->setInputTable('root@localhost/db/texts');
$builder->setOutputTable('root@localhost/db/word_counts');
$builder->setMapper(function ($record, $emitter) {
$words = preg_split('/s+/u', $record['text']);
foreach ($words as $word) {
$emitter->emit($word, 1);
} この辺が Map
});
$builder->setReducer(function ($key, $values) {
$sum = 0;
foreach ($values as $count) {
$sum += $count;
}
return array('count' => $sum);
});
return $builder;
31. use MyMRBuilder;
Map/Reduce の定義
$builder = new Builder;
$builder->setInputTable('root@localhost/db/texts');
$builder->setOutputTable('root@localhost/db/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); この辺が Reduce
});
return $builder;
32. 33. 34. Map レコードを
連想配列として受け取る
function ($record, $emitter) {
$words = preg_split('/s+/u',
$record['text']);
foreach ($words as $word) {
$emitter->emit($word, 1);
}
}
35. Map
function ($record, $emitter) {
$words = preg_split('/s+/u',
$record['text']);
foreach ($words as $word) {
$emitter->emit($word, 1);
}
} text カラム内の
文字列をスペースで分割
36. Map
function ($record, $emitter) {
$words = preg_split('/s+/u',
$record['text']);
foreach ($words as $word) {
$emitter->emit($word, 1);
}
}
Key/Value のペアとして
中間テーブルに INSERT
37. 38. Reduce
Key Value の配列
function ($key, $values) {
$sum = 0;
foreach ($values as $count) {
$sum += $count;
}
return array('count' => $sum);
}
39. Reduce
Value を全て足す
function ($key, $values) {
$sum = 0;
foreach ($values as $count) {
$sum += $count;
}
return array('count' => $sum);
}
40. 41. +----+--------------------+
Map | id | text |
+----+--------------------+
| 1 | to be or not to be |
+----+--------------------+
↓ レコードを連想配列として Map へ ↓
+----+---------+-------+
| id | key | value |
+----+---------+-------+
| 1 | to | 1 |
| 2 | be | 1 |
| 3 | or | 1 |
| 4 | not | 1 |
| 5 | to | 1 |
| 6 | be | 1 |
+----+---------+-------+
42. +----+--------------------+
Map | id | text |
+----+--------------------+
| 1 | to be or not to be |
+----+--------------------+
↓ レコードを連想配列として Map へ ↓
+----+---------+-------+
| id | key | value |
+----+---------+-------+
| 1 | to | 1 |
| 2 | be | 1 |
| 3 | or | 1 |
| 4 | not
value には JSON で入れるので | 1 |
| 5 | to
構造化データも使用可能 | 1 |
| 6 | be | 1 |
+----+---------+-------+
43. +----+---------+-------+
| id | key | value |
Shuffle +----+---------+-------+
| 1 | to
| 2 | be
| 1
| 1
|
|
| 3 | or | 1 |
| 4 | not | 1 |
| 5 | to | 1 |
| 6 | be | 1 |
+----+---------+-------+
↓ キーで GROUP BY して ↓
SELECT ↓ 値は GROUP_CONCAT ↓
`key`, +---------+--------+
GROUP_CONCAT(`value`) | key | values |
FROM +---------+--------+
`中間テーブル` | be | 1,1 |
| not | 1 |
GROUP BY | or | 1 |
`key` | to | 1,1 |
+---------+--------+
44. +---------+--------+
| key | values |
Reduce +---------+--------+
| be | 1,1 |
| not | 1 |
| or | 1 |
| to | 1,1 |
+---------+--------+
↓ キーと値の配列を Reduce へ ↓
+----+---------+-------+
| id | key | count |
+----+---------+-------+
| 1 | be | 2 |
| 2 | not | 1 |
| 3 | or | 1 |
| 4 | to | 2 |
+----+---------+-------+
45. +---------+--------+
| key | values |
Reduce +---------+--------+
| be | 1,1 |
| not | 1 |
| or | 1 |
実際にはデリミタとして改行を使用| to | 1,1 |
+---------+--------+
改行区切りの JSON になる
↓ キーと値の配列を Reduce へ ↓
+----+---------+-------+
| id | key | count |
+----+---------+-------+
| 1 | be | 2 |
| 2 | not | 1 |
| 3 | or | 1 |
| 4 | to | 2 |
+----+---------+-------+
46. 47. 48. 49. 50. リンク
• MyMR on GitHub
https://github.com/yuya-takeyama/mymr
• PHP と MySQL でカジュアルに MapReduce する
http://blog.yuyat.jp/archives/1706
• もっとカジュアルに PHP と MySQL で MapReduce する
http://blog.yuyat.jp/archives/1853
51.