日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

HBase Filter及对应Shell--转

發布時間:2025/4/5 编程问答 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 HBase Filter及对应Shell--转 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

http://www.cnblogs.com/skyl/p/4807793.html

比較運算符 CompareFilter.CompareOp
比較運算符用于定義比較關系,可以有以下幾類值供選擇:

  • EQUAL 相等
  • GREATER 大于
  • GREATER_OR_EQUAL 大于等于
  • LESS 小于
  • LESS_OR_EQUAL 小于等于
  • NOT_EQUAL 不等于

比較器 ByteArrayComparable
通過比較器可以實現多樣化目標匹配效果,比較器有以下子類可以使用:

  • BinaryComparator 匹配完整字節數組
  • BinaryPrefixComparator 匹配字節數組前綴
  • BitComparator  不常用
  • NullComparator  不常用
  • RegexStringComparator?匹配正則表達式
  • SubstringComparator?匹配子字符串

1.多重過濾器--FilterList(Shell不支持)
FilterList代表一個過濾器鏈,它可以包含一組即將應用于目標數據集的過濾器,過濾器間具有“與”FilterList.Operator.MUST_PASS_ALL?和“或”?FilterList.Operator.MUST_PASS_ONE?關系。

//結合過濾器,獲取所有age在15到30之間的行 private static void scanFilter() throws IOException,UnsupportedEncodingException {Configuration conf = HBaseConfiguration.create();conf.set("hbase.rootdir", "hdfs://ncst:9000/hbase");conf.set("hbase.zookeeper.quorum", "ncst");HTable ht = new HTable(conf, "users");// AndFilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ALL);// >=15SingleColumnValueFilter filter1 = new SingleColumnValueFilter("info".getBytes(), "age".getBytes(), CompareOp.GREATER_OR_EQUAL, "15".getBytes());// =<30SingleColumnValueFilter filter2 = new SingleColumnValueFilter("info".getBytes(), "age".getBytes(), CompareOp.LESS_OR_EQUAL, "30".getBytes());filterList.addFilter(filter1);filterList.addFilter(filter2); Scan scan = new Scan();// set Filterscan.setFilter(filterList);ResultScanner rs = ht.getScanner(scan);for(Result result : rs){for(Cell cell : result.rawCells()){System.out.println(new String(CellUtil.cloneRow(cell))+"\t"+new String(CellUtil.cloneFamily(cell))+"\t"+new String(CellUtil.cloneQualifier(cell))+"\t"+new String(CellUtil.cloneValue(cell),"UTF-8")+"\t"+cell.getTimestamp());}}ht.close(); }

2. 列值過濾器--SingleColumnValueFilter
用于測試列值相等(CompareOp.EQUAL ),不等(CompareOp.NOT_EQUAL),或單側范圍 (如CompareOp.GREATER)。構造函數:
2.1.比較的關鍵字是一個字符數組(Shell不支持?)
SingleColumnValueFilter(byte[] family, byte[] qualifier, CompareFilter.CompareOp compareOp, byte[] value)

//SingleColumnValueFilter例子 private static void scanFilter01() throws IOException,UnsupportedEncodingException {Configuration conf = HBaseConfiguration.create();conf.set("hbase.rootdir", "hdfs://ncst:9000/hbase");conf.set("hbase.zookeeper.quorum", "ncst");HTable ht = new HTable(conf, "users");SingleColumnValueFilter scvf = new SingleColumnValueFilter("info".getBytes(), "age".getBytes(), CompareOp.EQUAL, "18".getBytes());Scan scan = new Scan();scan.setFilter(scvf);ResultScanner rs = ht.getScanner(scan);for(Result result : rs){for(Cell cell : result.rawCells()){System.out.println(new String(CellUtil.cloneRow(cell))+"\t"+new String(CellUtil.cloneFamily(cell))+"\t"+new String(CellUtil.cloneQualifier(cell))+"\t"+new String(CellUtil.cloneValue(cell),"UTF-8")+"\t"+cell.getTimestamp());}}ht.close(); }

2.2.比較的關鍵字是一個比較器ByteArrayComparable
SingleColumnValueFilter(byte[] family, byte[] qualifier, CompareFilter.CompareOp compareOp, ByteArrayComparable comparator)

//SingleColumnValueFilter例子2 -- RegexStringComparator private static void scanFilter02() throws IOException,UnsupportedEncodingException {Configuration conf = HBaseConfiguration.create();conf.set("hbase.rootdir", "hdfs://ncst:9000/hbase");conf.set("hbase.zookeeper.quorum", "ncst");HTable ht = new HTable(conf, "users");
   //值比較的正則表達式 -- RegexStringComparator//匹配info:age值以"4"結尾RegexStringComparator comparator = new RegexStringComparator(".4");//第四個參數不一樣SingleColumnValueFilter scvf = new SingleColumnValueFilter("info".getBytes(), "age".getBytes(), CompareOp.EQUAL, comparator);Scan scan = new Scan();scan.setFilter(scvf);ResultScanner rs = ht.getScanner(scan);for(Result result : rs){for(Cell cell : result.rawCells()){System.out.println(new String(CellUtil.cloneRow(cell))+"\t"+new String(CellUtil.cloneFamily(cell))+"\t"+new String(CellUtil.cloneQualifier(cell))+"\t"+new String(CellUtil.cloneValue(cell),"UTF-8")+"\t"+cell.getTimestamp());}}ht.close(); } hbase(main):032:0> scan 'users',{FILTER=>"SingleColumnValueFilter('info','age',=,'regexstring:.4')"} ROW COLUMN+CELL xiaoming01 column=address:contry, timestamp=1442000277200, value=\xE4\xB8\xAD\xE5\x9B\xBD xiaoming01 column=address:country, timestamp=1442000228945, value=\xE4\xB8\xAD\xE5\x9B\xBD xiaoming01 column=info:age, timestamp=1441998917568, value=24 xiaoming02 column=info:age, timestamp=1441998917594, value=24 xiaoming03 column=info:age, timestamp=1441998919607, value=24 3 row(s) in 0.0130 seconds //SingleColumnValueFilter例子2 -- SubstringComparator private static void scanFilter03() throws IOException,UnsupportedEncodingException {Configuration conf = HBaseConfiguration.create();conf.set("hbase.rootdir", "hdfs://ncst:9000/hbase");conf.set("hbase.zookeeper.quorum", "ncst");HTable ht = new HTable(conf, "users");//檢測一個子串是否存在于值中(大小寫不敏感) -- SubstringComparator//過濾age值中包含'4'的RowKeySubstringComparator comparator = new SubstringComparator("4");//第四個參數不一樣SingleColumnValueFilter scvf = new SingleColumnValueFilter("info".getBytes(), "age".getBytes(), CompareOp.EQUAL, comparator);Scan scan = new Scan();scan.setFilter(scvf);ResultScanner rs = ht.getScanner(scan);for(Result result : rs){for(Cell cell : result.rawCells()){System.out.println(new String(CellUtil.cloneRow(cell))+"\t"+new String(CellUtil.cloneFamily(cell))+"\t"+new String(CellUtil.cloneQualifier(cell))+"\t"+new String(CellUtil.cloneValue(cell),"UTF-8")+"\t"+cell.getTimestamp());}}ht.close(); } hbase(main):033:0> scan 'users',{FILTER=>"SingleColumnValueFilter('info','age',=,'substring:4')"} ROW COLUMN+CELL xiaoming01 column=address:contry, timestamp=1442000277200, value=\xE4\xB8\xAD\xE5\x9B\xBD xiaoming01 column=address:country, timestamp=1442000228945, value=\xE4\xB8\xAD\xE5\x9B\xBD xiaoming01 column=info:age, timestamp=1441998917568, value=24 xiaoming02 column=info:age, timestamp=1441998917594, value=24 xiaoming03 column=info:age, timestamp=1441998919607, value=24 3 row(s) in 0.0180 seconds

3.列名過濾器
由于HBase采用鍵值對保存內部數據,列名過濾器過濾一行的列名(ColumnFamily:Qualifiers)是否存在 , 對應前節所述列值的情況。

3.1.基于Columun Family列族過濾數據的FamilyFilter
FamilyFilter(CompareFilter.CompareOp familyCompareOp, ByteArrayComparable familyComparator)

注意:
1.如果希望查找的是一個已知的列族,則使用?scan.addFamily(family);?比使用過濾器效率更高.
2.由于目前HBase對多列族支持不完善,所以該過濾器目前用途不大.

//基于列族過濾數據的FamilyFilter private static void scanFilter04() throws IOException,UnsupportedEncodingException {Configuration conf = HBaseConfiguration.create();conf.set("hbase.rootdir", "hdfs://ncst:9000/hbase");conf.set("hbase.zookeeper.quorum", "ncst");HTable ht = new HTable(conf, "users");//過濾 = 'address'的列族//FamilyFilter familyFilter = new FamilyFilter(CompareOp.EQUAL, new BinaryComparator("address".getBytes()));//過濾以'add'開頭的列族FamilyFilter familyFilter = new FamilyFilter(CompareOp.EQUAL, new BinaryPrefixComparator("add".getBytes()));Scan scan = new Scan();scan.setFilter(familyFilter);ResultScanner rs = ht.getScanner(scan);for(Result result : rs){for(Cell cell : result.rawCells()){System.out.println(new String(CellUtil.cloneRow(cell))+"\t"+new String(CellUtil.cloneFamily(cell))+"\t"+new String(CellUtil.cloneQualifier(cell))+"\t"+new String(CellUtil.cloneValue(cell),"UTF-8")+"\t"+cell.getTimestamp());}}ht.close(); } hbase(main):021:0> scan 'users',{FILTER=>"FamilyFilter(=,'binaryprefix:add')"} ROW COLUMN+CELL xiaoming column=address:city, timestamp=1441997498965, value=hangzhou xiaoming column=address:contry, timestamp=1441997498911, value=china xiaoming column=address:province, timestamp=1441997498939, value=zhejiang xiaoming01 column=address:contry, timestamp=1442000277200, value=\xE4\xB8\xAD\xE5\x9B\xBD xiaoming01 column=address:country, timestamp=1442000228945, value=\xE4\xB8\xAD\xE5\x9B\xBD zhangyifei column=address:city, timestamp=1441997499108, value=jieyang zhangyifei column=address:contry, timestamp=1441997499077, value=china zhangyifei column=address:province, timestamp=1441997499093, value=guangdong zhangyifei column=address:town, timestamp=1441997500711, value=xianqiao 3 row(s) in 0.0400 seconds

3.2.基于Qualifier列名過濾數據的QualifierFilter
QualifierFilter(CompareFilter.CompareOp op, ByteArrayComparable qualifierComparator)

說明:該過濾器應該比FamilyFilter更常用!

//基于Qualifier(列名)過濾數據的QualifierFilter private static void scanFilter05() throws IOException,UnsupportedEncodingException {Configuration conf = HBaseConfiguration.create();conf.set("hbase.rootdir", "hdfs://ncst:9000/hbase");conf.set("hbase.zookeeper.quorum", "ncst");HTable ht = new HTable(conf, "users");//過濾列名 = 'age'所有RowKey//QualifierFilter qualifierFilter = new QualifierFilter(CompareOp.EQUAL, new BinaryComparator("age".getBytes()));//過濾列名 以'age'開頭 所有RowKey(包含age)//QualifierFilter qualifierFilter = new QualifierFilter(CompareOp.EQUAL, new BinaryPrefixComparator("age".getBytes()));//過濾列名 包含'age' 所有RowKey(包含age)//QualifierFilter qualifierFilter = new QualifierFilter(CompareOp.EQUAL, new SubstringComparator("age"));//過濾列名 符合'.ge'正則表達式 所有RowKeyQualifierFilter qualifierFilter = new QualifierFilter(CompareOp.EQUAL, new RegexStringComparator(".ge"));Scan scan = new Scan();scan.setFilter(qualifierFilter);ResultScanner rs = ht.getScanner(scan);for(Result result : rs){for(Cell cell : result.rawCells()){System.out.println(new String(CellUtil.cloneRow(cell))+"\t"+new String(CellUtil.cloneFamily(cell))+"\t"+new String(CellUtil.cloneQualifier(cell))+"\t"+new String(CellUtil.cloneValue(cell),"UTF-8")+"\t"+cell.getTimestamp());}}ht.close(); } hbase(main):020:0> scan 'users',{FILTER=>"QualifierFilter(=,'regexstring:.ge')"} ROW COLUMN+CELL xiaoming column=info:age, timestamp=1441997971945, value=38 xiaoming01 column=info:age, timestamp=1441998917568, value=24 xiaoming02 column=info:age, timestamp=1441998917594, value=24 xiaoming03 column=info:age, timestamp=1441998919607, value=24 zhangyifei column=info:age, timestamp=1442247255446, value=18 5 row(s) in 0.0460 seconds

3.3.基于列名前綴過濾數據的ColumnPrefixFilter(該功能用QualifierFilter也能實現)
ColumnPrefixFilter(byte[] prefix)?
注意:一個列名是可以出現在多個列族中的,該過濾器將返回所有列族中匹配的列。

//ColumnPrefixFilter例子 private static void scanFilter06() throws IOException,UnsupportedEncodingException {Configuration conf = HBaseConfiguration.create();conf.set("hbase.rootdir", "hdfs://ncst:9000/hbase");conf.set("hbase.zookeeper.quorum", "ncst");HTable ht = new HTable(conf, "users");//匹配 以'ag'開頭的所有的列ColumnPrefixFilter columnPrefixFilter = new ColumnPrefixFilter("ag".getBytes());Scan scan = new Scan();scan.setFilter(columnPrefixFilter);ResultScanner rs = ht.getScanner(scan);for(Result result : rs){for(Cell cell : result.rawCells()){System.out.println(new String(CellUtil.cloneRow(cell))+"\t"+new String(CellUtil.cloneFamily(cell))+"\t"+new String(CellUtil.cloneQualifier(cell))+"\t"+new String(CellUtil.cloneValue(cell),"UTF-8")+"\t"+cell.getTimestamp());}}ht.close(); } hbase(main):018:0> scan 'users',{FILTER=>"ColumnPrefixFilter('ag')"} ROW COLUMN+CELL xiaoming column=info:age, timestamp=1441997971945, value=38 xiaoming01 column=info:age, timestamp=1441998917568, value=24 xiaoming02 column=info:age, timestamp=1441998917594, value=24 xiaoming03 column=info:age, timestamp=1441998919607, value=24 zhangyifei column=info:age, timestamp=1442247255446, value=18 5 row(s) in 0.0280 seconds

3.4.基于多個列名前綴過濾數據的MultipleColumnPrefixFilter
MultipleColumnPrefixFilter 和 ColumnPrefixFilter 行為差不多,但可以指定多個前綴。

//MultipleColumnPrefixFilter例子 private static void scanFilter07() throws IOException,UnsupportedEncodingException {Configuration conf = HBaseConfiguration.create();conf.set("hbase.rootdir", "hdfs://ncst:9000/hbase");conf.set("hbase.zookeeper.quorum", "ncst");HTable ht = new HTable(conf, "users");//匹配 以'a'或者'c'開頭 所有的列{二維數組}byte[][] prefixes =new byte[][]{"a".getBytes(), "c".getBytes()}; MultipleColumnPrefixFilter multipleColumnPrefixFilter = new MultipleColumnPrefixFilter(prefixes );Scan scan = new Scan();scan.setFilter(multipleColumnPrefixFilter);ResultScanner rs = ht.getScanner(scan);for(Result result : rs){for(Cell cell : result.rawCells()){System.out.println(new String(CellUtil.cloneRow(cell))+"\t"+new String(CellUtil.cloneFamily(cell))+"\t"+new String(CellUtil.cloneQualifier(cell))+"\t"+new String(CellUtil.cloneValue(cell),"UTF-8")+"\t"+cell.getTimestamp());}}ht.close(); } hbase(main):017:0> scan 'users',{FILTER=>"MultipleColumnPrefixFilter('a','c')"} ROW COLUMN+CELL xiaoming column=address:city, timestamp=1441997498965, value=hangzhou xiaoming column=address:contry, timestamp=1441997498911, value=china xiaoming column=info:age, timestamp=1441997971945, value=38 xiaoming column=info:company, timestamp=1441997498889, value=alibaba xiaoming01 column=address:contry, timestamp=1442000277200, value=\xE4\xB8\xAD\xE5\x9B\xBD xiaoming01 column=address:country, timestamp=1442000228945, value=\xE4\xB8\xAD\xE5\x9B\xBD xiaoming01 column=info:age, timestamp=1441998917568, value=24 xiaoming02 column=info:age, timestamp=1441998917594, value=24 xiaoming03 column=info:age, timestamp=1441998919607, value=24 zhangyifei column=address:city, timestamp=1441997499108, value=jieyang zhangyifei column=address:contry, timestamp=1441997499077, value=china zhangyifei column=info:age, timestamp=1442247255446, value=18 zhangyifei column=info:company, timestamp=1441997499039, value=alibaba 5 row(s) in 0.0430 seconds

3.5.基于列范圍(不是行范圍)過濾數據ColumnRangeFilter

  • 可用于獲得一個范圍的列,例如,如果你的一行中有百萬個列,但是你只希望查看列名從bbbb到dddd的范圍
  • 該方法從 HBase 0.92 版本開始引入
  • 一個列名是可以出現在多個列族中的,該過濾器將返回所有列族中匹配的列
  • 構造函數:
    ColumnRangeFilter(byte[] minColumn, boolean minColumnInclusive, byte[] maxColumn, boolean maxColumnInclusive)
    參數解釋:

    • minColumn?- 列范圍的最小值,如果為空,則沒有下限
    • minColumnInclusive?- 列范圍是否包含minColumn
    • maxColumn?- 列范圍最大值,如果為空,則沒有上限
    • maxColumnInclusive?- 列范圍是否包含maxColumn
    //ColumnRangeFilter例子 private static void scanFilter08() throws IOException, UnsupportedEncodingException {Configuration conf = HBaseConfiguration.create();conf.set("hbase.rootdir", "hdfs://ncst:9000/hbase");conf.set("hbase.zookeeper.quorum", "ncst");HTable ht = new HTable(conf, "users");//匹配 以'a'開頭到以'c'開頭(不包含c) 所有的列 ColumnRangeFilter columnRangeFilter = new ColumnRangeFilter("a".getBytes(), true, "c".getBytes(), false);Scan scan = new Scan();scan.setFilter(columnRangeFilter);ResultScanner rs = ht.getScanner(scan);for(Result result : rs){for(Cell cell : result.rawCells()){System.out.println(new String(CellUtil.cloneRow(cell))+"\t"+new String(CellUtil.cloneFamily(cell))+"\t"+new String(CellUtil.cloneQualifier(cell))+"\t"+new String(CellUtil.cloneValue(cell),"UTF-8")+"\t"+cell.getTimestamp());}}ht.close(); } hbase(main):016:0> scan 'users',{FILTER=>"ColumnRangeFilter('a',true,'c',false)"} ROW COLUMN+CELL xiaoming column=info:age, timestamp=1441997971945, value=38 xiaoming column=info:birthday, timestamp=1441997498851, value=1987-06-17 xiaoming01 column=info:age, timestamp=1441998917568, value=24 xiaoming02 column=info:age, timestamp=1441998917594, value=24 xiaoming03 column=info:age, timestamp=1441998919607, value=24 zhangyifei column=info:age, timestamp=1442247255446, value=18 zhangyifei column=info:birthday, timestamp=1441997498990, value=1987-4-17 5 row(s) in 0.0340 seconds

    4.RowKey
    當需要根據行鍵特征查找一個范圍的行數據時,使用Scan的startRow和stopRow會更高效,但是,startRow和stopRow只能匹配行鍵的開始字符,而不能匹配中間包含的字符。當需要針對行鍵進行更復雜的過濾時,可以使用RowFilter。
    構造函數:RowFilter(CompareFilter.CompareOp rowCompareOp, ByteArrayComparable rowComparator)

    //RowFilter例子 private static void scanFilter09() throws IOException,UnsupportedEncodingException {Configuration conf = HBaseConfiguration.create();conf.set("hbase.rootdir", "hdfs://ncst:9000/hbase");conf.set("hbase.zookeeper.quorum", "ncst");HTable ht = new HTable(conf, "users");//匹配 行鍵包含'01' 所有的行 RowFilter rowFilter = new RowFilter(CompareOp.EQUAL, new SubstringComparator("01"));Scan scan = new Scan();scan.setFilter(rowFilter);ResultScanner rs = ht.getScanner(scan);for(Result result : rs){for(Cell cell : result.rawCells()){System.out.println(new String(CellUtil.cloneRow(cell))+"\t"+new String(CellUtil.cloneFamily(cell))+"\t"+new String(CellUtil.cloneQualifier(cell))+"\t"+new String(CellUtil.cloneValue(cell),"UTF-8")+"\t"+cell.getTimestamp());}}ht.close(); } hbase(main):013:0> scan 'users',{FILTER=>"RowFilter(=,'substring:01')"} ROW COLUMN+CELL xiaoming01 column=address:contry, timestamp=1442000277200, value=\xE4\xB8\xAD\xE5\x9B\xBD xiaoming01 column=address:country, timestamp=1442000228945, value=\xE4\xB8\xAD\xE5\x9B\xBD xiaoming01 column=info:age, timestamp=1441998917568, value=24 1 row(s) in 0.0190 seconds

    5.PageFilter(Shell不支持?)
    指定頁面行數,返回對應行數的結果集。
    需要注意的是,該過濾器并不能保證返回的結果行數小于等于指定的頁面行數,因為過濾器是分別作用到各個region server的,它只能保證當前region返回的結果行數不超過指定頁面行數。
    構造函數:PageFilter(long pageSize)

    //PageFilter例子 private static void scanFilter10() throws IOException,UnsupportedEncodingException {Configuration conf = HBaseConfiguration.create();conf.set("hbase.rootdir", "hdfs://ncst:9000/hbase");conf.set("hbase.zookeeper.quorum", "ncst");HTable ht = new HTable(conf, "users");//從RowKey為 "xiaoming" 開始,取3行(包含xiaoming) PageFilter pageFilter = new PageFilter(3L);Scan scan = new Scan();scan.setStartRow("xiaoming".getBytes());scan.setFilter(pageFilter);ResultScanner rs = ht.getScanner(scan);for(Result result : rs){for(Cell cell : result.rawCells()){System.out.println(new String(CellUtil.cloneRow(cell))+"\t"+new String(CellUtil.cloneFamily(cell))+"\t"+new String(CellUtil.cloneQualifier(cell))+"\t"+new String(CellUtil.cloneValue(cell),"UTF-8")+"\t"+cell.getTimestamp());}}ht.close(); }

    注意:由于該過濾器并不能保證返回的結果行數小于等于指定的頁面行數,所以更好的返回指定行數的辦法是ResultScanner.next(int nbRows),即:

    //上面Demo的改動版
    private static void scanFilter11() throws IOException,UnsupportedEncodingException {Configuration conf = HBaseConfiguration.create();conf.set("hbase.rootdir", "hdfs://ncst:9000/hbase");conf.set("hbase.zookeeper.quorum", "ncst");HTable ht = new HTable(conf, "users");//從RowKey為 "xiaoming" 開始,取3行(包含xiaoming) //PageFilter pageFilter = new PageFilter(3L);Scan scan = new Scan();scan.setStartRow("xiaoming".getBytes());//scan.setFilter(pageFilter);ResultScanner rs = ht.getScanner(scan);//指定返回3行數據for(Result result : rs.next(3)){for(Cell cell : result.rawCells()){System.out.println(new String(CellUtil.cloneRow(cell))+"\t"+new String(CellUtil.cloneFamily(cell))+"\t"+new String(CellUtil.cloneQualifier(cell))+"\t"+new String(CellUtil.cloneValue(cell),"UTF-8")+"\t"+cell.getTimestamp());}}ht.close(); }

    6.SkipFilter(Shell不支持)
    根據整行中的每個列來做過濾,只要存在一列不滿足條件,整行都被過濾掉。
    構造函數:SkipFilter(Filter filter)

    例如,如果一行中的所有列代表的是不同物品的重量,則真實場景下這些數值都必須大于零,我們希望將那些包含任意列值為0的行都過濾掉。在這個情況下,我們結合ValueFilter和SkipFilter共同實現該目的:
    scan.setFilter(new SkipFilter(new ValueFilter(CompareOp.NOT_EQUAL,new BinaryComparator(Bytes.toBytes(0))));

    //SkipFilter例子 private static void scanFilter12() throws IOException,UnsupportedEncodingException {Configuration conf = HBaseConfiguration.create();conf.set("hbase.rootdir", "hdfs://ncst:9000/hbase");conf.set("hbase.zookeeper.quorum", "ncst");HTable ht = new HTable(conf, "users");//跳過列值中包含"24"的所有列SkipFilter skipFilter = new SkipFilter(new ValueFilter(CompareOp.NOT_EQUAL, new BinaryComparator("24".getBytes())));Scan scan = new Scan();scan.setFilter(skipFilter);ResultScanner rs = ht.getScanner(scan);for(Result result : rs){for(Cell cell : result.rawCells()){System.out.println(new String(CellUtil.cloneRow(cell))+"\t"+new String(CellUtil.cloneFamily(cell))+"\t"+new String(CellUtil.cloneQualifier(cell))+"\t"+new String(CellUtil.cloneValue(cell),"UTF-8")+"\t"+cell.getTimestamp());}}ht.close(); }

    7.Utility--FirstKeyOnlyFilter
    該過濾器僅僅返回每一行中第一個cell的值,可以用于高效的執行行數統計操作。估計實戰意義不大。
    構造函數:public FirstKeyOnlyFilter()

    //FirstKeyOnlyFilter例子 private static void scanFilter12() throws IOException,UnsupportedEncodingException {Configuration conf = HBaseConfiguration.create();conf.set("hbase.rootdir", "hdfs://ncst:9000/hbase");conf.set("hbase.zookeeper.quorum", "ncst");HTable ht = new HTable(conf, "users");//返回每一行中的第一個cell的值FirstKeyOnlyFilter firstKeyOnlyFilter = new FirstKeyOnlyFilter();Scan scan = new Scan();scan.setFilter(firstKeyOnlyFilter);ResultScanner rs = ht.getScanner(scan);int i = 0;for(Result result : rs){for(Cell cell : result.rawCells()){System.out.println(new String(CellUtil.cloneRow(cell))+"\t"+new String(CellUtil.cloneFamily(cell))+"\t"+new String(CellUtil.cloneQualifier(cell))+"\t"+new String(CellUtil.cloneValue(cell),"UTF-8")+"\t"+cell.getTimestamp());i++;}}//輸出總的行數System.out.println(i);ht.close(); } hbase(main):009:0> scan 'users',{FILTER=>'FirstKeyOnlyFilter()'} ROW COLUMN+CELL xiaoming column=address:city, timestamp=1441997498965, value=hangzhou xiaoming01 column=address:contry, timestamp=1442000277200, value=\xE4\xB8\xAD\xE5\x9B\xBD xiaoming02 column=info:age, timestamp=1441998917594, value=24 xiaoming03 column=info:age, timestamp=1441998919607, value=24 zhangyifei column=address:city, timestamp=1441997499108, value=jieyang 5 row(s) in 0.0240 seconds

    轉載于:https://www.cnblogs.com/davidwang456/p/8303056.html

    總結

    以上是生活随笔為你收集整理的HBase Filter及对应Shell--转的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

    主站蜘蛛池模板: 成人性毛片 | 动漫女生光屁股 | 秋霞福利 | 三年大片在线观看 | 成人动漫久久 | 精品久久人人 | 国产一区二区三区四区视频 | 天天色成人网 | 亚洲男人的天堂网 | 国产激情在线 | 亚洲欧美国产精品专区久久 | www.视频一区| 热久久伊人 | 天天干天天操天天操 | 久久嫩草 | a天堂资源在线 | 日韩福利视频 | 国产小视频网址 | 色综合免费视频 | 成人黄色片网站 | 91玉足脚交嫩脚丫在线播放 | 天堂新版8中文在线8 | aaa人片在线 | 国产一级做a爰片久久毛片男 | 国产浮力第一页 | 乱老熟女一区二区三区 | 可以直接看的毛片 | 色婷婷久久综合中文久久蜜桃av | 国产一二区视频 | 日日夜夜免费精品 | 亚洲一区亚洲二区 | 99久久人妻无码中文字幕系列 | 欧美日韩国产三区 | 亚洲桃色av| 国模av在线 | 青春草国产视频 | 久久久久国产精品一区二区 | 操碰人人 | 亚洲一区二区三区四区电影 | 国产曰肥老太婆无遮挡 | 欲涩漫入口免费网站 | 成人黄色在线 | 亚洲欧美中文日韩在线 | 亚洲精品国产91 | 日韩有码专区 | 欧美韩国日本在线 | 人人干狠狠干 | 美女xx网站| 日本人妻一区二区三区 | 黑人vs亚洲人在线播放 | 五月天综合久久 | 日本久久亚洲 | 国产又黄又爽视频 | 日韩福利电影在线 | 亚洲精品国产精品乱码视色 | av网站免费在线观看 | 亚洲精品国产精品乱码不卡 | 日本熟妇色xxxxx日本免费看 | 午夜看片福利 | 久久影院一区二区 | 初尝人妻少妇中文字幕 | 日韩av电影一区 | 制服.丝袜.亚洲.中文.综合 | 国产suv精品一区二区6 | 天天插日日干 | 特级黄色一级片 | 久久一本综合 | 99re伊人| 成人免费观看网址 | 天天干视频在线观看 | 中文字幕av日韩 | 精品国产免费人成在线观看 | 先锋资源中文字幕 | 丰满少妇麻豆av苏语棠 | 久久久久九九九 | 岛国av一区二区三区 | 国产一区二区波多野结衣 | 亚洲va在线观看 | 国产一区2区 | av福利网站 | 日韩视频在线观看一区二区三区 | 国产高潮自拍 | 丰满雪白极品少妇流白浆 | 日韩免费久久 | 天天舔天天摸 | 精品视频免费播放 | 97涩涩网| 欧美日韩国产精品一区 | 亚洲天堂女人 | 可以看污的网站 | 国产精品91一区二区 | 国产欧美日韩在线播放 | 亚洲一区二区电影网 | 久久一热 | 爱插美女网 | 日本人妻不卡一区二区三区中文字幕 | 一区二区伦理 | 国内精品福利视频 | 天堂av中文在线 |