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