Changes between Version 19 and Version 20 of LogParser


Ignore:
Timestamp:
Jul 8, 2008, 10:09:50 AM (16 years ago)
Author:
waue
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • LogParser

    v19 v20  
    2828 || Row || Column || Cell ||
    2929 || 118.170.101.250 || http:agent || Mozilla/4.0 (compatible; ||
    30 ..........(skip)........
     30 || ..(skip).. || ..(skip).. || ..(skip).. || 
    3131 || 87.65.93.58 || http:method || OPTIONS ||
    3232 || 87.65.93.58 || http:protocol || HTTP/1.1 ||
     
    4848
    4949}}}
    50 LogParserGo共宣告了以下幾個全域變數及方法:
    51  1 !HBaseConfiguration conf為重要的控制設定參數,其定義了很多方法可以設定或取得map reduce程式運作所需要的值
     50!LogParserGo共宣告了以下幾個全域變數及方法:
     51 1 HBaseConfiguration conf為重要的控制設定參數,其定義了很多方法可以設定或取得map reduce程式運作所需要的值
    5252 2 定義 TABLE 為 "table.name",table.name為 name property
    5353 3 string !tableName 為資料表名稱
    54  4 !Htable table 在定義一個HBase的操作變數
     54 4 Htable table 在定義一個HBase的操作變數
    5555 5 class !MapClass 為實做map的一個內部類別
    56  6 Path[] !listPaths 是個可以列出指定路徑下的檔案和目錄,原本0.16 api即宣告 Deprecated,因此為了解決warning在此實做
     56 6 Path[] !listPaths 是個可以列出指定路徑下的檔案和目錄,原本0.16 API即宣告 Deprecated,因此為了解決warning在此實做
    5757 7 void !runMapReduce(String table, String dir) 跑MapReduce的程序
    5858 8 void !creatTable(String table)  建立hbase的資料表
     
    7272}}}
    7373
    74 首先看到main函數究竟搞了些什麼?[[br]]
    75 宣告了table的名稱,要parser的檔案放在'''hdfs'''當中的哪個路徑下,注意此路徑為hdfs,若給的是local file system的路徑的話,程式跑的時候會產生!NullPointer Exception的錯誤。然後呼叫!creatTable函數其功能用來創建table,接著跑runMapReduce函數,而整個程式主體就是在runMapReduce
     74首先看到main函數究竟搞了些什麼?[[br]][[br]]
     75宣告了table的名稱,要parser的檔案放在'''hdfs'''當中的哪個路徑下,注意此路徑為hdfs,若給的是local file system的路徑的話,程式跑的時候會產生!NullPointer Exception的錯誤。然後呼叫!creatTable函數其功能用來創建table,接著跑!runMapReduce函數,而整個程式主體就是在!runMapReduce
    7676
    7777------------------------------------
     
    111111        }
    112112}}}
    113 此內部類別繼承了 [http://hadoop.apache.org/core/docs/r0.16.4/api/org/apache/hadoop/mapred/MapReduceBase.html org.apache.hadoop.mapred.MapReduceBase] ,並實做Mapper<WritableComparable, Text, Text, Writable> 介面,
     113此內部類別繼承了 [http://hadoop.apache.org/core/docs/r0.16.4/api/org/apache/hadoop/mapred/MapReduceBase.html org.apache.hadoop.mapred.MapReduceBase] ,並實做Mapper<!WritableComparable, Text, Text, Writable> 介面,
    114114不見得所有map reduce程式都需要實做此介面,但若有要讓map能分配工作就需要寫在下面此函數中:[[BR]]
    115 map(!WritableComparable key, Text value,        !OutputCollector<Text, Writable> output, Reporter reporter) [[BR]]
     115map(!WritableComparable key, Text value,!OutputCollector<Text, Writable> output, Reporter reporter) [[BR]]
    116116變數key為hbase中的row key,value則為值,output 可以透過collect() 功能將值寫入hbase的table中。但在此範例中,
    117117並沒有用到 output的寫入方式,reporter也沒有用到。[[br]]
    118 此方法因為有IO的存取,因此要宣告trows !IOException, 且用try來起始。[[br]]
    119 首先LogParser log = new !LogParser(value.toString()); value的值為要parser的內容的某一行,因為基於hdfs的map-reduce架構上,hadoop會幫我們把資料整合起來,因此程式的邏輯只要處理好這一行即可。LogParser 在下面會介紹到,目前只要知道log物件是原始資料value透過 LogParser 處理過的產物。透過log物件的方法!getIP,!getProtocol(),...等,我們可以輕易取得需要的資料,用table.put( Row_Key , Column_Qualify_Name , Value) 方法將Value值填入Row_Key中的Column_Qualify_Name欄位中。接著研究table物件。[[br]]
     118此方法因為有IO的存取,因此要宣告trows !IOException, 且用try來起始。[[br]][[br]]
     119首先!LogParser log = new !LogParser(value.toString()); value的值為要parser的內容的某一行,因為基於hdfs的map-reduce架構上,hadoop會幫我們把資料整合起來,因此程式的邏輯只要處理好這一行即可。!LogParser 在下面會介紹到,目前只要知道log物件是原始資料value透過 LogParser 處理過的產物。透過log物件的方法!getIP,!getProtocol(),...等,我們可以輕易取得需要的資料,用table.put( Row_Key , Column_Qualify_Name , Value) 方法將Value值填入Row_Key中的Column_Qualify_Name欄位中。接著研究table物件。[[br]]
    120120table是全域變數之一,由 [http://hadoop.apache.org/hbase/docs/current/api/org/apache/hadoop/hbase/HTable.html org.apache.hadoop.hbase.HTable] 類別定義。產生出HTable物件'''必定要'''給兩個初始化的值,一個是另一個全域變數也是重要的設定檔conf,另一個是tableName也就是資料表的名稱,當HTable 的 table 物件產生出來之後,我們就可以利用put來放入資料。然而一個新的資料表,要如何給他row_key呢?
    121 因此 table.startUpdate(new Text(log.getIp())) 的功能就是 將 ip設定為table的row_key。有興趣的話可以參考[http://hadoop.apache.org/hbase/docs/current/api/org/apache/hadoop/hbase/HTable.html#startUpdate(org.apache.hadoop.io.Text) 官方的startUpdate說明] [[br]]
     121因此 table.startUpdate(new Text(log.getIp())) 的功能就是 將 ip設定為table的row_key。有興趣的話可以參考[http://hadoop.apache.org/hbase/docs/current/api/org/apache/hadoop/hbase/HTable.html#startUpdate(org.apache.hadoop.io.Text) 官方的startUpdate說明] [[br]][[br]]
    122122用此方法可以回傳一個型態為Long的值,將他宣告成為lockId變數,之後就可以用他當主key,而將值一個一個輸入到對應的欄位中。因此我們可以把結構看成是這樣
    123123 || key\欄位 || http:protocol || http:method || http:code || http:bytesize || http:agent || url: || referrer: || http:code ||
    124124 || row_key  || value1 || value2 || value3 || value4 || value5 || value6 || value7 || value8 ||
    125125需要注意的是,由於Htable 是三維度的結構,row_key、column、timestamp。因此最後commit時間變數則是利用以下方法:[[br]]
    126 table.commit(lockId, log.getTimestamp()),將log內取得的時間update到整個row去。[[br]]
     126table.commit(lockId, log.getTimestamp()),將log內取得的時間update到整個row去。[[br]][[br]]
    127127
    128128configure(jobConf conf) 此為override org.apache.hadoop.mapred.MapReduceBase.configure(JobConf )