1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.filter;
20
21 import com.google.common.base.Preconditions;
22 import com.google.protobuf.InvalidProtocolBufferException;
23 import org.apache.hadoop.classification.InterfaceAudience;
24 import org.apache.hadoop.classification.InterfaceStability;
25 import org.apache.hadoop.hbase.KeyValue;
26 import org.apache.hadoop.hbase.exceptions.DeserializationException;
27 import org.apache.hadoop.hbase.protobuf.generated.FilterProtos;
28
29 import java.util.ArrayList;
30
31
32
33
34
35
36 @InterfaceAudience.Public
37 @InterfaceStability.Stable
38 public class FirstKeyOnlyFilter extends FilterBase {
39 private boolean foundKV = false;
40
41 public FirstKeyOnlyFilter() {
42 }
43
44 public void reset() {
45 foundKV = false;
46 }
47
48 public ReturnCode filterKeyValue(KeyValue v) {
49 if(foundKV) return ReturnCode.NEXT_ROW;
50 foundKV = true;
51 return ReturnCode.INCLUDE;
52 }
53
54 public static Filter createFilterFromArguments(ArrayList<byte []> filterArguments) {
55 Preconditions.checkArgument(filterArguments.size() == 0,
56 "Expected 0 but got: %s", filterArguments.size());
57 return new FirstKeyOnlyFilter();
58 }
59
60
61
62
63 protected boolean hasFoundKV() {
64 return this.foundKV;
65 }
66
67
68
69
70
71 protected void setFoundKV(boolean value) {
72 this.foundKV = value;
73 }
74
75
76
77
78 public byte [] toByteArray() {
79 FilterProtos.FirstKeyOnlyFilter.Builder builder =
80 FilterProtos.FirstKeyOnlyFilter.newBuilder();
81 return builder.build().toByteArray();
82 }
83
84
85
86
87
88
89
90 public static FirstKeyOnlyFilter parseFrom(final byte [] pbBytes)
91 throws DeserializationException {
92
93 try {
94 FilterProtos.FirstKeyOnlyFilter.parseFrom(pbBytes);
95 } catch (InvalidProtocolBufferException e) {
96 throw new DeserializationException(e);
97 }
98
99 return new FirstKeyOnlyFilter();
100 }
101
102
103
104
105
106
107 boolean areSerializedFieldsEqual(Filter o) {
108 if (o == this) return true;
109 if (!(o instanceof FirstKeyOnlyFilter)) return false;
110
111 return true;
112 }
113 }