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
42
43
44
45
46
47
48
49
50
51
52
53
54 @InterfaceAudience.Public
55 @InterfaceStability.Stable
56 public class SkipFilter extends FilterBase {
57 private boolean filterRow = false;
58 private Filter filter;
59
60 public SkipFilter(Filter filter) {
61 this.filter = filter;
62 }
63
64 public Filter getFilter() {
65 return filter;
66 }
67
68 @Override
69 public void reset() throws IOException {
70 filter.reset();
71 filterRow = false;
72 }
73
74 private void changeFR(boolean value) {
75 filterRow = filterRow || value;
76 }
77
78 @Override
79 public ReturnCode filterKeyValue(Cell v) throws IOException {
80 ReturnCode c = filter.filterKeyValue(v);
81 changeFR(c != ReturnCode.INCLUDE);
82 return c;
83 }
84
85 @Override
86 public Cell transformCell(Cell v) throws IOException {
87 return filter.transformCell(v);
88 }
89
90 @Override
91 public boolean 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.SkipFilter.Builder builder =
106 FilterProtos.SkipFilter.newBuilder();
107 builder.setFilter(ProtobufUtil.toFilter(this.filter));
108 return builder.build().toByteArray();
109 }
110
111
112
113
114
115
116
117 public static SkipFilter parseFrom(final byte [] pbBytes)
118 throws DeserializationException {
119 FilterProtos.SkipFilter proto;
120 try {
121 proto = FilterProtos.SkipFilter.parseFrom(pbBytes);
122 } catch (InvalidProtocolBufferException e) {
123 throw new DeserializationException(e);
124 }
125 try {
126 return new SkipFilter(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 SkipFilter)) return false;
141
142 SkipFilter other = (SkipFilter)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 }