1. <ul id="0c1fb"></ul>

      <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
      <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区

      RELATEED CONSULTING
      相關(guān)咨詢
      選擇下列產(chǎn)品馬上在線溝通
      服務(wù)時(shí)間:8:30-17:00
      你可能遇到了下面的問(wèn)題
      關(guān)閉右側(cè)工具欄

      新聞中心

      這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
      java操作hbaseapi
      1. 需要引入的jar包(這里的jar包括hbase,hive的UDF,hive的jdbc連接)

        成都創(chuàng)新互聯(lián)公司一直秉承“誠(chéng)信做人,踏實(shí)做事”的原則,不欺瞞客戶,是我們最起碼的底線! 以服務(wù)為基礎(chǔ),以質(zhì)量求生存,以技術(shù)求發(fā)展,成交一個(gè)客戶多一個(gè)朋友!為您提供成都網(wǎng)站建設(shè)、成都做網(wǎng)站、成都網(wǎng)頁(yè)設(shè)計(jì)、小程序開(kāi)發(fā)、成都網(wǎng)站開(kāi)發(fā)、成都網(wǎng)站制作、成都軟件開(kāi)發(fā)、重慶APP開(kāi)發(fā)是成都本地專業(yè)的網(wǎng)站建設(shè)和網(wǎng)站設(shè)計(jì)公司,等你一起來(lái)見(jiàn)證!

        java操作hbase api

      2. java源碼

      package com.hbase.jdbc;
      
      import java.util.ArrayList;
      import java.util.List;
      
      import org.apache.hadoop.conf.Configuration;
      import org.apache.hadoop.hbase.Cell;
      import org.apache.hadoop.hbase.CellUtil;
      import org.apache.hadoop.hbase.HBaseConfiguration;
      import org.apache.hadoop.hbase.HColumnDescriptor;
      import org.apache.hadoop.hbase.HTableDescriptor;
      import org.apache.hadoop.hbase.TableName;
      import org.apache.hadoop.hbase.client.Delete;
      import org.apache.hadoop.hbase.client.Get;
      import org.apache.hadoop.hbase.client.HBaseAdmin;
      import org.apache.hadoop.hbase.client.HTable;
      import org.apache.hadoop.hbase.client.Put;
      import org.apache.hadoop.hbase.client.Result;
      import org.apache.hadoop.hbase.client.ResultScanner;
      import org.apache.hadoop.hbase.client.Scan;
      import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp;
      import org.apache.hadoop.hbase.filter.Filter;
      import org.apache.hadoop.hbase.filter.FilterList;
      import org.apache.hadoop.hbase.filter.SingleColumnValueFilter;
      import org.apache.hadoop.hbase.util.Bytes;
      
      public class HBaseOperate {
          public static Configuration conf;
      
          /*
           * hbase的基本設(shè)置 
           */
          static{
              conf = HBaseConfiguration.create();
              conf.set("hbase.master", "192.168.1.100:600000");  
              conf.set("hbase.zookeeper.quorum", "192.168.192.137"); 
          }
          
          public static void main(String args[]) throws Exception{
              String[] cols = {"age","sex","address"};
              String tableName = "userInfo3";
      //        new HBaseOperate().createTable(tableName, cols);
              String[] columnValue = {"北京","1","16",};
              String[] column = {"baseAddress","baseSex","baseAge"};
      //        new HBaseOperate().listTable();
      //        new HBaseOperate().insertData(tableName,"doubi", column, columnValue);
      //        new HBaseOperate().dropTable(tableName);
      //        new HBaseOperate().getRow(tableName, "wj");
      //        new HBaseOperate().deleteRow(tableName, "wj");
      //        new HBaseOperate().getAllRow(tableName);
      //        new HBaseOperate().getRowByCondition(tableName);
              new HBaseOperate().getRowByManyCondition(tableName);
          }
          
          /**
           * 創(chuàng)建表
           */
          public void createTable(String tableName,String cols[]) throws Exception{
              HBaseAdmin ha = new HBaseAdmin(conf);
              if(ha.tableExists(tableName)){
                  System.out.println("表已經(jīng)存在");
              }else{
                  HTableDescriptor table = new HTableDescriptor(TableName.valueOf(tableName));
                  for(String c: cols){
                      HColumnDescriptor col=new HColumnDescriptor(c);//列簇名
                      table.addFamily(col);
                  }
                  
                  ha.createTable(table);
                  ha.close();
                  System.out.println("創(chuàng)建表成功!");
              }
          }
          
          /**
           * 刪除表 
           */
          public void dropTable(String tableName) throws Exception{
              System.out.println("start drop table!");
              HBaseAdmin ha = new HBaseAdmin(conf);
              ha.disableTable(tableName);
              ha.deleteTable(tableName);
              System.out.println("drop table success!");
          }
          
          /**
           * 查看所有表 
           */
          public void listTable() throws Exception{
              HBaseAdmin ha = new HBaseAdmin(conf);
              TableName[] tableNames = ha.listTableNames();
              for(int i = 0; i < tableNames.length; i ++){
                  System.out.println(tableNames[i].getNameAsString());
              }
          }
          
          /**
           * 插入數(shù)據(jù)
           */
          public void insertData(String tableName, String rowKey, String[] column, 
                                  String[] columnValue) throws Exception{
              System.out.println("start insert table!");
              HTable table = new HTable(conf, tableName);
              HTableDescriptor hd = table.getTableDescriptor();
              HColumnDescriptor[] hcds = hd.getColumnFamilies();//最后一列開(kāi)始
              Put put = new Put(rowKey.getBytes());
              
              for(int i = 0; i < hcds.length; i ++){
                  HColumnDescriptor hcd = hcds[i];
                  put.add(hcd.getName(), column[i].getBytes(), columnValue[i].getBytes());
                  //family column value
              }
              
              table.put(put);
              System.out.println("end insert table!");
          }
          
          /**
           * 獲取一行數(shù)據(jù) 
           */
          public void getRow(String tableName, String key) throws Exception{
              System.out.println("start get row!");
              HTable table = new HTable(conf, tableName);
              Get get = new Get(key.getBytes());
              
              Result result = table.get(get);
              for(Cell cell : result.rawCells()){
                  System.out.println("row family++++++ " + 
                      new String(CellUtil.cloneFamily(cell)) + 
                      "  row column++++++ " + new String(CellUtil.cloneQualifier(cell)) + 
                      "   row value ++++++" + new String(CellUtil.cloneValue(cell)));
              }
              
              System.out.println("get row end!");
          }
          
          /**
           * 刪除一行數(shù)據(jù) 
           */
          public void deleteRow(String tableName, String key) throws Exception{
              System.out.println("delete row start!");
              HTable table =new HTable(conf, tableName);
              Delete d1 = new Delete(key.getBytes());
              table.delete(d1);
              System.out.println("delete row end!");
          }
          
          /**
           * 獲取表所有數(shù)據(jù)
           */
          public void getAllRow(String tableName) throws Exception{
              System.out.println("get all row start!");
              HTable table = new HTable(conf, tableName);
              Scan s = new Scan();
              ResultScanner rs = table.getScanner(s);
              for(Result result : rs){
                  for(Cell cell : result.rawCells()){
                      System.out.println("row key++++++" + new String(CellUtil.cloneRow(cell)) +
                       " row family++++++ " + new String(CellUtil.cloneFamily(cell)) + 
                       "   row column++++++ " + new String(CellUtil.cloneQualifier(cell)) + 
                       "   row value ++++++" + new String(CellUtil.cloneValue(cell)));
                  }
              }
              System.out.println("get all row end");
          }
          
          /**
           * 根據(jù)條件查詢記錄
           */
          public void getRowByCondition(String tableName) throws Exception{
              System.out.println("begin query!");
              HTable table = new HTable(conf, tableName);
              Filter filter = new SingleColumnValueFilter(Bytes.toBytes("sex"), Bytes.toBytes("baseAge"), CompareOp.EQUAL, Bytes.toBytes("100")); //family column 比較符號(hào) 比較值
              Scan s = new Scan();  
              s.setFilter(filter);  
              
              ResultScanner rs = table.getScanner(s);  
              
              for(Result result : rs){
                  for(Cell cell : result.rawCells()){
                      System.out.println("row key++++++" + new String(CellUtil.cloneRow(cell)) + 
                      " row family++++++ " + new String(CellUtil.cloneFamily(cell)) + 
                      "   row column++++++ " + new String(CellUtil.cloneQualifier(cell)) + 
                      "   row value ++++++" + new String(CellUtil.cloneValue(cell)));
                  }
              } 
      
              System.out.println("end query!");
          }
          
          /**
           * 多條件查詢
           */
          public void getRowByManyCondition(String tableName) throws Exception{
              System.out.println("begin query!");
              HTable table = new HTable(conf, tableName);
              Filter filterSex = new SingleColumnValueFilter(Bytes.toBytes("sex"), 
                  Bytes.toBytes("baseAge"), CompareOp.EQUAL, Bytes.toBytes("16")); 
                  //family column 比較符號(hào) 比較值
              Filter filterAge = new SingleColumnValueFilter(Bytes.toBytes("age"), 
                  Bytes.toBytes("baseSex"), CompareOp.EQUAL, Bytes.toBytes("1")); 
                  //family column 比較符號(hào) 比較值
              
              List filterList = new ArrayList();
              filterList.add(filterAge);
              filterList.add(filterSex);
              
              Scan s = new Scan();  
              FilterList filterListS = new FilterList(filterList);  
              s.setFilter(filterListS);
              
              //可以設(shè)置查詢結(jié)果的開(kāi)始 和 結(jié)束位置(針對(duì)的是key值)
              s.setStartRow("wj".getBytes());
              s.setStopRow("wj".getBytes());
              
              ResultScanner rs = table.getScanner(s);  
              for(Result result : rs){
                  for(Cell cell : result.rawCells()){
                      System.out.println("row key++++++" + new String(CellUtil.cloneRow(cell)) +
                       " row family++++++ " + new String(CellUtil.cloneFamily(cell)) + 
                       "   row column++++++ " + new String(CellUtil.cloneQualifier(cell)) + 
                       "   row value ++++++" + new String(CellUtil.cloneValue(cell)));
                  }
              } 
              
              System.out.println("end query!");
          }
      }

       

       

       

       

       

       

       

       

       

       

       


      網(wǎng)頁(yè)標(biāo)題:java操作hbaseapi
      URL標(biāo)題:http://ef60e0e.cn/article/jjpdjh.html
      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区
      1. <ul id="0c1fb"></ul>

        <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
        <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

        昌乐县| 盘锦市| 丰都县| 海城市| 五寨县| 西畴县| 和政县| 乌鲁木齐县| 东乡| 古丈县| 石楼县| 吐鲁番市| 临桂县| 贵南县| 尉犁县| 大石桥市| 广安市| 色达县| 龙泉市| 寻甸| 泸西县| 长武县| 温州市| 巩义市| 清镇市| 银川市| 延安市| 师宗县| 灵山县| 长寿区| 大新县| 蚌埠市| 宿迁市| 岳普湖县| 永仁县| 旬阳县| 西乌珠穆沁旗| 济南市| 旌德县| 凉城县| 禄丰县|