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