wiki:waue/2010/0205-00
案例實務
TSMC 餐廳

事先準備

  • 請先準備以下檔案
    • /tmp/tsmc/store.txt
      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/tsmc/income/0202.txt
      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/tsmc/income/0203.txt
      xxx:T01:P4:xxxxx
      ooo:T02:P1:xxxxx
      oo:T03:P1:xxxxx
      xxx:T03:P1:xxxxx
      aaa:T03:P1:xxxxx
      

可用 tsmcHBase_100204.jar 作此範例測試

假設:

目前有四間商店進駐TSMC餐廳,分別為

位在 第1區的GunLong,品項4項單價為<20,40,30,50>

第2區的ESing,品項1項單價為<50>

第3區的SunDon,品項2項單價為<40,30>

第4區的StarBucks,品項3項單價為<50,50,20>

1. 建立商店資料

TSMC1LoadFile.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 tsmcHBase_100204.jar TSMC1LoadFile
create new table: tsmc
Put data :"GunLong" to Table: tsmc's Detail:Name
Put data :"01" to Table: tsmc's Detail:Locate
Put data :"20" to Table: tsmc's Products:P1
Put data :"40" to Table: tsmc's Products:P2
Put data :"30" to Table: tsmc's Products:P3
Put data :"50" to Table: tsmc's Products:P4

Put data :"Esing" to Table: tsmc's Detail:Name
Put data :"02" to Table: tsmc's Detail:Locate
Put data :"50" to Table: tsmc's Products:P1

Put data :"SunDon" to Table: tsmc's Detail:Name
Put data :"03" to Table: tsmc's Detail:Locate
Put data :"40" to Table: tsmc's Products:P1
Put data :"30" to Table: tsmc's Products:P2

Put data :"StarBucks" to Table: tsmc's Detail:Name
Put data :"04" to Table: tsmc's Detail:Locate
Put data :"50" to Table: tsmc's Products:P1
Put data :"50" to Table: tsmc's Products:P2
Put data :"20" to Table: tsmc's Products:P3

2 計算單月每個品項的購買次數

TSMC2Count.java ,

$ /opt/hadoop/bin/hadoop jar tsmcHBase_100204.jar TSMC2Count
Detail Detail Products ProductsProducts 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 'tsmc'
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. 計算當天營業額

TSMC3CalculateMR.java,

$ /opt/hadoop/bin/hadoop jar tsmcHBase_100204.jar TSMC3CalculateMR
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 ‘tsmc’
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. 建立索引資料表

TSMC4SortTurnover.java

$ /opt/hadoop/bin/hadoop jar tsmcHBase_100204.jar TSMC4SortTurnover
> scan 'tsmc-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 產生最終報表

$ /opt/hadoop/bin/hadoop jar tsmcHBase_100204.jar TSMC5ShowReport 130
SunDon 's turnover is 120 $.
GunLong 's turnover is 140 $.
StarBucks 's turnover is 170 $.
Last modified 11 years ago Last modified on Feb 5, 2010, 12:08:48 AM