Hbase过滤器2

根据限定符只返回一行数据,不存在:

public static void addQualifierFilter(FilterList list, byte[] family, byte[] qualifier) {
        byte[] fakeValue = Bytes.toBytes("DOESNOTEXIST");
        SingleColumnValueFilter filter = 
        	    new SingleColumnValueFilter(family, qualifier, CompareOp.NOT_EQUAL, fakeValue);  
        filter.setFilterIfMissing(true);
        list.addFilter(filter);
    }

 根据限定符选出不包含没有数据的:

 public static void addQualifierExcludeFilter(FilterList list, byte[] family, byte[] qualifier) {
    	SkipFilter filter = new SkipFilter(new QualifierFilter(CompareOp.NOT_EQUAL, new BinaryComparator(qualifier)));
        list.addFilter(filter);
    }

 根据时间来过滤:

public static void addTimeStampFilter(FilterList list, byte[] family, byte[] qualifier, byte[] timestamp) {
        SingleColumnValueFilter filter = 
        	    new SingleColumnValueFilter(family, qualifier, CompareOp.GREATER_OR_EQUAL, timestamp);
        list.addFilter(filter);
    }

 根据时间来过滤(不包含指定的时间):

public static void addTimeStampExcludeFilter(FilterList list, byte[] family, byte[] qualifier, byte[] timestamp) {
        SingleColumnValueExcludeFilter filter = 
        	    new SingleColumnValueExcludeFilter(family, qualifier, CompareOp.GREATER_OR_EQUAL, timestamp);
        list.addFilter(filter);
    }

 使用方法:

FilterList list = new FilterList();
		HBaseManager.addQualifierFilter(list, HTableConstant.USER_HOBBY_HOBBY_COLUMN_FAMILY, 
				HTableConstant.USER_HOBBY_USER_ID_QUALIFIER);
		HBaseManager.addTimeStampFilter(list,
				HTableConstant.USER_HOBBY_HOBBY_COLUMN_FAMILY,
				HTableConstant.USER_HOBBY_DATE_QUALIFIER, Bytes.toBytes(date));
		scan.setFilter(list);

 

你可能感兴趣的:(hbase)