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.filter.CompareFilter.CompareOp; 25 26 /** 27 * A {@link Filter} that checks a single column value, but does not emit the 28 * tested column. This will enable a performance boost over 29 * {@link SingleColumnValueFilter}, if the tested column value is not actually 30 * needed as input (besides for the filtering itself). 31 */ 32 public class SingleColumnValueExcludeFilter extends SingleColumnValueFilter { 33 34 /** 35 * Writable constructor, do not use. 36 */ 37 public SingleColumnValueExcludeFilter() { 38 super(); 39 } 40 41 /** 42 * Constructor for binary compare of the value of a single column. If the 43 * column is found and the condition passes, all columns of the row will be 44 * emitted; except for the tested column value. If the column is not found or 45 * the condition fails, the row will not be emitted. 46 * 47 * @param family name of column family 48 * @param qualifier name of column qualifier 49 * @param compareOp operator 50 * @param value value to compare column values against 51 */ 52 public SingleColumnValueExcludeFilter(byte[] family, byte[] qualifier, 53 CompareOp compareOp, byte[] value) { 54 super(family, qualifier, compareOp, value); 55 } 56 57 /** 58 * Constructor for binary compare of the value of a single column. If the 59 * column is found and the condition passes, all columns of the row will be 60 * emitted; except for the tested column value. If the condition fails, the 61 * row will not be emitted. 62 * <p> 63 * Use the filterIfColumnMissing flag to set whether the rest of the columns 64 * in a row will be emitted if the specified column to check is not found in 65 * the row. 66 * 67 * @param family name of column family 68 * @param qualifier name of column qualifier 69 * @param compareOp operator 70 * @param comparator Comparator to use. 71 */ 72 public SingleColumnValueExcludeFilter(byte[] family, byte[] qualifier, 73 CompareOp compareOp, WritableByteArrayComparable comparator) { 74 super(family, qualifier, compareOp, comparator); 75 } 76 77 public ReturnCode filterKeyValue(KeyValue keyValue) { 78 ReturnCode superRetCode = super.filterKeyValue(keyValue); 79 if (superRetCode == ReturnCode.INCLUDE) { 80 // If the current column is actually the tested column, 81 // we will skip it instead. 82 if (keyValue.matchingColumn(this.columnFamily, this.columnQualifier)) { 83 return ReturnCode.SKIP; 84 } 85 } 86 return superRetCode; 87 } 88 }