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 import org.apache.hadoop.hbase.client.Get; 25 26 /** 27 * This filter is used to filter based on the column qualifier. It takes an 28 * operator (equal, greater, not equal, etc) and a byte [] comparator for the 29 * column qualifier portion of a key. 30 * <p> 31 * This filter can be wrapped with {@link WhileMatchFilter} and {@link SkipFilter} 32 * to add more control. 33 * <p> 34 * Multiple filters can be combined using {@link FilterList}. 35 * <p> 36 * If an already known column qualifier is looked for, use {@link Get#addColumn} 37 * directly rather than a filter. 38 */ 39 public class QualifierFilter extends CompareFilter { 40 41 /** 42 * Writable constructor, do not use. 43 */ 44 public QualifierFilter() { 45 } 46 47 /** 48 * Constructor. 49 * @param qualifierCompareOp the compare op for column qualifier matching 50 * @param qualifierComparator the comparator for column qualifier matching 51 */ 52 public QualifierFilter(final CompareOp qualifierCompareOp, 53 final WritableByteArrayComparable qualifierComparator) { 54 super(qualifierCompareOp, qualifierComparator); 55 } 56 57 @Override 58 public ReturnCode filterKeyValue(KeyValue v) { 59 int qualifierLength = v.getQualifierLength(); 60 if (qualifierLength > 0) { 61 if (doCompare(this.compareOp, this.comparator, v.getBuffer(), 62 v.getQualifierOffset(), qualifierLength)) { 63 return ReturnCode.SKIP; 64 } 65 } 66 return ReturnCode.INCLUDE; 67 } 68 }