Changes between Version 20 and Version 21 of LogParser
- Timestamp:
- Jul 8, 2008, 10:18:18 AM (17 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
LogParser
v20 v21 36 36 37 37 {{{ 38 #!java 38 39 public class LogParserGo { 39 40 static HBaseConfiguration conf = new HBaseConfiguration(); … … 49 50 }}} 50 51 !LogParserGo共宣告了以下幾個全域變數及方法: 51 1 HBaseConfiguration conf為重要的控制設定參數,其定義了很多方法可以設定或取得map reduce程式運作所需要的值 52 53 1 HBaseConfiguration conf為重要的控制設定參數,其定義了很多方法可以設定或取得map reduce程式運作所需要的值 52 54 2 定義 TABLE 為 "table.name",table.name為 name property 53 3 string !tableName 為資料表名稱 54 4 Htable table 在定義一個HBase的操作變數 55 5 class !MapClass 為實做map的一個內部類別 56 6 Path[] !listPaths 是個可以列出指定路徑下的檔案和目錄,原本0.16 API即宣告 Deprecated,因此為了解決warning在此實做 57 7 void !runMapReduce(String table, String dir) 跑MapReduce的程序 58 8 void !creatTable(String table) 建立hbase的資料表 59 9 void main(String[] args) main 函數 55 3 string !tableName 為資料表名稱 56 4 Htable table 在定義一個HBase的操作變數 57 5 class !MapClass 為實做map的一個內部類別 58 6 Path[] !listPaths 是個可以列出指定路徑下的檔案和目錄,原本0.16 API即宣告 Deprecated,因此為了解決warning在此實做 59 7 void !runMapReduce(String table, String dir) 跑MapReduce的程序 60 8 void !creatTable(String table) 建立hbase的資料表 61 9 void main(String[] args) main 函數 60 62 61 63 1~4為變數較為單純,之後將說明5~9的函數功能 … … 117 119 並沒有用到 output的寫入方式,reporter也沒有用到。[[br]] 118 120 此方法因為有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]]121 首先!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]] 120 122 table是全域變數之一,由 [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 123 因此 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]] … … 259 261 || ip || - || - || 時間 || "http " || 回傳碼 || 長度 || "指引" || "代理器" || 260 262 || 140.110.138.176 || - || - || [02/Jul/2008:16:55:02 +0800] || "GET /hbase-0.1.3.zip HTTP/1.0" || 200 || 10249801 || " -" || "Wget/1.10.2" || 261 之後就很顯而易見,用matcher.group(n)取得值後,一一的用this.參數來作設定,但其實不用this 編譯依然能過關,只是習慣在建構子內用到該class的參數會這麼用(以跟繼承到父類別的參數作區別?)其中時間需要用 SimpleDateFormat小轉譯一下,http的內容需要用split()來作更細部的分解。263 之後就很顯而易見,用matcher.group(n)取得值後,一一的用this.參數來作設定,但其實不用this 編譯依然能過關,只是習慣在建構子內用到該class的參數會這麼用(以跟繼承到父類別的參數作區別?)其中時間需要用!SimpleDateFormat小轉譯一下,http的內容需要用split()來作更細部的分解。 262 264 263 265 {{{