//The class of the defined filter (value filter) // After writing the class that defines the filter, make a jar report and distribute it to each region server //After the distribution is completed, the hbase-env.sh file needs to be modified // export HBASE_CLASSPATH="jar package path, restart hbase"; public class TestFilter extends FilterBase{ private byte[] value=null; / / Determine whether each row of data is filtered private boolean filterbz=true; public TestFilter(){ super(); } public TestFilter(byte[] value){ this.value=value; } public void write(DataOutput out) throws IOException { // TODO Auto-generated method stub Bytes.writeByteArray(out, value); } @Override public void reset(){ this.filterbz=true; } public ReturnCode filterKeyValue(KeyValue kv){ if(Bytes.compareTo(value, kv.getValue())==0){ filterbz=false; } return ReturnCode.INCLUDE; } @Override public boolean filterRow(){ return filterbz; } public void readFields(DataInput in) throws IOException { // TODO Auto-generated method stub this.value=Bytes.readByteArray(in); } } // call the defined filter public static void testglq(String tablename) throws IOException{ HTable table = new HTable(getconfig(), tablename); Filter filter=new TestFilter(Bytes.toBytes("value1")); Scan scan=new Scan(); scan.setFilter(filter); ResultScanner scanner=table.getScanner(scan); for (Result result : scanner) { System.out.println(result); } }
hbase custom filter
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=326343788&siteId=291194637
Recommended
Ranking