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 public boolean filterRow() {
91 return filterRow;
92 }
93
94 public boolean hasFilterRow() {
95 return true;
96 }
97
98
99
100
101 public byte[] toByteArray() throws IOException {
102 FilterProtos.SkipFilter.Builder builder =
103 FilterProtos.SkipFilter.newBuilder();
104 builder.setFilter(ProtobufUtil.toFilter(this.filter));
105 return builder.build().toByteArray();
106 }
107
108
109
110
111
112
113
114 public static SkipFilter parseFrom(final byte [] pbBytes)
115 throws DeserializationException {
116 FilterProtos.SkipFilter proto;
117 try {
118 proto = FilterProtos.SkipFilter.parseFrom(pbBytes);
119 } catch (InvalidProtocolBufferException e) {
120 throw new DeserializationException(e);
121 }
122 try {
123 return new SkipFilter(ProtobufUtil.toFilter(proto.getFilter()));
124 } catch (IOException ioe) {
125 throw new DeserializationException(ioe);
126 }
127 }
128
129
130
131
132
133
134 boolean areSerializedFieldsEqual(Filter o) {
135 if (o == this) return true;
136 if (!(o instanceof SkipFilter)) return false;
137
138 SkipFilter other = (SkipFilter)o;
139 return getFilter().areSerializedFieldsEqual(other.getFilter());
140 }
141
142 public boolean isFamilyEssential(byte[] name) throws IOException {
143 return filter.isFamilyEssential(name);
144 }
145
146 @Override
147 public String toString() {
148 return this.getClass().getSimpleName() + " " + this.filter.toString();
149 }
150 }