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