hbase 自定义过滤器
//定义的过滤器(值过滤) 的类 // 写完定义过滤器的类 打成 jar 报 ,分发到 每个region 服务器中 //分发完成后 需修改 hbase-env.sh 文件 // export HBASE_CLASSPATH="jar 包路径 ,重新启动hbase"; public class TestFilter extends FilterBase{ private byte[] value=null; //判断每一行数据是否过滤 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); } } //调用定义的过滤器 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); } }
相关推荐
hjr 2020-09-15
FightFourEggs 2020-08-16
踩风火轮的乌龟 2020-07-26
xiyoukeke 2020-07-19
xwb 2020-07-19
拿什么来拯救自己 2020-07-07
yjsflxiang 2020-07-04
luobotoutou 2020-06-16
JF0 2020-06-13
柠檬班 2020-06-11
adwen00 2020-06-09
hitxueliang 2020-06-05
PlayerL 2020-06-03
bluet00 2020-05-31
bianruifeng 2020-05-31
zhangchaoming 2020-05-17
wennuanwarm 2020-05-11
plusz 2020-05-09
nan00zzu 2020-05-11