1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.hadoop.hbase.regionserver;
22
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25 import org.apache.hadoop.hbase.regionserver.ScanQueryMatcher.MatchCode;
26 import org.apache.hadoop.hbase.util.Bytes;
27
28
29
30
31 public class ScanWildcardColumnTracker implements ColumnTracker {
32 private static final Log LOG =
33 LogFactory.getLog(ScanWildcardColumnTracker.class);
34 private byte [] columnBuffer = null;
35 private int columnOffset = 0;
36 private int columnLength = 0;
37 private int currentCount = 0;
38 private int maxVersions;
39
40
41
42
43
44 public ScanWildcardColumnTracker(int maxVersion) {
45 this.maxVersions = maxVersion;
46 }
47
48
49
50
51
52
53
54
55
56
57
58 @Override
59 public MatchCode checkColumn(byte[] bytes, int offset, int length) {
60 if (columnBuffer == null) {
61
62 columnBuffer = bytes;
63 columnOffset = offset;
64 columnLength = length;
65 currentCount = 0;
66
67 if (++currentCount > maxVersions)
68 return ScanQueryMatcher.MatchCode.SKIP;
69 return ScanQueryMatcher.MatchCode.INCLUDE;
70 }
71 int cmp = Bytes.compareTo(bytes, offset, length,
72 columnBuffer, columnOffset, columnLength);
73 if (cmp == 0) {
74 if (++currentCount > maxVersions)
75 return ScanQueryMatcher.MatchCode.SKIP;
76 return ScanQueryMatcher.MatchCode.INCLUDE;
77 }
78
79
80 if (cmp > 0) {
81
82 columnBuffer = bytes;
83 columnOffset = offset;
84 columnLength = length;
85 currentCount = 0;
86 if (++currentCount > maxVersions)
87 return ScanQueryMatcher.MatchCode.SKIP;
88 return ScanQueryMatcher.MatchCode.INCLUDE;
89 }
90
91
92
93
94
95
96 LOG.error("ScanWildcardColumnTracker.checkColumn ran " +
97 "into a column actually smaller than the previous column: " +
98 Bytes.toStringBinary(bytes, offset, length));
99
100 columnBuffer = bytes;
101 columnOffset = offset;
102 columnLength = length;
103 currentCount = 0;
104 if (++currentCount > maxVersions)
105 return ScanQueryMatcher.MatchCode.SKIP;
106 return ScanQueryMatcher.MatchCode.INCLUDE;
107 }
108
109 @Override
110 public void update() {
111
112 throw new UnsupportedOperationException(
113 "ScanWildcardColumnTracker.update should never be called!");
114 }
115
116 @Override
117 public void reset() {
118 columnBuffer = null;
119 }
120
121
122
123
124
125
126
127
128 public ColumnCount getColumnHint() {
129 return null;
130 }
131
132
133
134
135
136
137 @Override
138 public boolean done() {
139 return false;
140 }
141 }