Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ private RowSetUtil() {}

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

RowSet.Builder newRowSet = RowSet.newBuilder();

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

if (rowSet.getRowKeysList().isEmpty() && rowSet.getRowRangesList().isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,13 +292,13 @@ public List<Query> shard(SortedSet<ByteString> splitPoints) {
*
* <pre>{@code
* Query query = Query.create(...).range("a", "z");
* Query.QueryPaginator paginator = query.createQueryPaginator(100);
* Query.QueryPaginator paginator = query.createPaginator(100);
* ByteString lastSeenRowKey = ByteString.EMPTY;
* do {
* List<Row> rows = client.readRowsCallable().all().call(paginator.getNextQuery());
* for (Row row : rows) {
* // do some processing
* lastSeenRow = row;
* lastSeenRowKey = row.getKey();
* }
* } while (paginator.advance(lastSeenRowKey));
* }</pre>
Expand Down Expand Up @@ -440,6 +440,12 @@ public Query getNextQuery() {
/**
* Construct the next query. Return true if there are more queries to return. False if we've
* read everything.
*
* @param lastSeenRowKey the key of the last row received across the pagination loop. Initialize
* this to {@link ByteString#EMPTY} before the loop and update it as each row is read (see
* {@link #createPaginator(int)}). If the first page is empty, {@link ByteString#EMPTY}
* signals completion; if a subsequent page is empty, passing the unchanged key from the
* previous page signals completion.
*/
public boolean advance(@Nonnull ByteString lastSeenRowKey) {
Preconditions.checkNotNull(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.google.cloud.bigtable.data.v2.internal;

import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertThrows;

import com.google.bigtable.v2.RowRange;
import com.google.bigtable.v2.RowSet;
Expand Down Expand Up @@ -344,4 +345,20 @@ public void eraseLargeRowEmptyRangeTest() {
RowSet actual = RowSetUtil.eraseLargeRow(rowSet, key);
assertThat(actual).isNull();
}

@Test
public void testEraseEmptyKey() {
RowSet rowSet = RowSet.getDefaultInstance();
assertThrows(
IllegalArgumentException.class, () -> RowSetUtil.erase(rowSet, ByteString.EMPTY, true));
assertThrows(
IllegalArgumentException.class, () -> RowSetUtil.erase(rowSet, ByteString.EMPTY, false));
}

@Test
public void testEraseLargeRowEmptyKey() {
RowSet rowSet = RowSet.getDefaultInstance();
assertThrows(
IllegalArgumentException.class, () -> RowSetUtil.eraseLargeRow(rowSet, ByteString.EMPTY));
}
}
Loading