欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
簡(jiǎn)單使用hbase

簡(jiǎn)單使用hbase

關(guān)鍵字: hbase

我們來(lái)簡(jiǎn)單了解如何操作hbase,hbase與我們常用的數據庫最大的差別就是列存儲和無(wú)數據類(lèi)型,所有數據都以string類(lèi)型存儲,再有如果hbase table里有5個(gè)字段,但實(shí)際只有4個(gè)字段有值,那么為null的那個(gè)字段是不占用空間的,這點(diǎn)比較好,可以跟我們常用的數據庫比較下
首先還是創(chuàng )建一個(gè)表,暫不使用mapreduce:

Java代碼
  1. /**  
  2.  * 定義幾個(gè)常量  
  3.  */  
  4. public static HBaseConfiguration conf = new HBaseConfiguration();   
  5. static HTable table = null;   
  6. /**  
  7.  * 創(chuàng )建hbase table  
  8.  * @param table  
  9.  * @throws IOException  
  10.  */  
  11. public static void creatTable(String tablename) throws IOException {   
  12.     HBaseAdmin admin = new HBaseAdmin(conf);   
  13.     if (!admin.tableExists(new Text(tablename))) {   
  14.         HTableDescriptor tableDesc = new HTableDescriptor(tablename);   
  15.         tableDesc.addFamily(new HColumnDescriptor("ip:"));   
  16.         tableDesc.addFamily(new HColumnDescriptor("time:"));   
  17.         tableDesc.addFamily(new HColumnDescriptor("type:"));   
  18.         tableDesc.addFamily(new HColumnDescriptor("cookie:"));   
  19.         //注意這個(gè)C列,下面我會(huì )簡(jiǎn)單以此列來(lái)說(shuō)明列存儲   
  20.         tableDesc.addFamily(new HColumnDescriptor("c:"));   
  21.         admin.createTable(tableDesc);   
  22.         System.out.println("table create ok!!!");   
  23.     } else {   
  24.         System.out.println("table Already exists");   
  25.     }   
  26. }  

 將hadoop/hbase都啟動(dòng)再運行,在hql中使用"desc tablename"就可以看出這個(gè)表有5個(gè)字段,下面我們再來(lái)往這個(gè)表里錄入點(diǎn)數據,上面說(shuō)過(guò)值為空的字段是不占用空間的,這里還要注意點(diǎn),經(jīng)過(guò)我的測試,如果發(fā)現這個(gè)字段無(wú)值,就不要往hbase里面寫(xiě)null值,當然你要真往這個(gè)字段存null值是不會(huì )有任何問(wèn)題的,但你查詢(xún)這個(gè)有null值的字段時(shí),會(huì )有點(diǎn)毛病,當然這個(gè)我也不知道怎么描述,有興趣的可以試試看,所以我下面有判斷,再者,hbase table里面的每一行數據集都必須有一個(gè)唯一row關(guān)鍵字,這個(gè)row你可以隨便定義,方便準確找到你需要的數據

Java代碼
  1. /**  
  2.  * 錄入數據  
  3.  * @throws Exception  
  4.  */  
  5. public static void insertData() throws Exception{   
  6.     //讀取日志文件   
  7.     BufferedReader reader = new BufferedReader(new FileReader("log file name"));   
  8.     if(table==null)   
  9.         table = new HTable(conf, new Text(tablename));   
  10.     String line;   
  11.     while((line = reader.readLine()) != null){   
  12.         //這里我就不說(shuō)了,先前有說(shuō)明   
  13.         LogAccess log = new LogAccess(line);   
  14.         //這里我使用time+cookie為row關(guān)鍵字,確保不重復,如果cookie記錄有重復,將區別對待,這里暫不多做說(shuō)明   
  15.         String row = createRow(log.getTime(),log.getCookie());   
  16.            
  17.         long lockid = table.startUpdate(new Text(row));   
  18.         if(!log.getIp().equals("") && log.getIp()!=null)   
  19.             table.put(lockid, new Text("ip:"), log.getIp().getBytes());   
  20.         if(!log.getTime().equals("") && log.getTime()!=null)   
  21.             table.put(lockid, new Text("time:"), log.getTime().getBytes());   
  22.         if(!log.getType().equals("") && log.getType()!=null)   
  23.             table.put(lockid, new Text("type:"), log.getType().getBytes());   
  24.         if(!log.getCookie().equals("") && log.getCookie()!=null)   
  25.             table.put(lockid, new Text("cookie:"), log.getCookie().getBytes());   
  26.         //這里要注意,我是往c列中寫(xiě)入了5個(gè)字段,你可以想象,我在c列中存入了一個(gè)map   
  27.         if(!log.getRegmark().equals("") && log.getRegmark()!=null)   
  28.             table.put(lockid, new Text("c:_regmark"), log.getRegmark().getBytes());   
  29.         if(!log.getRegmark2().equals("") && log.getRegmark2()!=null)   
  30.             table.put(lockid, new Text("c:_regmark2"), log.getRegmark2().getBytes());   
  31.         if(!log.getSendshow().equals("") && log.getSendshow()!=null)   
  32.             table.put(lockid, new Text("c:_sendshow"), log.getSendshow().getBytes());   
  33.         if(!log.getCurrenturl().equals("") && log.getCurrenturl()!=null)   
  34.             table.put(lockid, new Text("c:_currenturl"), log.getCurrenturl().getBytes());   
  35.         if(!log.getAgent().equals("") && log.getAgent()!=null)   
  36.             table.put(lockid, new Text("c:_agent"), log.getAgent().getBytes());   
  37.         //存入數據   
  38.         table.commit(lockid);   
  39.     }   
  40. }  

 

O了,測試下吧

評論
blank 2008-10-16   回復
http://solomons.javaeye.com/blog/205736
上面這篇文章詳細講解了hadoop/hbase的安裝以及啟動(dòng)方式,有興趣看看吧
xianglei 2008-10-15   回復
hbase怎么啟動(dòng)?
本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
在HBase里使用MapReduce例子
Hbase--JavaApi實(shí)踐
flink學(xué)習筆記
HBase client API Guide
Java操作Hbase進(jìn)行建表、刪表以及對數據進(jìn)行增刪改查,條件查詢(xún)
Spark操作Hbase
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久