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 @InterfaceAudience.Public
53 @InterfaceStability.Stable
54 public class SkipFilter extends FilterBase {
55 private boolean filterRow = false;
56 private Filter filter;
57
58 public SkipFilter(Filter filter) {
59 this.filter = filter;
60 }
61
62 public Filter getFilter() {
63 return filter;
64 }
65
66 @Override
67 public void reset() throws IOException {
68 filter.reset();
69 filterRow = false;
70 }
71
72 private void changeFR(boolean value) {
73 filterRow = filterRow || value;
74 }
75
76 @Override
77 public ReturnCode filterKeyValue(Cell v) throws IOException {
78 ReturnCode c = filter.filterKeyValue(v);
79 changeFR(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 public boolean filterRow() {
89 return filterRow;
90 }
91
92 public boolean hasFilterRow() {
93 return true;
94 }
95
96
97
98
99 public byte[] toByteArray() throws IOException {
100 FilterProtos.SkipFilter.Builder builder =
101 FilterProtos.SkipFilter.newBuilder();
102 builder.setFilter(ProtobufUtil.toFilter(this.filter));
103 return builder.build().toByteArray();
104 }
105
106
107
108
109
110
111
112 public static SkipFilter parseFrom(final byte [] pbBytes)
113 throws DeserializationException {
114 FilterProtos.SkipFilter proto;
115 try {
116 proto = FilterProtos.SkipFilter.parseFrom(pbBytes);
117 } catch (InvalidProtocolBufferException e) {
118 throw new DeserializationException(e);
119 }
120 try {
121 return new SkipFilter(ProtobufUtil.toFilter(proto.getFilter()));
122 } catch (IOException ioe) {
123 throw new DeserializationException(ioe);
124 }
125 }
126
127
128
129
130
131
132 boolean areSerializedFieldsEqual(Filter o) {
133 if (o == this) return true;
134 if (!(o instanceof SkipFilter)) return false;
135
136 SkipFilter other = (SkipFilter)o;
137 return getFilter().areSerializedFieldsEqual(other.getFilter());
138 }
139
140 public boolean isFamilyEssential(byte[] name) throws IOException {
141 return filter.isFamilyEssential(name);
142 }
143
144 @Override
145 public String toString() {
146 return this.getClass().getSimpleName() + " " + this.filter.toString();
147 }
148 }