1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.accumulo.core.iterators;
18
19 import java.io.IOException;
20 import java.util.Collection;
21 import java.util.Map;
22
23 import org.apache.accumulo.core.data.ByteSequence;
24 import org.apache.accumulo.core.data.Key;
25 import org.apache.accumulo.core.data.Range;
26 import org.apache.accumulo.core.data.Value;
27
28 public class ColumnFamilyCounter implements SortedKeyValueIterator<Key,Value> {
29
30 private SortedKeyValueIterator<Key,Value> source;
31 private Key key;
32 private Value value;
33
34 @Override
35 public void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options, IteratorEnvironment env) throws IOException {
36 this.source = source;
37 }
38
39 @Override
40 public boolean hasTop() {
41 return key != null;
42 }
43
44 @Override
45 public void next() throws IOException {
46 if (source.hasTop()) {
47 ByteSequence currentRow = source.getTopKey().getRowData();
48 ByteSequence currentColf = source.getTopKey().getColumnFamilyData();
49 long ts = source.getTopKey().getTimestamp();
50
51 source.next();
52
53 int count = 1;
54
55 while (source.hasTop() && source.getTopKey().getRowData().equals(currentRow) && source.getTopKey().getColumnFamilyData().equals(currentColf)) {
56 count++;
57 source.next();
58 }
59
60 this.key = new Key(currentRow.toArray(), currentColf.toArray(), new byte[0], new byte[0], ts);
61 this.value = new Value(Integer.toString(count).getBytes());
62
63 } else {
64 this.key = null;
65 this.value = null;
66 }
67 }
68
69 @Override
70 public void seek(Range range, Collection<ByteSequence> columnFamilies, boolean inclusive) throws IOException {
71 source.seek(range, columnFamilies, inclusive);
72 next();
73 }
74
75 @Override
76 public Key getTopKey() {
77 return key;
78 }
79
80 @Override
81 public Value getTopValue() {
82 return value;
83 }
84
85 @Override
86 public SortedKeyValueIterator<Key,Value> deepCopy(IteratorEnvironment env) {
87
88 return null;
89 }
90
91 }