use of com.google.cloud.bigtable.hbase.util.RowKeyWrapper in project java-bigtable-hbase by googleapis.
the class MultiRowRangeFilterAdapter method rowRangeToRange.
private Range<RowKeyWrapper> rowRangeToRange(RowRange rowRange) {
boolean startUnbounded = HConstants.EMPTY_BYTE_ARRAY.equals(rowRange.getStartRow());
RowKeyWrapper start = new RowKeyWrapper(ByteString.copyFrom(rowRange.getStartRow()));
BoundType startboundType = rowRange.isStartRowInclusive() ? BoundType.CLOSED : BoundType.OPEN;
boolean stopUnbounded = HConstants.EMPTY_BYTE_ARRAY.equals(rowRange.getStopRow());
RowKeyWrapper stop = new RowKeyWrapper(ByteString.copyFrom(rowRange.getStopRow()));
BoundType stopboundType = rowRange.isStopRowInclusive() ? BoundType.CLOSED : BoundType.OPEN;
if (startUnbounded && stopUnbounded) {
return Range.all();
} else if (startUnbounded) {
return Range.upTo(stop, stopboundType);
} else if (stopUnbounded) {
return Range.downTo(start, startboundType);
} else {
return Range.range(start, startboundType, stop, stopboundType);
}
}
use of com.google.cloud.bigtable.hbase.util.RowKeyWrapper in project java-bigtable-hbase by googleapis.
the class PrefixFilterAdapter method getIndexScanHint.
@Override
public RangeSet<RowKeyWrapper> getIndexScanHint(PrefixFilter filter) {
if (filter.getPrefix().length == 0) {
return ImmutableRangeSet.of(Range.<RowKeyWrapper>all());
} else {
ByteString start = ByteString.copyFrom(filter.getPrefix());
ByteString end = ByteString.copyFrom(RowKeyUtil.calculateTheClosestNextRowKeyForPrefix(filter.getPrefix()));
return ImmutableRangeSet.of(Range.closedOpen(new RowKeyWrapper(start), new RowKeyWrapper(end)));
}
}
use of com.google.cloud.bigtable.hbase.util.RowKeyWrapper in project java-bigtable-hbase by googleapis.
the class ScanAdapter method getRangeSet.
private RangeSet<RowKeyWrapper> getRangeSet(Scan scan) {
if (scan instanceof BigtableExtendedScan) {
RowSet rowSet = ((BigtableExtendedScan) scan).getRowSet();
return rowRangeAdapter.rowSetToRangeSet(rowSet);
} else {
RangeSet<RowKeyWrapper> rangeSet = TreeRangeSet.create();
final ByteString startRow = ByteString.copyFrom(scan.getStartRow());
final ByteString stopRow = ByteString.copyFrom(scan.getStopRow());
if (scan.isGetScan()) {
rangeSet.add(Range.singleton(new RowKeyWrapper(startRow)));
} else {
final BoundType startBound = (!OPEN_CLOSED_AVAILABLE || scan.includeStartRow()) ? BoundType.CLOSED : BoundType.OPEN;
final BoundType endBound = (!OPEN_CLOSED_AVAILABLE || !scan.includeStopRow()) ? BoundType.OPEN : BoundType.CLOSED;
rangeSet.add(rowRangeAdapter.boundedRange(startBound, startRow, endBound, stopRow));
}
return rangeSet;
}
}
use of com.google.cloud.bigtable.hbase.util.RowKeyWrapper in project java-bigtable-hbase by googleapis.
the class RowRangeAdapter method boundedRange.
/**
* To determine {@link Range<RowKeyWrapper>} based start/end key & {@link BoundType}.
*/
@VisibleForTesting
Range<RowKeyWrapper> boundedRange(BoundType startBound, ByteString startKey, BoundType endBound, ByteString endKey) {
// Bigtable doesn't allow empty row keys, so an empty start row which is open or closed is
// considered unbounded. ie. all row keys are bigger than the empty key (no need to
// differentiate between open/closed)
final boolean startUnbounded = startKey.isEmpty();
// Bigtable doesn't allow empty row keys, so an empty end row which is open or closed is
// considered unbounded. ie. all row keys are smaller than the empty end key (no need to
// differentiate between open/closed)
final boolean endUnbounded = endKey.isEmpty();
if (startUnbounded && endUnbounded) {
return Range.all();
} else if (startUnbounded) {
return Range.upTo(new RowKeyWrapper(endKey), endBound);
} else if (endUnbounded) {
return Range.downTo(new RowKeyWrapper(startKey), startBound);
} else {
return Range.range(new RowKeyWrapper(startKey), startBound, new RowKeyWrapper(endKey), endBound);
}
}
use of com.google.cloud.bigtable.hbase.util.RowKeyWrapper in project java-bigtable-hbase by googleapis.
the class RowRangeAdapter method rangeSetToByteStringRange.
/**
* Convert guava's {@link RangeSet} to Bigtable's {@link ByteStringRange}. Please note that this
* will convert boundless ranges into unset key cases.
*/
@VisibleForTesting
void rangeSetToByteStringRange(RangeSet<RowKeyWrapper> guavaRangeSet, Query query) {
for (Range<RowKeyWrapper> guavaRange : guavaRangeSet.asRanges()) {
// Is it a point?
if (guavaRange.hasLowerBound() && guavaRange.lowerBoundType() == BoundType.CLOSED && guavaRange.hasUpperBound() && guavaRange.upperBoundType() == BoundType.CLOSED && guavaRange.lowerEndpoint().equals(guavaRange.upperEndpoint())) {
query.rowKey(guavaRange.lowerEndpoint().getKey());
} else {
ByteStringRange byteRange = ByteStringRange.unbounded();
// Handle start key
if (guavaRange.hasLowerBound()) {
switch(guavaRange.lowerBoundType()) {
case CLOSED:
byteRange.startClosed(guavaRange.lowerEndpoint().getKey());
break;
case OPEN:
byteRange.startOpen(guavaRange.lowerEndpoint().getKey());
break;
default:
throw new IllegalArgumentException("Unexpected lower bound type: " + guavaRange.lowerBoundType());
}
}
// handle end key
if (guavaRange.hasUpperBound()) {
switch(guavaRange.upperBoundType()) {
case CLOSED:
byteRange.endClosed(guavaRange.upperEndpoint().getKey());
break;
case OPEN:
byteRange.endOpen(guavaRange.upperEndpoint().getKey());
break;
default:
throw new IllegalArgumentException("Unexpected upper bound type: " + guavaRange.upperBoundType());
}
}
query.range(byteRange);
}
}
}
Aggregations