View Javadoc

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 column value. It takes an
27   * operator (equal, greater, not equal, etc) and a byte [] comparator for the
28   * cell value.
29   * <p>
30   * This filter can be wrapped with {@link WhileMatchFilter} and {@link SkipFilter}
31   * to add more control.
32   * <p>
33   * Multiple filters can be combined using {@link FilterList}.
34   * <p>
35   * To test the value of a single qualifier when scanning multiple qualifiers,
36   * use {@link SingleColumnValueFilter}.
37   */
38  public class ValueFilter extends CompareFilter {
39  
40    /**
41     * Writable constructor, do not use.
42     */
43    public ValueFilter() {
44    }
45  
46    /**
47     * Constructor.
48     * @param valueCompareOp the compare op for value matching
49     * @param valueComparator the comparator for value matching
50     */
51    public ValueFilter(final CompareOp valueCompareOp,
52        final WritableByteArrayComparable valueComparator) {
53      super(valueCompareOp, valueComparator);
54    }
55  
56    @Override
57    public ReturnCode filterKeyValue(KeyValue v) {
58      if (doCompare(this.compareOp, this.comparator, v.getBuffer(),
59          v.getValueOffset(), v.getValueLength())) {
60        return ReturnCode.SKIP;
61      }
62      return ReturnCode.INCLUDE;
63    }
64  }