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