Java Code Examples for org.apache.accumulo.core.data.Range#isInfiniteStartKey()

The following examples show how to use org.apache.accumulo.core.data.Range#isInfiniteStartKey() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RangeSplit.java    From datawave with Apache License 2.0 6 votes vote down vote up
/**
 * This implementation of length is only an estimate, it does not provide exact values. Do not have your code rely on this return value.
 */
public long getLength() throws IOException {
    Range firstRange = ranges.first();
    Range listRange = ranges.last();
    Text startRow = firstRange.isInfiniteStartKey() ? new Text(new byte[] {Byte.MIN_VALUE}) : firstRange.getStartKey().getRow();
    Text stopRow = listRange.isInfiniteStopKey() ? new Text(new byte[] {Byte.MAX_VALUE}) : listRange.getEndKey().getRow();
    int maxCommon = Math.min(7, Math.min(startRow.getLength(), stopRow.getLength()));
    long diff = 0;
    
    byte[] start = startRow.getBytes();
    byte[] stop = stopRow.getBytes();
    for (int i = 0; i < maxCommon; ++i) {
        diff |= 0xff & (start[i] ^ stop[i]);
        diff <<= Byte.SIZE;
    }
    
    if (startRow.getLength() != stopRow.getLength())
        diff |= 0xff;
    
    return diff + 1;
}
 
Example 2
Source File: QueryIterator.java    From datawave with Apache License 2.0 5 votes vote down vote up
/**
 * Determines if a range is document specific according to the following criteria
 * 
 * <pre>
 *     1. Cannot have a null start or end key
 *     2. Cannot span multiple rows
 *     3. ColumnFamily must contain a null byte separator
 * </pre>
 *
 * @param r
 *            - {@link Range} to be evaluated
 * @return - true if this is a document specific range, false if not.
 */
public static boolean isDocumentSpecificRange(Range r) {
    Preconditions.checkNotNull(r);
    
    // Also @see datawave.query.index.lookup.TupleToRange
    // We have already made the assertion that the client is sending us
    // an inclusive start key due to the inability to ascertain the
    // difference between and event-specific range and a continueMultiScan.
    //
    // As such, it is acceptable for us to make the same assertion on the
    // inclusivity of the start key.
    
    // Cannot have a null start or end key
    if (r.isInfiniteStartKey() || r.isInfiniteStopKey()) {
        return false;
    }
    
    // Cannot span multiple rows.
    Key startKey = r.getStartKey();
    Key endKey = r.getEndKey();
    if (!startKey.getRowData().equals(endKey.getRowData())) {
        return false;
    }
    
    // Column Family must contain a null byte separator.
    Text startCF = startKey.getColumnFamily();
    Text endCF = endKey.getColumnFamily();
    if (startCF.find(Constants.NULL) == -1 || endCF.find(Constants.NULL) == -1) {
        return false;
    }
    return true;
}
 
Example 3
Source File: EventDataScanNestedIterator.java    From datawave with Apache License 2.0 5 votes vote down vote up
@Override
public void seek(Range range, Collection<ByteSequence> columnFamilies, boolean inclusive) throws IOException {
    this.totalRange = range;
    this.columnFamilies = columnFamilies;
    this.inclusive = inclusive;
    
    // determine if we have been torn down and rebuilt
    if (!range.isInfiniteStartKey() && !range.isStartKeyInclusive()) {
        move(nextStartKey(range.getStartKey()));
    } else {
        source.seek(range, columnFamilies, inclusive);
        findNextDocument();
    }
}
 
Example 4
Source File: AccumuloQueryRuleset.java    From rya with Apache License 2.0 5 votes vote down vote up
private static boolean rangeContainsRange(final Range r1, final Range r2) {
    // 1. If r1.start is infinite, r1 contains r2.start
    if (!r1.isInfiniteStartKey()) {
        // 2. Otherwise, if r2.start is infinite, r1 can't contain r2
        if (r2.isInfiniteStartKey()) {
            return false;
        }
        final Key start2 = r2.getStartKey();
        // 3. If r2 is inclusive, r1 needs to contain r2's start key.
        if (r2.isStartKeyInclusive()) {
            if (!r1.contains(start2)) {
                return false;
            }
        }
        // 4. Otherwise, the only failure is if r2's start key comes first (they can be equal)
        else if (start2.compareTo(r1.getStartKey()) < 0) {
            return false;
        }
    }
    // Similar logic for end points
    if (!r1.isInfiniteStopKey()) {
        if (r2.isInfiniteStopKey()) {
            return false;
        }
        final Key end2 = r2.getEndKey();
        if (r2.isEndKeyInclusive()) {
            if (!r1.contains(end2)) {
                return false;
            }
        }
        else if (end2.compareTo(r1.getEndKey()) > 0) {
            return false;
        }
    }
    return true;
}
 
Example 5
Source File: ColumnCardinalityCache.java    From presto with Apache License 2.0 4 votes vote down vote up
private static boolean isExact(Range range)
{
    return !range.isInfiniteStartKey() && !range.isInfiniteStopKey() &&
            range.getStartKey().followingKey(PartialKey.ROW).equals(range.getEndKey());
}