Skip to content

Commit 1bc507f

Browse files
fix(bigtable): reject empty split points in RowSetUtil and clarify QueryPaginator Javadoc (#14811)
Clarify `Query.QueryPaginator#advance` Javadoc and example usage, and reject empty keys in `RowSetUtil#erase` and `RowSetUtil#eraseLargeRow`.
1 parent 323a8f7 commit 1bc507f

3 files changed

Lines changed: 27 additions & 2 deletions

File tree

‎java-bigtable/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/RowSetUtil.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ private RowSetUtil() {}
5151

5252
/** Removes the {@code #excludePoint} rowkey from the {@code RowSet} */
5353
public static RowSet eraseLargeRow(RowSet rowSet, ByteString excludePoint) {
54+
Preconditions.checkArgument(!excludePoint.isEmpty(), "Can't handle empty excludePoint");
5455

5556
RowSet.Builder newRowSet = RowSet.newBuilder();
5657

@@ -89,6 +90,7 @@ public static RowSet eraseLargeRow(RowSet rowSet, ByteString excludePoint) {
8990
* removed. The primary usecase is to resume a broken ReadRows stream.
9091
*/
9192
public static RowSet erase(RowSet rowSet, ByteString splitPoint, boolean fromStart) {
93+
Preconditions.checkArgument(!splitPoint.isEmpty(), "Can't handle empty splitPoint");
9294
RowSet.Builder newRowSet = RowSet.newBuilder();
9395

9496
if (rowSet.getRowKeysList().isEmpty() && rowSet.getRowRangesList().isEmpty()) {

‎java-bigtable/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/models/Query.java‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,13 +292,13 @@ public List<Query> shard(SortedSet<ByteString> splitPoints) {
292292
*
293293
* <pre>{@code
294294
* Query query = Query.create(...).range("a", "z");
295-
* Query.QueryPaginator paginator = query.createQueryPaginator(100);
295+
* Query.QueryPaginator paginator = query.createPaginator(100);
296296
* ByteString lastSeenRowKey = ByteString.EMPTY;
297297
* do {
298298
* List<Row> rows = client.readRowsCallable().all().call(paginator.getNextQuery());
299299
* for (Row row : rows) {
300300
* // do some processing
301-
* lastSeenRow = row;
301+
* lastSeenRowKey = row.getKey();
302302
* }
303303
* } while (paginator.advance(lastSeenRowKey));
304304
* }</pre>
@@ -440,6 +440,12 @@ public Query getNextQuery() {
440440
/**
441441
* Construct the next query. Return true if there are more queries to return. False if we've
442442
* read everything.
443+
*
444+
* @param lastSeenRowKey the key of the last row received across the pagination loop. Initialize
445+
* this to {@link ByteString#EMPTY} before the loop and update it as each row is read (see
446+
* {@link #createPaginator(int)}). If the first page is empty, {@link ByteString#EMPTY}
447+
* signals completion; if a subsequent page is empty, passing the unchanged key from the
448+
* previous page signals completion.
443449
*/
444450
public boolean advance(@Nonnull ByteString lastSeenRowKey) {
445451
Preconditions.checkNotNull(

‎java-bigtable/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/RowSetUtilTest.java‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package com.google.cloud.bigtable.data.v2.internal;
1717

1818
import static com.google.common.truth.Truth.assertThat;
19+
import static org.junit.Assert.assertThrows;
1920

2021
import com.google.bigtable.v2.RowRange;
2122
import com.google.bigtable.v2.RowSet;
@@ -344,4 +345,20 @@ public void eraseLargeRowEmptyRangeTest() {
344345
RowSet actual = RowSetUtil.eraseLargeRow(rowSet, key);
345346
assertThat(actual).isNull();
346347
}
348+
349+
@Test
350+
public void testEraseEmptyKey() {
351+
RowSet rowSet = RowSet.getDefaultInstance();
352+
assertThrows(
353+
IllegalArgumentException.class, () -> RowSetUtil.erase(rowSet, ByteString.EMPTY, true));
354+
assertThrows(
355+
IllegalArgumentException.class, () -> RowSetUtil.erase(rowSet, ByteString.EMPTY, false));
356+
}
357+
358+
@Test
359+
public void testEraseLargeRowEmptyKey() {
360+
RowSet rowSet = RowSet.getDefaultInstance();
361+
assertThrows(
362+
IllegalArgumentException.class, () -> RowSetUtil.eraseLargeRow(rowSet, ByteString.EMPTY));
363+
}
347364
}

0 commit comments

Comments
 (0)