| 1 | [[PageOutline]] |
| 2 | |
| 3 | ◢ <[wiki:NTUT160625/Lab8 實作八]> | <[wiki:NTUT160625 回課程大綱]> ▲ | <[wiki:NTUT160625/Lab10 實作十]> ◣ |
| 4 | |
| 5 | = 實作九 Lab 9 = |
| 6 | |
| 7 | {{{ |
| 8 | #!html |
| 9 | <div style="text-align: center;"><big style="font-weight: bold;"><big>練習豬的拉丁語<br/>Pig Latin in Practice</big></big></div> |
| 10 | }}} |
| 11 | |
| 12 | {{{ |
| 13 | #!text |
| 14 | 以下練習,請連線至 hdp01.3du.me 操作。底下的 userXX 等於您的用戶名稱。 |
| 15 | 以下練習,請連線至 hdp02.3du.me 操作。底下的 userXX 等於您的用戶名稱。 |
| 16 | 以下練習,請連線至 hdp03.3du.me 操作。底下的 userXX 等於您的用戶名稱。 |
| 17 | 以下練習,請連線至 hdp04.3du.me 操作。底下的 userXX 等於您的用戶名稱。 |
| 18 | }}} |
| 19 | |
| 20 | == Aggregation (Local Mode) == |
| 21 | |
| 22 | {{{ |
| 23 | ~$ wget http://www.hadoop.tw/excite-small.log |
| 24 | ~$ pig -x local |
| 25 | grunt> log = LOAD 'excite-small.log' AS (user, timestamp, query); |
| 26 | grunt> grpd = GROUP log BY user; |
| 27 | grunt> cntd = FOREACH grpd GENERATE group, COUNT(log); |
| 28 | grunt> STORE cntd INTO 'lab8_out1'; |
| 29 | grunt> quit |
| 30 | ~$ head lab8_out1/part-* |
| 31 | }}} |
| 32 | |
| 33 | == Filter (Local Mode) == |
| 34 | |
| 35 | {{{ |
| 36 | ~$ pig -x local |
| 37 | grunt> log = LOAD 'excite-small.log' AS (user, timestamp, query); |
| 38 | grunt> grpd = GROUP log BY user; |
| 39 | grunt> cntd = FOREACH grpd GENERATE group, COUNT(log) AS cnt; |
| 40 | grunt> fltrd = FILTER cntd BY cnt > 50; |
| 41 | grunt> STORE fltrd INTO 'lab8_out2'; |
| 42 | grunt> quit |
| 43 | ~$ head lab8_out2/part-* |
| 44 | }}} |
| 45 | |
| 46 | == Sorting (Local Mode) == |
| 47 | |
| 48 | {{{ |
| 49 | ~$ pig -x local |
| 50 | grunt> log = LOAD 'excite-small.log' AS (user, timestamp, query); |
| 51 | grunt> grpd = GROUP log BY user; |
| 52 | grunt> cntd = FOREACH grpd GENERATE group, COUNT(log) AS cnt; |
| 53 | grunt> fltrd = FILTER cntd BY cnt > 50; |
| 54 | grunt> srtd = ORDER fltrd BY cnt; |
| 55 | grunt> STORE srtd INTO 'lab8_out3'; |
| 56 | grunt> quit |
| 57 | ~$ head lab8_out3/part-* |
| 58 | }}} |
| 59 | |
| 60 | == Connect Pig to Hadoop (Full Distributed Mode) == |
| 61 | |
| 62 | {{{ |
| 63 | ~$ hadoop fs -put excite-small.log . |
| 64 | ~$ pig |
| 65 | grunt> log = LOAD 'excite-small.log' AS (user, timestamp, query); |
| 66 | grunt> grpd = GROUP log BY user; |
| 67 | grunt> cntd = FOREACH grpd GENERATE group, COUNT(log); |
| 68 | grunt> STORE cntd INTO 'lab8_out1'; |
| 69 | grunt> quit |
| 70 | ~$ hadoop fs -cat lab8_out1/part-00000 |
| 71 | }}} |