Search in sources :

Example 16 with ByteStringRange

use of com.google.cloud.bigtable.data.v2.models.Range.ByteStringRange in project java-bigtable by googleapis.

the class RowSetUtil method getBound.

/**
 * Get the bounding range of a {@link RowSet}.
 */
public static ByteStringRange getBound(RowSet rowSet) {
    // Find min & max keys
    ByteString minKey = null;
    ByteString maxKey = null;
    for (ByteString key : rowSet.getRowKeysList()) {
        if (minKey == null || ByteStringComparator.INSTANCE.compare(minKey, key) > 0) {
            minKey = key;
        }
        if (maxKey == null || ByteStringComparator.INSTANCE.compare(maxKey, key) < 0) {
            maxKey = key;
        }
    }
    // Convert min & max keys in start & end points for a range
    StartPoint minStartPoint = null;
    EndPoint maxEndPoint = null;
    if (minKey != null) {
        minStartPoint = new StartPoint(minKey, true);
    }
    if (maxKey != null) {
        maxEndPoint = new EndPoint(maxKey, true);
    }
    // Expand the range using the RowSet ranges
    for (RowRange rowRange : rowSet.getRowRangesList()) {
        StartPoint currentStartPoint = StartPoint.extract(rowRange);
        if (minStartPoint == null || minStartPoint.compareTo(currentStartPoint) > 0) {
            minStartPoint = currentStartPoint;
        }
        EndPoint currentEndpoint = EndPoint.extract(rowRange);
        if (maxEndPoint == null || maxEndPoint.compareTo(currentEndpoint) < 0) {
            maxEndPoint = currentEndpoint;
        }
    }
    // Build a range using the endpoints
    ByteStringRange boundingRange = ByteStringRange.unbounded();
    if (minStartPoint != null) {
        if (minStartPoint.isClosed) {
            boundingRange.startClosed(minStartPoint.value);
        } else {
            boundingRange.startOpen(minStartPoint.value);
        }
    }
    if (maxEndPoint != null) {
        if (maxEndPoint.isClosed) {
            boundingRange.endClosed(maxEndPoint.value);
        } else {
            boundingRange.endOpen(maxEndPoint.value);
        }
    }
    return boundingRange;
}
Also used : RowRange(com.google.bigtable.v2.RowRange) ByteString(com.google.protobuf.ByteString) ByteStringRange(com.google.cloud.bigtable.data.v2.models.Range.ByteStringRange)

Example 17 with ByteStringRange

use of com.google.cloud.bigtable.data.v2.models.Range.ByteStringRange in project java-bigtable by googleapis.

the class RowSetUtilTest method singleClosedOpenRangeBoundTest.

@Test
public void singleClosedOpenRangeBoundTest() {
    RowSet rowSet = RowSet.newBuilder().addRowRanges(RowRange.newBuilder().setStartKeyClosed(ByteString.copyFromUtf8("a")).setEndKeyOpen(ByteString.copyFromUtf8("b"))).build();
    ByteStringRange actual = RowSetUtil.getBound(rowSet);
    assertThat(actual).isEqualTo(ByteStringRange.unbounded().startClosed("a").endOpen("b"));
}
Also used : RowSet(com.google.bigtable.v2.RowSet) ByteStringRange(com.google.cloud.bigtable.data.v2.models.Range.ByteStringRange) Test(org.junit.Test)

Example 18 with ByteStringRange

use of com.google.cloud.bigtable.data.v2.models.Range.ByteStringRange in project java-bigtable by googleapis.

the class RowSetUtilTest method multiKeyBoundTest.

@Test
public void multiKeyBoundTest() {
    RowSet rowSet = RowSet.newBuilder().addRowKeys(ByteString.copyFromUtf8("a")).addRowKeys(ByteString.copyFromUtf8("d")).build();
    ByteStringRange actual = RowSetUtil.getBound(rowSet);
    assertThat(actual).isEqualTo(ByteStringRange.unbounded().startClosed("a").endClosed("d"));
}
Also used : RowSet(com.google.bigtable.v2.RowSet) ByteStringRange(com.google.cloud.bigtable.data.v2.models.Range.ByteStringRange) Test(org.junit.Test)

Example 19 with ByteStringRange

use of com.google.cloud.bigtable.data.v2.models.Range.ByteStringRange in project java-bigtable by googleapis.

the class RowSetUtilTest method singleOpenOpenRangeBoundTest.

@Test
public void singleOpenOpenRangeBoundTest() {
    RowSet rowSet = RowSet.newBuilder().addRowRanges(RowRange.newBuilder().setStartKeyOpen(ByteString.copyFromUtf8("a")).setEndKeyOpen(ByteString.copyFromUtf8("b"))).build();
    ByteStringRange actual = RowSetUtil.getBound(rowSet);
    assertThat(actual).isEqualTo(ByteStringRange.unbounded().startOpen("a").endOpen("b"));
}
Also used : RowSet(com.google.bigtable.v2.RowSet) ByteStringRange(com.google.cloud.bigtable.data.v2.models.Range.ByteStringRange) Test(org.junit.Test)

Example 20 with ByteStringRange

use of com.google.cloud.bigtable.data.v2.models.Range.ByteStringRange in project java-bigtable by googleapis.

the class RangeTest method byteStringEqualsTest.

@Test
public void byteStringEqualsTest() {
    ByteStringRange r1 = ByteStringRange.create("a", "c");
    ByteStringRange r2 = ByteStringRange.create("a", "c");
    ByteStringRange r3 = ByteStringRange.create("q", "z");
    assertThat(r1).isEqualTo(r2);
    assertThat(r2).isEqualTo(r1);
    assertThat(r1).isNotEqualTo(r3);
}
Also used : ByteStringRange(com.google.cloud.bigtable.data.v2.models.Range.ByteStringRange) Test(org.junit.Test)

Aggregations

ByteStringRange (com.google.cloud.bigtable.data.v2.models.Range.ByteStringRange)22 Test (org.junit.Test)20 RowSet (com.google.bigtable.v2.RowSet)10 RowRange (com.google.bigtable.v2.RowRange)1 RowKeyWrapper (com.google.cloud.bigtable.hbase.util.RowKeyWrapper)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ByteString (com.google.protobuf.ByteString)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1