Skip to content
This repository was archived by the owner on May 8, 2026. It is now read-only.

Commit f843a8f

Browse files
committed
edge cases
1 parent d53d43e commit f843a8f

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,17 @@ private static List<RowRange> splitOnLargeRowKey(RowRange range, ByteString larg
184184
// if the end key is on the right of the large row key, set the start key to be large row key
185185
// open. Empty end key is unbounded so it's always on the right of the large key
186186
if (endKey.isEmpty() || ByteStringComparator.INSTANCE.compare(endKey, largeRowKey) > 0) {
187-
RowRange afterSplit = range.toBuilder().setStartKeyOpen(largeRowKey).build();
188-
rowRanges.add(afterSplit);
187+
// handle the edge case where (key, key\0) is an empty range and should be excluded
188+
ByteString nextKey = largeRowKey.concat(ByteString.copyFrom(new byte[] {0}));
189+
EndPoint endPoint = EndPoint.extract(range);
190+
boolean isEmptyRange = !endPoint.isClosed && endPoint.value.equals(nextKey);
191+
192+
if (!isEmptyRange) {
193+
RowRange afterSplit = range.toBuilder().setStartKeyOpen(largeRowKey).build();
194+
rowRanges.add(afterSplit);
195+
}
189196
}
197+
190198
return rowRanges;
191199
}
192200

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,20 @@ public void multipleRangeBoundTest() {
331331
assertThat(actual).isEqualTo(ByteStringRange.create("a", "z"));
332332
}
333333

334+
@Test
335+
public void eraseLargeRowEmptyRangeTest() {
336+
ByteString key = ByteString.copyFromUtf8("a");
337+
ByteString keyTrailer = key.concat(ByteString.copyFrom(new byte[] {0}));
338+
339+
RowSet rowSet =
340+
RowSet.newBuilder()
341+
.addRowRanges(
342+
RowRange.newBuilder().setStartKeyClosed(key).setEndKeyOpen(keyTrailer).build())
343+
.build();
344+
RowSet actual = RowSetUtil.eraseLargeRow(rowSet, key);
345+
assertThat(actual).isNull();
346+
}
347+
334348
// Helpers
335349
private static void verifyShard(RowSet input, SortedSet<ByteString> splits, RowSet... expected) {
336350
List<RowSet> actualWithNull = RowSetUtil.shard(input, splits);

0 commit comments

Comments
 (0)