1 /** 2 * Copyright 2010 The Apache Software Foundation 3 * 4 * Licensed to the Apache Software Foundation (ASF) under one 5 * or more contributor license agreements. See the NOTICE file 6 * distributed with this work for additional information 7 * regarding copyright ownership. The ASF licenses this file 8 * to you under the Apache License, Version 2.0 (the 9 * "License"); you may not use this file except in compliance 10 * with the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, software 15 * distributed under the License is distributed on an "AS IS" BASIS, 16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 * See the License for the specific language governing permissions and 18 * limitations under the License. 19 */ 20 21 package org.apache.hadoop.hbase.filter; 22 23 import org.apache.hadoop.hbase.KeyValue; 24 25 /** 26 * This filter is used to filter based on the column family. It takes an 27 * operator (equal, greater, not equal, etc) and a byte [] comparator for the 28 * column family portion of a key. 29 * <p/> 30 * This filter can be wrapped with {@link org.apache.hadoop.hbase.filter.WhileMatchFilter} and {@link org.apache.hadoop.hbase.filter.SkipFilter} 31 * to add more control. 32 * <p/> 33 * Multiple filters can be combined using {@link org.apache.hadoop.hbase.filter.FilterList}. 34 * <p/> 35 * If an already known column family is looked for, use {@link org.apache.hadoop.hbase.client.Get#addFamily(byte[])} 36 * directly rather than a filter. 37 */ 38 public class FamilyFilter extends CompareFilter { 39 /** 40 * Writable constructor, do not use. 41 */ 42 public FamilyFilter() { 43 } 44 45 /** 46 * Constructor. 47 * 48 * @param familyCompareOp the compare op for column family matching 49 * @param familyComparator the comparator for column family matching 50 */ 51 public FamilyFilter(final CompareOp familyCompareOp, 52 final WritableByteArrayComparable familyComparator) { 53 super(familyCompareOp, familyComparator); 54 } 55 56 @Override 57 public ReturnCode filterKeyValue(KeyValue v) { 58 int familyLength = v.getFamilyLength(); 59 if (familyLength > 0) { 60 if (doCompare(this.compareOp, this.comparator, v.getBuffer(), 61 v.getFamilyOffset(), familyLength)) { 62 return ReturnCode.SKIP; 63 } 64 } 65 return ReturnCode.INCLUDE; 66 } 67 }