Skip to content

Commit 3129b5f

Browse files
committed
HBASE-26762: Rename and deprecate setRowPrefixFilter to setStartStopRowForPrefixScan
Signed-off-by: Niels Basjes <nielsbasjes@apache.org>
1 parent a064359 commit 3129b5f

File tree

8 files changed

+56
-37
lines changed

8 files changed

+56
-37
lines changed

hbase-client/src/main/java/org/apache/hadoop/hbase/client/ImmutableScan.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ public Scan withStopRow(byte[] stopRow, boolean inclusive) {
9595
}
9696

9797
@Override
98-
public Scan setRowPrefixFilter(byte[] rowPrefix) {
98+
public Scan setStartStopRowForPrefixScan(byte[] rowPrefix) {
9999
throw new UnsupportedOperationException(
100-
"ImmutableScan does not allow access to setRowPrefixFilter");
100+
"ImmutableScan does not allow access to setStartStopRowForPrefixScan");
101101
}
102102

103103
@Override

hbase-client/src/main/java/org/apache/hadoop/hbase/client/Scan.java

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,8 @@ public Scan setTimestamp(long timestamp) {
340340
* If the specified row does not exist, the Scanner will start from the next closest row after the
341341
* specified row.
342342
* <p>
343-
* <b>Note:</b><strong>Do NOT use this in combination with
344-
* {@link #setRowPrefixFilter(byte[])}.</strong>
343+
* <b>Note:</b> <strong>Do NOT use this in combination with
344+
* {@link #setRowPrefixFilter(byte[])} or {@link #setStartStopRowForPrefixScan(byte[])}.</strong>
345345
* Doing so will make the scan result unexpected or even undefined.
346346
* </p>
347347
* @param startRow row to start scanner at or after
@@ -359,8 +359,8 @@ public Scan withStartRow(byte[] startRow) {
359359
* If the specified row does not exist, or the {@code inclusive} is {@code false}, the Scanner
360360
* will start from the next closest row after the specified row.
361361
* <p>
362-
* <b>Note:</b><strong>Do NOT use this in combination with
363-
* {@link #setRowPrefixFilter(byte[])}.</strong>
362+
* <b>Note:</b> <strong>Do NOT use this in combination with
363+
* {@link #setRowPrefixFilter(byte[])} or {@link #setStartStopRowForPrefixScan(byte[])}.</strong>
364364
* Doing so will make the scan result unexpected or even undefined.
365365
* </p>
366366
* @param startRow row to start scanner at or after
@@ -384,8 +384,8 @@ public Scan withStartRow(byte[] startRow, boolean inclusive) {
384384
* <p>
385385
* The scan will include rows that are lexicographically less than the provided stopRow.
386386
* <p>
387-
* <b>Note:</b><strong>Do NOT use this in combination with
388-
* {@link #setRowPrefixFilter(byte[])}.</strong>
387+
* <b>Note:</b> <strong>Do NOT use this in combination with
388+
* {@link #setRowPrefixFilter(byte[])} or {@link #setStartStopRowForPrefixScan(byte[])}.</strong>
389389
* Doing so will make the scan result unexpected or even undefined.
390390
* </p>
391391
* @param stopRow row to end at (exclusive)
@@ -403,8 +403,8 @@ public Scan withStopRow(byte[] stopRow) {
403403
* The scan will include rows that are lexicographically less than (or equal to if
404404
* {@code inclusive} is {@code true}) the provided stopRow.
405405
* <p>
406-
* <b>Note:</b><strong>Do NOT use this in combination with
407-
* {@link #setRowPrefixFilter(byte[])}.</strong>
406+
* <b>Note:</b> <strong>Do NOT use this in combination with
407+
* {@link #setRowPrefixFilter(byte[])} or {@link #setStartStopRowForPrefixScan(byte[])}.</strong>
408408
* Doing so will make the scan result unexpected or even undefined.
409409
* </p>
410410
* @param stopRow row to end at
@@ -433,8 +433,27 @@ public Scan withStopRow(byte[] stopRow, boolean inclusive) {
433433
* Such a combination will yield unexpected and even undefined results.</p>
434434
* @param rowPrefix the prefix all rows must start with. (Set <i>null</i> to remove the filter.)
435435
* @return this
436+
* @deprecated since 3.0.0. The name of this method is considered to be confusing as it does not
437+
* use a {@link Filter} but uses setting the startRow and stopRow instead.
438+
* Use {@link #setStartStopRowForPrefixScan(byte[])} instead.
436439
*/
440+
@Deprecated
437441
public Scan setRowPrefixFilter(byte[] rowPrefix) {
442+
return setStartStopRowForPrefixScan(rowPrefix);
443+
}
444+
445+
/**
446+
* <p>Set a filter (using stopRow and startRow) so the result set only contains rows where the
447+
* rowKey starts with the specified prefix.</p>
448+
* <p>This is a utility method that converts the desired rowPrefix into the appropriate values
449+
* for the startRow and stopRow to achieve the desired result.</p>
450+
* <p>This can safely be used in combination with setFilter.</p>
451+
* <p><strong>This CANNOT be used in combination with withStartRow and/or withStopRow.</strong>
452+
* Such a combination will yield unexpected and even undefined results.</p>
453+
* @param rowPrefix the prefix all rows must start with. (Set <i>null</i> to remove the filter.)
454+
* @return this
455+
*/
456+
public Scan setStartStopRowForPrefixScan(byte[] rowPrefix) {
438457
if (rowPrefix == null) {
439458
withStartRow(HConstants.EMPTY_START_ROW);
440459
withStopRow(HConstants.EMPTY_END_ROW);

hbase-client/src/main/java/org/apache/hadoop/hbase/quotas/QuotaTableUtil.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ public static Scan makeQuotaSnapshotScanForTable(TableName tn) {
288288
// Limit to "u:v" column
289289
s.addColumn(QUOTA_FAMILY_USAGE, QUOTA_QUALIFIER_POLICY);
290290
if (null == tn) {
291-
s.setRowPrefixFilter(QUOTA_TABLE_ROW_KEY_PREFIX);
291+
s.setStartStopRowForPrefixScan(QUOTA_TABLE_ROW_KEY_PREFIX);
292292
} else {
293293
byte[] row = getTableRowKey(tn);
294294
// Limit rowspace to the "t:" prefix
@@ -637,7 +637,7 @@ static void deleteTableUsageSnapshotsForNamespace(Connection connection, String
637637
throws IOException {
638638
Scan s = new Scan();
639639
//Get rows for all tables in namespace
640-
s.setRowPrefixFilter(Bytes.add(QUOTA_TABLE_ROW_KEY_PREFIX, Bytes.toBytes(namespace + TableName.NAMESPACE_DELIM)));
640+
s.setStartStopRowForPrefixScan(Bytes.add(QUOTA_TABLE_ROW_KEY_PREFIX, Bytes.toBytes(namespace + TableName.NAMESPACE_DELIM)));
641641
//Scan for table usage column (u:p) in quota table
642642
s.addColumn(QUOTA_FAMILY_USAGE,QUOTA_QUALIFIER_POLICY);
643643
//Scan for table quota column (q:s) if table has a space quota defined
@@ -706,7 +706,7 @@ static Scan createScanForNamespaceSnapshotSizes(String namespace) {
706706
Scan s = new Scan();
707707
if (namespace == null || namespace.isEmpty()) {
708708
// Read all namespaces, just look at the row prefix
709-
s.setRowPrefixFilter(QUOTA_NAMESPACE_ROW_KEY_PREFIX);
709+
s.setStartStopRowForPrefixScan(QUOTA_NAMESPACE_ROW_KEY_PREFIX);
710710
} else {
711711
// Fetch the exact row for the table
712712
byte[] rowkey = getNamespaceRowKey(namespace);
@@ -727,7 +727,7 @@ static Scan createScanForSpaceSnapshotSizes(TableName table) {
727727
Scan s = new Scan();
728728
if (null == table) {
729729
// Read all tables, just look at the row prefix
730-
s.setRowPrefixFilter(QUOTA_TABLE_ROW_KEY_PREFIX);
730+
s.setStartStopRowForPrefixScan(QUOTA_TABLE_ROW_KEY_PREFIX);
731731
} else {
732732
// Fetch the exact row for the table
733733
byte[] rowkey = getTableRowKey(table);

hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestImmutableScan.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public void testScanCopyConstructor() throws Exception {
8484
.setReplicaId(3)
8585
.setReversed(true)
8686
.setRowOffsetPerColumnFamily(5)
87-
.setRowPrefixFilter(Bytes.toBytes("row_"))
87+
.setStartStopRowForPrefixScan(Bytes.toBytes("row_"))
8888
.setScanMetricsEnabled(true)
8989
.setReadType(Scan.ReadType.STREAM)
9090
.withStartRow(Bytes.toBytes("row_1"))
@@ -181,10 +181,10 @@ private void testUnmodifiableSetters(Scan scanCopy) throws IOException {
181181
assertEquals("ImmutableScan does not allow access to withStopRow", e.getMessage());
182182
}
183183
try {
184-
scanCopy.setRowPrefixFilter(new byte[] { 1, 2 });
184+
scanCopy.setStartStopRowForPrefixScan(new byte[] { 1, 2 });
185185
throw new RuntimeException("Should not reach here");
186186
} catch (UnsupportedOperationException e) {
187-
assertEquals("ImmutableScan does not allow access to setRowPrefixFilter", e.getMessage());
187+
assertEquals("ImmutableScan does not allow access to setStartStopRowForPrefixScan", e.getMessage());
188188
}
189189
try {
190190
scanCopy.readAllVersions();

hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestScan.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ public void testScanCopyConstructor() throws Exception {
246246
.setReplicaId(3)
247247
.setReversed(true)
248248
.setRowOffsetPerColumnFamily(5)
249-
.setRowPrefixFilter(Bytes.toBytes("row_"))
249+
.setStartStopRowForPrefixScan(Bytes.toBytes("row_"))
250250
.setScanMetricsEnabled(true)
251251
.setReadType(ReadType.STREAM)
252252
.withStartRow(Bytes.toBytes("row_1"))

hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestScanRowPrefix.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
import org.slf4j.LoggerFactory;
4343

4444
/**
45-
* Test if Scan.setRowPrefixFilter works as intended.
45+
* Test if Scan.setStartStopRowForPrefixScan works as intended.
4646
*/
4747
@Category({FilterTests.class, MediumTests.class})
4848
public class TestScanRowPrefix extends FilterTestingCluster {
@@ -64,8 +64,8 @@ public void testPrefixScanning() throws IOException {
6464
Table table = openTable(tableName);
6565

6666
/**
67-
* Note that about half of these tests were relevant for an different implementation approach
68-
* of setRowPrefixFilter. These test cases have been retained to ensure that also the
67+
* Note that about half of these tests were relevant for a different implementation approach
68+
* of setStartStopRowForPrefixScan. These test cases have been retained to ensure that also the
6969
* edge cases found there are still covered.
7070
*/
7171

@@ -119,16 +119,16 @@ public void testPrefixScanning() throws IOException {
119119
// ========
120120
// PREFIX 0
121121
Scan scan = new Scan();
122-
scan.setRowPrefixFilter(prefix0);
122+
scan.setStartStopRowForPrefixScan(prefix0);
123123
verifyScanResult(table, scan, expected0, "Scan empty prefix failed");
124124

125125
// ========
126126
// PREFIX 1
127127
scan = new Scan();
128-
scan.setRowPrefixFilter(prefix1);
128+
scan.setStartStopRowForPrefixScan(prefix1);
129129
verifyScanResult(table, scan, expected1, "Scan normal prefix failed");
130130

131-
scan.setRowPrefixFilter(null);
131+
scan.setStartStopRowForPrefixScan(null);
132132
verifyScanResult(table, scan, expected0, "Scan after prefix reset failed");
133133

134134
scan = new Scan();
@@ -138,10 +138,10 @@ public void testPrefixScanning() throws IOException {
138138
// ========
139139
// PREFIX 2
140140
scan = new Scan();
141-
scan.setRowPrefixFilter(prefix2);
141+
scan.setStartStopRowForPrefixScan(prefix2);
142142
verifyScanResult(table, scan, expected2, "Scan edge 0xFF prefix failed");
143143

144-
scan.setRowPrefixFilter(null);
144+
scan.setStartStopRowForPrefixScan(null);
145145
verifyScanResult(table, scan, expected0, "Scan after prefix reset failed");
146146

147147
scan = new Scan();
@@ -151,10 +151,10 @@ public void testPrefixScanning() throws IOException {
151151
// ========
152152
// PREFIX 3
153153
scan = new Scan();
154-
scan.setRowPrefixFilter(prefix3);
154+
scan.setStartStopRowForPrefixScan(prefix3);
155155
verifyScanResult(table, scan, expected3, "Scan normal with 0x00 ends failed");
156156

157-
scan.setRowPrefixFilter(null);
157+
scan.setStartStopRowForPrefixScan(null);
158158
verifyScanResult(table, scan, expected0, "Scan after prefix reset failed");
159159

160160
scan = new Scan();
@@ -164,10 +164,10 @@ public void testPrefixScanning() throws IOException {
164164
// ========
165165
// PREFIX 4
166166
scan = new Scan();
167-
scan.setRowPrefixFilter(prefix4);
167+
scan.setStartStopRowForPrefixScan(prefix4);
168168
verifyScanResult(table, scan, expected4, "Scan end prefix failed");
169169

170-
scan.setRowPrefixFilter(null);
170+
scan.setStartStopRowForPrefixScan(null);
171171
verifyScanResult(table, scan, expected0, "Scan after prefix reset failed");
172172

173173
scan = new Scan();
@@ -178,13 +178,13 @@ public void testPrefixScanning() throws IOException {
178178
// COMBINED
179179
// Prefix + Filter
180180
scan = new Scan();
181-
scan.setRowPrefixFilter(prefix1);
181+
scan.setStartStopRowForPrefixScan(prefix1);
182182
verifyScanResult(table, scan, expected1, "Prefix filter failed");
183183

184184
scan.setFilter(new ColumnPrefixFilter(prefix2));
185185
verifyScanResult(table, scan, expected2, "Combined Prefix + Filter failed");
186186

187-
scan.setRowPrefixFilter(null);
187+
scan.setStartStopRowForPrefixScan(null);
188188
verifyScanResult(table, scan, expected2, "Combined Prefix + Filter; removing Prefix failed");
189189

190190
scan.setFilter(null);
@@ -196,13 +196,13 @@ public void testPrefixScanning() throws IOException {
196196
scan.setFilter(new ColumnPrefixFilter(prefix2));
197197
verifyScanResult(table, scan, expected2, "Test filter failed");
198198

199-
scan.setRowPrefixFilter(prefix1);
199+
scan.setStartStopRowForPrefixScan(prefix1);
200200
verifyScanResult(table, scan, expected2, "Combined Filter + Prefix failed");
201201

202202
scan.setFilter(null);
203203
verifyScanResult(table, scan, expected1, "Combined Filter + Prefix ; removing Filter failed");
204204

205-
scan.setRowPrefixFilter(null);
205+
scan.setStartStopRowForPrefixScan(null);
206206
verifyScanResult(table, scan, expected0, "Scan after prefix reset failed");
207207
}
208208

hbase-shell/src/main/ruby/hbase/table.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def _deleterows_internal(row, column = nil,
208208

209209
# create scan to get table names using prefix
210210
scan = org.apache.hadoop.hbase.client.Scan.new
211-
scan.setRowPrefixFilter(prefix.to_java_bytes)
211+
scan.setStartStopRowForPrefixScan(prefix.to_java_bytes)
212212
# Run the scanner to get all rowkeys
213213
scanner = @table.getScanner(scan)
214214
# Create a list to store all deletes
@@ -536,7 +536,7 @@ def _hash_to_scan(args)
536536
end
537537

538538
# This will overwrite any startrow/stoprow settings
539-
scan.setRowPrefixFilter(rowprefixfilter.to_java_bytes) if rowprefixfilter
539+
scan.setStartStopRowForPrefixScan(rowprefixfilter.to_java_bytes) if rowprefixfilter
540540

541541
# Clear converters from last scan.
542542
@converters.clear

src/main/asciidoc/_chapters/datamodel.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ Table table = ... // instantiate a Table instance
300300
301301
Scan scan = new Scan();
302302
scan.addColumn(CF, ATTR);
303-
scan.setRowPrefixFilter(Bytes.toBytes("row"));
303+
scan.setStartStopRowForPrefixScan(Bytes.toBytes("row"));
304304
ResultScanner rs = table.getScanner(scan);
305305
try {
306306
for (Result r = rs.next(); r != null; r = rs.next()) {

0 commit comments

Comments
 (0)