1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.client;
19
20 import java.io.IOException;
21
22 import org.apache.hadoop.hbase.Cell;
23 import org.apache.hadoop.hbase.classification.InterfaceAudience;
24 import org.apache.hadoop.hbase.exceptions.DeserializationException;
25 import org.apache.hadoop.hbase.filter.FilterBase;
26 import org.apache.hadoop.hbase.util.Bytes;
27
28 @InterfaceAudience.Private
29 public final class ColumnCountOnRowFilter extends FilterBase {
30
31 private final int limit;
32
33 private int count = 0;
34
35 public ColumnCountOnRowFilter(int limit) {
36 this.limit = limit;
37 }
38
39 @Override
40 public ReturnCode filterKeyValue(Cell v) throws IOException {
41 count++;
42 return count > limit ? ReturnCode.NEXT_ROW : ReturnCode.INCLUDE;
43 }
44
45 @Override
46 public void reset() throws IOException {
47 this.count = 0;
48 }
49
50 @Override
51 public byte[] toByteArray() throws IOException {
52 return Bytes.toBytes(limit);
53 }
54
55 public static ColumnCountOnRowFilter parseFrom(byte[] bytes) throws DeserializationException {
56 return new ColumnCountOnRowFilter(Bytes.toInt(bytes));
57 }
58 }