1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.hadoop.hbase.filter;
21
22 import java.io.IOException;
23
24 import org.apache.hadoop.hbase.classification.InterfaceAudience;
25 import org.apache.hadoop.hbase.classification.InterfaceStability;
26 import org.apache.hadoop.hbase.Cell;
27 import org.apache.hadoop.hbase.exceptions.DeserializationException;
28 import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
29 import org.apache.hadoop.hbase.protobuf.generated.FilterProtos;
30
31 import com.google.protobuf.InvalidProtocolBufferException;
32
33
34
35
36
37
38
39
40
41 @InterfaceAudience.Public
42 @InterfaceStability.Stable
43 public class WhileMatchFilter extends FilterBase {
44 private boolean filterAllRemaining = false;
45 private Filter filter;
46
47 public WhileMatchFilter(Filter filter) {
48 this.filter = filter;
49 }
50
51 public Filter getFilter() {
52 return filter;
53 }
54
55 @Override
56 public void reset() throws IOException {
57 this.filter.reset();
58 }
59
60 private void changeFAR(boolean value) {
61 filterAllRemaining = filterAllRemaining || value;
62 }
63
64 @Override
65 public boolean filterAllRemaining() throws IOException {
66 return this.filterAllRemaining || this.filter.filterAllRemaining();
67 }
68
69 @Override
70 public boolean filterRowKey(byte[] buffer, int offset, int length) throws IOException {
71 boolean value = filter.filterRowKey(buffer, offset, length);
72 changeFAR(value);
73 return value;
74 }
75
76 @Override
77 public ReturnCode filterKeyValue(Cell v) throws IOException {
78 ReturnCode c = filter.filterKeyValue(v);
79 changeFAR(c != ReturnCode.INCLUDE);
80 return c;
81 }
82
83 @Override
84 public Cell transformCell(Cell v) throws IOException {
85 return filter.transformCell(v);
86 }
87
88 @Override
89 public boolean filterRow() throws IOException {
90 boolean filterRow = this.filter.filterRow();
91 changeFAR(filterRow);
92 return filterRow;
93 }
94
95 @Override
96 public boolean hasFilterRow() {
97 return true;
98 }
99
100
101
102
103 @Override
104 public byte[] toByteArray() throws IOException {
105 FilterProtos.WhileMatchFilter.Builder builder =
106 FilterProtos.WhileMatchFilter.newBuilder();
107 builder.setFilter(ProtobufUtil.toFilter(this.filter));
108 return builder.build().toByteArray();
109 }
110
111
112
113
114
115
116
117 public static WhileMatchFilter parseFrom(final byte [] pbBytes)
118 throws DeserializationException {
119 FilterProtos.WhileMatchFilter proto;
120 try {
121 proto = FilterProtos.WhileMatchFilter.parseFrom(pbBytes);
122 } catch (InvalidProtocolBufferException e) {
123 throw new DeserializationException(e);
124 }
125 try {
126 return new WhileMatchFilter(ProtobufUtil.toFilter(proto.getFilter()));
127 } catch (IOException ioe) {
128 throw new DeserializationException(ioe);
129 }
130 }
131
132
133
134
135
136
137 @Override
138 boolean areSerializedFieldsEqual(Filter o) {
139 if (o == this) return true;
140 if (!(o instanceof WhileMatchFilter)) return false;
141
142 WhileMatchFilter other = (WhileMatchFilter)o;
143 return getFilter().areSerializedFieldsEqual(other.getFilter());
144 }
145
146 @Override
147 public boolean isFamilyEssential(byte[] name) throws IOException {
148 return filter.isFamilyEssential(name);
149 }
150
151 @Override
152 public String toString() {
153 return this.getClass().getSimpleName() + " " + this.filter.toString();
154 }
155 }