hbase valuefilter用于过滤值 package com.fatkun.filter.comparison;import java.io.ioexception;import org.apache.hadoop.conf.configuration;import org.apache.hadoop.hbase.hbaseconfiguration;import org.apache.hadoop.hbase.hcolumndescriptor;impo
hbase valuefilter用于过滤值
package com.fatkun.filter.comparison; 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.filter; import org.apache.hadoop.hbase.filter.substringcomparator; import org.apache.hadoop.hbase.filter.valuefilter; import org.apache.hadoop.hbase.util.bytes; public class testhbasevaluefilter { string tablename = "test_value_filter"; configuration config = hbaseconfiguration.create(); /** * 部分代码来自hbase权威指南 * * @throws ioexception */ public void testfilter() throws ioexception { htable table = new htable(config, tablename); scan scan = new scan(); system.out.println("只列出值包含data1的列"); filter filter1 = new valuefilter(comparefilter.compareop.equal, new substringcomparator("data1")); 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("row003")); 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【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!