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
      相關咨詢
      選擇下列產品馬上在線溝通
      服務時間:8:30-17:00
      你可能遇到了下面的問題
      關閉右側工具欄

      新聞中心

      這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
      hbase2.0.2javaapi怎么用

      這篇文章將為大家詳細講解有關hbase 2.0.2 java api怎么用,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。

      創(chuàng)新互聯(lián)建站-成都網(wǎng)站建設公司,專注成都網(wǎng)站建設、成都網(wǎng)站制作、網(wǎng)站營銷推廣,域名注冊,網(wǎng)頁空間,網(wǎng)站托管運營有關企業(yè)網(wǎng)站制作方案、改版、費用等問題,請聯(lián)系創(chuàng)新互聯(lián)建站

      package com.hbase.test;
      import java.io.IOException;
      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.CompareOperator;
      import org.apache.hadoop.hbase.HBaseConfiguration;
      import org.apache.hadoop.hbase.TableName;
      import org.apache.hadoop.hbase.client.Admin;
      import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor;
      import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;
      import org.apache.hadoop.hbase.client.Connection;
      import org.apache.hadoop.hbase.client.ConnectionFactory;
      import org.apache.hadoop.hbase.client.Delete;
      import org.apache.hadoop.hbase.client.Get;
      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.client.Table;
      import org.apache.hadoop.hbase.client.TableDescriptor;
      import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
      import org.apache.hadoop.hbase.filter.ColumnPrefixFilter;
      import org.apache.hadoop.hbase.filter.FilterList;
      import org.apache.hadoop.hbase.filter.FilterList.Operator;
      import org.apache.hadoop.hbase.filter.RegexStringComparator;
      import org.apache.hadoop.hbase.filter.RowFilter;
      import org.apache.hadoop.hbase.filter.SingleColumnValueFilter;
      import org.apache.hadoop.hbase.util.Bytes;
      import org.junit.After;
      import org.junit.Before;
      import org.junit.Test;
      public class HbaseTest {
      	
      	Configuration conf = null;
      	Connection conn = null;
      	@Before
      	public void getConfigAndConnection() {
      		conf = HBaseConfiguration.create();
      		conf.set("hbase.zookeeper.quorum", "bigdata01,bigdata02,bigdata03");
      		conf.set("hbase.zookeeper.property.clientPort", "2181");
      		try {
      			conn = ConnectionFactory.createConnection(conf);
      		} catch (IOException e) {
      			e.printStackTrace();
      		}		
      	}
      	@Test
      	public void createTable() throws IOException {
      			Admin admin = conn.getAdmin();
      			if(!admin.isTableAvailable(TableName.valueOf("test"))) {
      				TableName tableName = TableName.valueOf("test");
      				//表描述器構造器
      				TableDescriptorBuilder  tdb  =TableDescriptorBuilder.newBuilder(tableName)  ;
      				//列族描述起構造器
      				ColumnFamilyDescriptorBuilder cdb =  ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("user"));
      				//獲得列描述起
      				ColumnFamilyDescriptor  cfd = cdb.build();
      				//添加列族
      				tdb.setColumnFamily(cfd);
      				//獲得表描述器
      				TableDescriptor td = tdb.build();
      				//創(chuàng)建表
      				//admin.addColumnFamily(tableName, cfd); //給標添加列族
      				admin.createTable(td);
      			}
      			//關閉鏈接
      	}
      	//單條插入
      	@Test
      	public void insertOneData() throws IOException {
      		//new 一個列  ,hgs_000為row key
      		Put put = new Put(Bytes.toBytes("hgs_000"));
      		//下面三個分別為,列族,列名,列值
      		put.addColumn(Bytes.toBytes("testfm"),Bytes.toBytes("name") , Bytes.toBytes("hgs"));
      		TableName tableName = TableName.valueOf("test");
      		//得到 table
      		Table table = conn.getTable(tableName);
      		//執(zhí)行插入
      		table.put(put);				
      	}
      	//插入多個列
      	@Test
      	public void insertManyData() throws IOException {
      		Table table = conn.getTable(TableName.valueOf("test"));
      		List puts = new ArrayList();
      		Put put1 = new Put(Bytes.toBytes("hgs_001"));
      		put1.addColumn(Bytes.toBytes("testfm"),Bytes.toBytes("name") , Bytes.toBytes("wd"));
      		
      		Put put2 = new Put(Bytes.toBytes("hgs_001"));
      		put2.addColumn(Bytes.toBytes("testfm"),Bytes.toBytes("age") , Bytes.toBytes("25"));
      		
      		Put put3 = new Put(Bytes.toBytes("hgs_001"));
      		put3.addColumn(Bytes.toBytes("testfm"),Bytes.toBytes("weight") , Bytes.toBytes("60kg"));
      		
      		Put put4 = new Put(Bytes.toBytes("hgs_001"));
      		put4.addColumn(Bytes.toBytes("testfm"),Bytes.toBytes("sex") , Bytes.toBytes("男"));
      		puts.add(put1);
      		puts.add(put2);
      		puts.add(put3);
      		puts.add(put4);		
      		table.put(puts);
      		table.close();
      }
      	//同一條數(shù)據(jù)的插入
      	@Test
      	public void singleRowInsert() throws IOException {
      		Table table = conn.getTable(TableName.valueOf("test"));
      		
      		Put put1 = new Put(Bytes.toBytes("hgs_005"));
      		
      		put1.addColumn(Bytes.toBytes("testfm"),Bytes.toBytes("name") , Bytes.toBytes("cm"));		
      		put1.addColumn(Bytes.toBytes("testfm"),Bytes.toBytes("age") , Bytes.toBytes("22"));		
      		put1.addColumn(Bytes.toBytes("testfm"),Bytes.toBytes("weight") , Bytes.toBytes("88kg"));
      		put1.addColumn(Bytes.toBytes("testfm"),Bytes.toBytes("sex") , Bytes.toBytes("男"));	
      		
      		table.put(put1);
      		table.close();
      	}
      	//數(shù)據(jù)的更新,hbase對數(shù)據(jù)只有追加,沒有更新,但是查詢的時候會把最新的數(shù)據(jù)返回給哦我們
      	@Test
      	public void updateData() throws IOException {
      		Table table = conn.getTable(TableName.valueOf("test"));
      		Put put1 = new Put(Bytes.toBytes("hgs_002"));
      		put1.addColumn(Bytes.toBytes("testfm"),Bytes.toBytes("weight") , Bytes.toBytes("63kg"));
      		table.put(put1);
      		table.close();
      	}
      	
      	//刪除數(shù)據(jù)
      	@Test
      	public void deleteData() throws IOException {
      		Table table = conn.getTable(TableName.valueOf("test"));
      		//參數(shù)為 row key
      		//刪除一列
      		Delete delete1 = new Delete(Bytes.toBytes("hgs_000"));
      		delete1.addColumn(Bytes.toBytes("testfm"), Bytes.toBytes("weight"));
      		//刪除多列
      		Delete delete2 = new Delete(Bytes.toBytes("hgs_001"));
      		delete2.addColumns(Bytes.toBytes("testfm"), Bytes.toBytes("age"));
      		delete2.addColumns(Bytes.toBytes("testfm"), Bytes.toBytes("sex"));
      		//刪除某一行的列族內容
      		Delete delete3 = new Delete(Bytes.toBytes("hgs_002"));
      		delete3.addFamily(Bytes.toBytes("testfm"));
      		
      		//刪除一整行
      		Delete delete4 = new Delete(Bytes.toBytes("hgs_003"));
      		table.delete(delete1);
      		table.delete(delete2);
      		table.delete(delete3);
      		table.delete(delete4);
      		table.close();
      	}
      	
      	//查詢
      	//
      	@Test
      	public void querySingleRow() throws IOException {
      		Table table = conn.getTable(TableName.valueOf("test"));
      		//獲得一行
      		Get get = new Get(Bytes.toBytes("hgs_000"));
      		Result set = table.get(get);
      		Cell[] cells  = set.rawCells();
      		for(Cell cell : cells) {
      			System.out.println(Bytes.toString(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength())+"::"+
      		                    Bytes.toString(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()));
      		}
      		table.close();
      		//Bytes.toInt(result.getValue(Bytes.toBytes("info"), Bytes.toBytes("password")))
      		
      	}
      	//全表掃描
      	@Test
      	public void scanTable() throws IOException {
      		Table table = conn.getTable(TableName.valueOf("test"));
      		Scan scan = new Scan();
      		//scan.addFamily(Bytes.toBytes("info"));
      		//scan.addColumn(Bytes.toBytes("info"), Bytes.toBytes("password"));
      		//scan.setStartRow(Bytes.toBytes("wangsf_0"));
      		//scan.setStopRow(Bytes.toBytes("wangwu"));
      		ResultScanner rsacn = table.getScanner(scan);
      		for(Result rs:rsacn) {
      			String rowkey = Bytes.toString(rs.getRow());
      			System.out.println("row key :"+rowkey);
      			Cell[] cells  = rs.rawCells();
      			for(Cell cell : cells) {
      				System.out.println(Bytes.toString(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength())+"::"+
      			                    Bytes.toString(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()));
      			}
      			System.out.println("-----------------------------------------");
      		}
      	}
      	//過濾器
      	
      	@Test
      	//列值過濾器
      	public void singColumnFilter() throws IOException {
      		Table table = conn.getTable(TableName.valueOf("test"));
      		Scan scan = new Scan();
      		//下列參數(shù)分別為,列族,列名,比較符號,值
      		SingleColumnValueFilter filter =  new SingleColumnValueFilter( Bytes.toBytes("testfm"),  Bytes.toBytes("name"),
                       CompareOperator.EQUAL,  Bytes.toBytes("wd")) ;
      		scan.setFilter(filter);
      		ResultScanner scanner = table.getScanner(scan);
      		for(Result rs:scanner) {
      			String rowkey = Bytes.toString(rs.getRow());
      			System.out.println("row key :"+rowkey);
      			Cell[] cells  = rs.rawCells();
      			for(Cell cell : cells) {
      				System.out.println(Bytes.toString(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength())+"::"+
      			                    Bytes.toString(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()));
      			}
      			System.out.println("-----------------------------------------");
      		}
      	}
      	//row key過濾器
      	@Test
      	public void rowkeyFilter() throws IOException {
      		Table table = conn.getTable(TableName.valueOf("test"));
      		Scan scan = new Scan();
      		RowFilter filter = new RowFilter(CompareOperator.EQUAL,new RegexStringComparator("^hgs_00*"));
      		scan.setFilter(filter);
      		ResultScanner scanner  = table.getScanner(scan);
      		for(Result rs:scanner) {
      			String rowkey = Bytes.toString(rs.getRow());
      			System.out.println("row key :"+rowkey);
      			Cell[] cells  = rs.rawCells();
      			for(Cell cell : cells) {
      				System.out.println(Bytes.toString(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength())+"::"+
      			                    Bytes.toString(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()));
      			}
      			System.out.println("-----------------------------------------");
      		}
      	}
      	//列名前綴過濾器
      	@Test
      	public void columnPrefixFilter() throws IOException {
      		Table table = conn.getTable(TableName.valueOf("test"));
      		Scan scan = new Scan();
      		ColumnPrefixFilter filter = new ColumnPrefixFilter(Bytes.toBytes("name"));
      		scan.setFilter(filter);
      		ResultScanner scanner  = table.getScanner(scan);
      		for(Result rs:scanner) {
      			String rowkey = Bytes.toString(rs.getRow());
      			System.out.println("row key :"+rowkey);
      			Cell[] cells  = rs.rawCells();
      			for(Cell cell : cells) {
      				System.out.println(Bytes.toString(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength())+"::"+
      			                    Bytes.toString(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()));
      			}
      			System.out.println("-----------------------------------------");
      		}
      	}
      	
      	//過濾器集合
      	@Test
      	public void FilterSet() throws IOException {
      		Table table = conn.getTable(TableName.valueOf("test"));
      		Scan scan = new Scan();
      		FilterList list = new FilterList(Operator.MUST_PASS_ALL);
      		SingleColumnValueFilter filter1 =  new SingleColumnValueFilter( Bytes.toBytes("testfm"),  Bytes.toBytes("age"),
                      CompareOperator.GREATER,  Bytes.toBytes("23")) ;
      		ColumnPrefixFilter filter2 = new ColumnPrefixFilter(Bytes.toBytes("weig"));
      		list.addFilter(filter1);
      		list.addFilter(filter2);
      		
      		scan.setFilter(list);
      		ResultScanner scanner  = table.getScanner(scan);
      		for(Result rs:scanner) {
      			String rowkey = Bytes.toString(rs.getRow());
      			System.out.println("row key :"+rowkey);
      			Cell[] cells  = rs.rawCells();
      			for(Cell cell : cells) {
      				System.out.println(Bytes.toString(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength())+"::"+
      			                    Bytes.toString(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()));
      			}
      			System.out.println("-----------------------------------------");
      		}
      		
      	}
      	@After
      	public void closeConn() throws IOException {
      		conn.close();
      	}
      }	
      	

      關于“hbase 2.0.2 java api怎么用”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。


      分享標題:hbase2.0.2javaapi怎么用
      分享網(wǎng)址:http://www.ef60e0e.cn/article/jhiecd.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>

        宿迁市| 湖州市| 华宁县| 剑河县| 诸城市| 柳河县| 富源县| 惠州市| 明星| 黔西县| 昭通市| 江油市| 新兴县| 商南县| 灵武市| 利辛县| 白沙| 丁青县| 泽普县| 仙游县| 龙陵县| 江川县| 锦屏县| 浏阳市| 三原县| 高陵县| 宕昌县| 天台县| 黔西县| 古田县| 苏尼特右旗| 隆化县| 滨海县| 综艺| 聂拉木县| 阜南县| 新昌县| 焉耆| 宁武县| 洛扎县| 宕昌县|