{{{ #!html
案例實務
NCHC 餐廳
}}} [[PageOutline]] [wiki:waue/2011/0426 >> 回課程大綱] = 執行環境 = * 檢查是否有加裝 transactional 函式庫 * 加裝 tableindexed 函式庫 {{{ cp /opt/hbase/contrib/transactional/hbase-*-transactional.jar /opt/hbase/lib/ }}} * 重新啟動 hbase {{{ /opt/hbase/bin/stop-hbase.sh /opt/hbase/bin/start-hbase.sh }}} = 事先準備 = * 請先準備以下檔案 * /tmp/NCHC/store.txt {{{ #!text T01;GunLong; 01;20;40;30;50 T02;Esing; 02;50 T03;SunDon; 03;40;30 T04;StarBucks; 04;50;50;20 }}} * 請準備以下檔案,並將 income 資料夾上傳到hdfs * /tmp/NCHC/income/0202.txt {{{ #!text waue:T01:P1:xxxxx jazz:T01:P2:xxxxx lia:T01:P3:xxxxx hung:T02:P1:xxxxx lia:T04:P1:xxxxx lia:T04:P1:xxxxx hung:T04:P3:xxxxx hung:T04:P2:xxxxx }}} * /tmp/NCHC/income/0203.txt {{{ #!text xxx:T01:P4:xxxxx ooo:T02:P1:xxxxx oo:T03:P1:xxxxx xxx:T03:P1:xxxxx aaa:T03:P1:xxxxx }}} * 上傳到 HDFS {{{ $ /opt/hadoop/bin/hadoop fs -put /tmp/NCHC/income/ income }}} == 假設: == 目前有四間商店進駐 NCHC ,分別為 位在第1區的GunLong,品項4項單價為<20,40,30,50> 第2區的ESing,品項1項單價為<50> 第3區的SunDon,品項2項單價為<40,30> 第4區的StarBucks,品項3項單價為<50,50,20> == 1. 建立商店資料 == [wiki:waue/2011/0425_NCHC1LoadFile NCHC1LoadFile.java ], || || Detail || Detail || Products || Products || Products || Products || Turnover || || || Name || Locate || P1 || P2 || P3 || P4|| || || T01 || Gun-Long || 01 || 20 || 40 || 30 || 50 || || || T02 || ESing || 02 || 50 || || || || || || T03 || Sun-Don || 03 || 40 || 30 || || || || || T04 || Star Bucks || 04 || 50 || 50 || || || || {{{ $ /opt/hadoop/bin/hadoop jar NCHCMenu.jar NCHC1LoadFile }}} {{{ create new table: NCHC Put data :"GunLong" to Table: NCHC's Detail:Name Put data :"01" to Table: NCHC's Detail:Locate Put data :"20" to Table: NCHC's Products:P1 Put data :"40" to Table: NCHC's Products:P2 Put data :"30" to Table: NCHC's Products:P3 Put data :"50" to Table: NCHC's Products:P4 Put data :"Esing" to Table: NCHC's Detail:Name Put data :"02" to Table: NCHC's Detail:Locate Put data :"50" to Table: NCHC's Products:P1 Put data :"SunDon" to Table: NCHC's Detail:Name Put data :"03" to Table: NCHC's Detail:Locate Put data :"40" to Table: NCHC's Products:P1 Put data :"30" to Table: NCHC's Products:P2 Put data :"StarBucks" to Table: NCHC's Detail:Name Put data :"04" to Table: NCHC's Detail:Locate Put data :"50" to Table: NCHC's Products:P1 Put data :"50" to Table: NCHC's Products:P2 Put data :"20" to Table: NCHC's Products:P3 }}} == 2 計算單月每個品項的購買次數 == [wiki:waue/2011/0425_NCHC2Count NCHC2Count.java] , {{{ $ /opt/hadoop/bin/hadoop jar NCHCMenu.jar NCHC2Count }}} || || Detail ||Detail || Products || Products||Products || Products|| Turnover || Turnover || Turnover || Turnover || || || || Name || Locate || P1 || P2 || P3 || P4|| P1 || P2 || P3 || P4 || || || T01 || Gun-Long || 01 || 20 || 40 || 30 || 50 || 1 || 1 || 1 || 1 || || || T02 || ESing || 02 || 50 || || || ||2 || || || || || || T03 || Sun-Don || 03 || 40 || 30 || || ||3 || || || || || || T04 || Star Bucks || 04 || 50 || 50 || || ||2 || 1 || 1 || || || {{{ > scan 'NCHC' ROW COLUMN+CELL T01 column=Detail:Locate, timestamp=1265184360616, value=01 T01 column=Detail:Name, timestamp=1265184360548, value=GunLong T01 column=Products:P1, timestamp=1265184360694, value=20 T01 column=Products:P2, timestamp=1265184360758, value=40 T01 column=Products:P3, timestamp=1265184360815, value=30 T01 column=Products:P4, timestamp=1265184360866, value=50 T01 column=Turnover:P1, timestamp=1265187021528, value=1 T01 column=Turnover:P2, timestamp=1265187021528, value=1 T01 column=Turnover:P3, timestamp=1265187021528, value=1 T01 column=Turnover:P4, timestamp=1265187021528, value=1 T02 column=Detail:Locate, timestamp=1265184360951, value=02 T02 column=Detail:Name, timestamp=1265184360910, value=Esing T02 column=Products:P1, timestamp=1265184361051, value=50 T02 column=Turnover:P1, timestamp=1265187021528, value=2 T03 column=Detail:Locate, timestamp=1265184361124, value=03 T03 column=Detail:Name, timestamp=1265184361098, value=SunDon T03 column=Products:P1, timestamp=1265184361189, value=40 T03 column=Products:P2, timestamp=1265184361259, value=30 T03 column=Turnover:P1, timestamp=1265187021529, value=3 T04 column=Detail:Locate, timestamp=1265184361311, value=04 T04 column=Detail:Name, timestamp=1265184361287, value=StarBucks T04 column=Products:P1, timestamp=1265184361343, value=50 T04 column=Products:P2, timestamp=1265184361386, value=50 T04 column=Products:P3, timestamp=1265184361422, value=20 T04 column=Turnover:P1, timestamp=1265187021529, value=2 T04 column=Turnover:P2, timestamp=1265187021529, value=1 T04 column=Turnover:P3, timestamp=1265187021529, value=1 4 row(s) in 0.0310 seconds }}} == 3. 計算當天營業額 == [wiki:waue/2011/0425_NCHC3CalculateMR NCHC3CalculateMR.java], {{{ $ /opt/hadoop/bin/hadoop jar NCHCMenu.jar NCHC3CalculateMR }}} || || Detail || Detail || Products || Products|| Products || Products || Turnover || Turnover || Turnover || Turnover || Turnover || || || Name || Locate || P1 || P2 || P3 || P4|| P1 || P2 || P3 || P4 || Sum || || T01 || Gun-Long || 01 || 20 || 40 || 30 || 50 || 1 || 1 || 1 || 1 || 140 || || T02 || ESing || 02 || 50 || || || ||2 || || || || 100 || || T03 || Sun-Don || 03 || 40 || 30 || || ||3 || || || || 120 || || T04 || Star Bucks || 04 || 50 || 50 || || ||2 || 1 || 1 || || 170 || {{{ > scan ‘NCHC’ ROW COLUMN+CELL T01 column=Detail:Locate, timestamp=1265184360616, value=01 T01 column=Detail:Name, timestamp=1265184360548, value=GunLong T01 column=Products:P1, timestamp=1265184360694, value=20 T01 column=Products:P2, timestamp=1265184360758, value=40 T01 column=Products:P3, timestamp=1265184360815, value=30 T01 column=Products:P4, timestamp=1265184360866, value=50 T01 column=Turnover:P1, timestamp=1265187021528, value=1 T01 column=Turnover:P2, timestamp=1265187021528, value=1 T01 column=Turnover:P3, timestamp=1265187021528, value=1 T01 column=Turnover:P4, timestamp=1265187021528, value=1 T01 column=Turnover:sum, timestamp=1265190421993, value=140 T02 column=Detail:Locate, timestamp=1265184360951, value=02 T02 column=Detail:Name, timestamp=1265184360910, value=Esing T02 column=Products:P1, timestamp=1265184361051, value=50 T02 column=Turnover:P1, timestamp=1265187021528, value=2 T02 column=Turnover:sum, timestamp=1265190421993, value=100 T03 column=Detail:Locate, timestamp=1265184361124, value=03 T03 column=Detail:Name, timestamp=1265184361098, value=SunDon T03 column=Products:P1, timestamp=1265184361189, value=40 T03 column=Products:P2, timestamp=1265184361259, value=30 T03 column=Turnover:P1, timestamp=1265187021529, value=3 T03 column=Turnover:sum, timestamp=1265190421993, value=120 T04 column=Detail:Locate, timestamp=1265184361311, value=04 T04 column=Detail:Name, timestamp=1265184361287, value=StarBucks T04 column=Products:P1, timestamp=1265184361343, value=50 T04 column=Products:P2, timestamp=1265184361386, value=50 T04 column=Products:P3, timestamp=1265184361422, value=20 T04 column=Turnover:P1, timestamp=1265187021529, value=2 T04 column=Turnover:P2, timestamp=1265187021529, value=1 T04 column=Turnover:P3, timestamp=1265187021529, value=1 T04 column=Turnover:sum, timestamp=1265190421993, value=170 4 row(s) in 0.0460 seconds }}} == 4. 建立索引資料表 == [wiki:waue/2011/0425_NCHC4SortTurnover NCHC4SortTurnover.java] {{{ $ /opt/hadoop/bin/hadoop jar NCHCMenu.jar NCHC4SortTurnover }}} {{{ > scan 'NCHC-Sum' ROW COLUMN+CELL 100T02 column=Turnover:Sum, timestamp=1265190782127, value=100 100T02 column=__INDEX__:ROW, timestamp=1265190782127, value=T02 120T03 column=Turnover:Sum, timestamp=1265190782128, value=120 120T03 column=__INDEX__:ROW, timestamp=1265190782128, value=T03 140T01 column=Turnover:Sum, timestamp=1265190782126, value=140 140T01 column=__INDEX__:ROW, timestamp=1265190782126, value=T01 170T04 column=Turnover:Sum, timestamp=1265190782129, value=170 170T04 column=__INDEX__:ROW, timestamp=1265190782129, value=T04 4 row(s) in 0.0140 seconds }}} == 4.b 產生最終報表 == [wiki:waue/2011/0425_NCHC5ShowReport NCHC5ShowReport.java] {{{ $ /opt/hadoop/bin/hadoop jar NCHCMenu.jar NCHC5ShowReport 130 }}} {{{ #!text SunDon 's turnover is 120 $. GunLong 's turnover is 140 $. StarBucks 's turnover is 170 $. }}}