familyfilter 用于过滤family
package com.fatkun.filter;import java.io.ioexception;import org.apache.hadoop.conf.configuration;import org.apache.hadoop.hbase.hbaseconfiguration;import org.apache.hadoop.hbase.hcolumndescriptor;import org.apache.hadoop.hbase.htabledescriptor;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.binarycomparator;import org.apache.hadoop.hbase.filter.comparefilter;import org.apache.hadoop.hbase.filter.familyfilter;import org.apache.hadoop.hbase.filter.filter;import org.apache.hadoop.hbase.util.bytes;public class testhbasefamilyfilter { string tablename = test_family_filter; configuration config = hbaseconfiguration.create(); /** * 部分代码来自hbase权威指南 * @throws ioexception */ public void testrowfilter() throws ioexception { htable table = new htable(config, tablename); scan scan = new scan(); system.out.println(只列出小于data2的列); filter filter1 = new familyfilter(comparefilter.compareop.less, new binarycomparator(bytes.tobytes(data2))); scan.setfilter(filter1); resultscanner scanner1 = table.getscanner(scan); for (result res : scanner1) { system.out.println(res); } scanner1.close(); system.out.println(get也可以设置filter); get get1 = new get(bytes.tobytes(row005)); get1.setfilter(filter1); result result1 = table.get(get1); system.out.println(result of get(): + result1); } /** * 初始化数据 */ public void init() { // 创建表和初始化数据 try { hbaseadmin admin = new hbaseadmin(config); if (!admin.tableexists(tablename)) { htabledescriptor htd = new htabledescriptor(tablename); hcolumndescriptor hcd1 = new hcolumndescriptor(data1); htd.addfamily(hcd1); hcolumndescriptor hcd2 = new hcolumndescriptor(data2); htd.addfamily(hcd2); hcolumndescriptor hcd3 = new hcolumndescriptor(data3); htd.addfamily(hcd3); admin.createtable(htd); } htable table = new htable(config, tablename); table.setautoflush(false); int count = 50; for (int i = 1; i 原文地址:hbase familyfilter, 感谢原作者分享。
