Search in sources :

Example 1 with RowKeyWrapper

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);
    }
}
Also used : BoundType(com.google.common.collect.BoundType) RowKeyWrapper(com.google.cloud.bigtable.hbase.util.RowKeyWrapper)

Example 2 with RowKeyWrapper

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)));
    }
}
Also used : ByteString(com.google.protobuf.ByteString) RowKeyWrapper(com.google.cloud.bigtable.hbase.util.RowKeyWrapper)

Example 3 with RowKeyWrapper

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;
    }
}
Also used : ByteString(com.google.protobuf.ByteString) BoundType(com.google.common.collect.BoundType) RowSet(com.google.bigtable.v2.RowSet) RowKeyWrapper(com.google.cloud.bigtable.hbase.util.RowKeyWrapper) BigtableExtendedScan(com.google.cloud.bigtable.hbase.BigtableExtendedScan)

Example 4 with RowKeyWrapper

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);
    }
}
Also used : RowKeyWrapper(com.google.cloud.bigtable.hbase.util.RowKeyWrapper) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 5 with RowKeyWrapper

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);
        }
    }
}
Also used : ByteStringRange(com.google.cloud.bigtable.data.v2.models.Range.ByteStringRange) RowKeyWrapper(com.google.cloud.bigtable.hbase.util.RowKeyWrapper) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

RowKeyWrapper (com.google.cloud.bigtable.hbase.util.RowKeyWrapper)34 Test (org.junit.Test)28 RowSet (com.google.bigtable.v2.RowSet)14 ByteString (com.google.protobuf.ByteString)12 Filters (com.google.cloud.bigtable.data.v2.models.Filters)9 MultiRowRangeFilter (org.apache.hadoop.hbase.filter.MultiRowRangeFilter)9 RowRange (org.apache.hadoop.hbase.filter.MultiRowRangeFilter.RowRange)9 PrefixFilter (org.apache.hadoop.hbase.filter.PrefixFilter)5 FilterList (org.apache.hadoop.hbase.filter.FilterList)4 BigtableExtendedScan (com.google.cloud.bigtable.hbase.BigtableExtendedScan)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 BoundType (com.google.common.collect.BoundType)2 Filter (org.apache.hadoop.hbase.filter.Filter)2 ChainFilter (com.google.cloud.bigtable.data.v2.models.Filters.ChainFilter)1 InterleaveFilter (com.google.cloud.bigtable.data.v2.models.Filters.InterleaveFilter)1 ByteStringRange (com.google.cloud.bigtable.data.v2.models.Range.ByteStringRange)1 FilterAdapter (com.google.cloud.bigtable.hbase.adapters.filters.FilterAdapter)1 FilterAdapterContext (com.google.cloud.bigtable.hbase.adapters.filters.FilterAdapterContext)1 ImmutableRangeSet (com.google.common.collect.ImmutableRangeSet)1 RangeSet (com.google.common.collect.RangeSet)1