wiki:waue/2010/0205-00

Version 6 (modified by waue, 15 years ago) (diff)

--

案例實務
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
      

假設:

目前有四間商店進駐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 Products
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 StarBucks? 04 50 50
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 ,

Detail Products
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 StarBucks? 04 50 50
> 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,

> 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

> 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