1 package org.apache.hadoop.hbase.filter;
2
3 import java.io.DataInput;
4 import java.io.DataOutput;
5 import java.io.IOException;
6 import java.util.List;
7 import java.util.TreeSet;
8
9 import org.apache.hadoop.hbase.KeyValue;
10
11
12
13
14
15
16
17
18
19
20 public class TimestampsFilter extends FilterBase {
21
22 TreeSet<Long> timestamps;
23
24
25
26 long minTimeStamp = Long.MAX_VALUE;
27
28
29
30
31 public TimestampsFilter() {
32 super();
33 }
34
35
36
37
38
39
40
41
42 public TimestampsFilter(List<Long> timestamps) {
43 this.timestamps = new TreeSet<Long>(timestamps);
44 init();
45 }
46
47 private void init() {
48 if (this.timestamps.size() > 0) {
49 minTimeStamp = this.timestamps.first();
50 }
51 }
52
53
54
55
56
57 public long getMin() {
58 return minTimeStamp;
59 }
60
61 @Override
62 public ReturnCode filterKeyValue(KeyValue v) {
63 if (this.timestamps.contains(v.getTimestamp())) {
64 return ReturnCode.INCLUDE;
65 } else if (v.getTimestamp() < minTimeStamp) {
66
67
68 return ReturnCode.NEXT_COL;
69 }
70 return ReturnCode.SKIP;
71 }
72
73 @Override
74 public void readFields(DataInput in) throws IOException {
75 int numTimestamps = in.readInt();
76 this.timestamps = new TreeSet<Long>();
77 for (int idx = 0; idx < numTimestamps; idx++) {
78 this.timestamps.add(in.readLong());
79 }
80 init();
81 }
82
83 @Override
84 public void write(DataOutput out) throws IOException {
85 int numTimestamps = this.timestamps.size();
86 out.writeInt(numTimestamps);
87 for (Long timestamp : this.timestamps) {
88 out.writeLong(timestamp);
89 }
90 }
91 }