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.Scan;
25
26 import java.util.List;
27
28 /**
29 * This filter is used to filter based on the key. It takes an operator
30 * (equal, greater, not equal, etc) and a byte [] comparator for the row,
31 * and column qualifier portions of a key.
32 * <p>
33 * This filter can be wrapped with {@link WhileMatchFilter} to add more control.
34 * <p>
35 * Multiple filters can be combined using {@link FilterList}.
36 * <p>
37 * If an already known row range needs to be scanned, use {@link Scan} start
38 * and stop rows directly rather than a filter.
39 */
40 public class RowFilter extends CompareFilter {
41
42 private boolean filterOutRow = false;
43
44 /**
45 * Writable constructor, do not use.
46 */
47 public RowFilter() {
48 super();
49 }
50
51 /**
52 * Constructor.
53 * @param rowCompareOp the compare op for row matching
54 * @param rowComparator the comparator for row matching
55 */
56 public RowFilter(final CompareOp rowCompareOp,
57 final WritableByteArrayComparable rowComparator) {
58 super(rowCompareOp, rowComparator);
59 }
60
61 @Override
62 public void reset() {
63 this.filterOutRow = false;
64 }
65
66 @Override
67 public ReturnCode filterKeyValue(KeyValue v) {
68 if(this.filterOutRow) {
69 return ReturnCode.NEXT_ROW;
70 }
71 return ReturnCode.INCLUDE;
72 }
73
74 @Override
75 public boolean filterRowKey(byte[] data, int offset, int length) {
76 if(doCompare(this.compareOp, this.comparator, data, offset, length)) {
77 this.filterOutRow = true;
78 }
79 return this.filterOutRow;
80 }
81
82 @Override
83 public boolean filterRow() {
84 return this.filterOutRow;
85 }
86 }