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

The following examples show how to use org.apache.accumulo.core.data.Range#isEndKeyInclusive() . 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: FirstEntryInPrefixedRowIterator.java    From accumulo-recipes with Apache License 2.0 6 votes vote down vote up
@Override
public void seek(Range range, Collection<ByteSequence> columnFamilies, boolean inclusive) throws IOException {
    // save parameters for future internal seeks
    latestRange = range;
    latestColumnFamilies = columnFamilies;
    latestInclusive = inclusive;
    lastRowFound = null;

    Key startKey = range.getStartKey();
    Range seekRange = new Range(startKey == null ? null : new Key(startKey.getRow(), startKey.getColumnFamily()), true, range.getEndKey(), range.isEndKeyInclusive());
    super.seek(seekRange, columnFamilies, inclusive);
    finished = false;

    if (getSource().hasTop()) {
        lastRowFound = getSource().getTopKey().getRow();
        if (range.beforeStartKey(getSource().getTopKey()))
            consume();
    }
}
 
Example 2
Source File: FirstNEntriesInRowIterator.java    From accumulo-recipes with Apache License 2.0 6 votes vote down vote up
@Override
public void seek(Range range, Collection<ByteSequence> columnFamilies, boolean inclusive) throws IOException {
    // save parameters for future internal seeks
    latestRange = range;
    latestColumnFamilies = columnFamilies;
    latestInclusive = inclusive;
    lastRowFound = null;

    Key startKey = range.getStartKey();
    Range seekRange = new Range(startKey == null ? null : new Key(startKey.getRow()), true, range.getEndKey(), range.isEndKeyInclusive());
    getSource().seek(seekRange, columnFamilies, inclusive);
    finished = false;

    if (getSource().hasTop()) {
        lastRowFound = getSource().getTopKey().getRow();
        if (hasSeeked && range.beforeStartKey(getSource().getTopKey()))
            skipRow();
    }

    hasSeeked = true;

    prepKeys();
}
 
Example 3
Source File: SeekingAggregator.java    From datawave with Apache License 2.0 6 votes vote down vote up
/**
 * Advance an iterator until skip(...) returns false. May be a combination of seek() and next() calls
 * 
 * @param itr
 * @param pointer
 * @param currentRange
 * @param columnFamilies
 * @param includeColumnFamilies
 * @throws IOException
 */
protected void advanceItr(SortedKeyValueIterator<Key,Value> itr, ByteSequence pointer, Range currentRange, Collection<ByteSequence> columnFamilies,
                boolean includeColumnFamilies) throws IOException {
    Key current = itr.getTopKey();
    Text row = current.getRow();
    int nextCount = 0;
    while (current != null && skip(current, row, pointer)) {
        if (maxNextCount == -1 || nextCount < maxNextCount) {
            itr.next();
            nextCount++;
        } else {
            Key startKey = getSeekStartKey(current, pointer);
            Range newRange = new Range(startKey, false, currentRange.getEndKey(), currentRange.isEndKeyInclusive());
            itr.seek(newRange, columnFamilies, includeColumnFamilies);
            nextCount = 0;
        }
        
        current = itr.hasTop() ? itr.getTopKey() : null;
    }
}
 
Example 4
Source File: MatchingKeySkippingIterator.java    From datawave with Apache License 2.0 6 votes vote down vote up
@Override
public void seek(Range range, Collection<ByteSequence> columnFamilies, boolean inclusive) throws IOException {
    // save parameters for future internal seeks
    latestRange = range;
    latestColumnFamilies = columnFamilies;
    latestInclusive = inclusive;
    lastKeyFound = null;
    
    Key startKey = range.getStartKey();
    Range seekRange = new Range(startKey == null ? null : new Key(startKey.getRow()), true, range.getEndKey(), range.isEndKeyInclusive());
    super.seek(seekRange, columnFamilies, inclusive);
    finished = false;
    
    if (getSource().hasTop()) {
        lastKeyFound = getSource().getTopKey();
        if (range.beforeStartKey(getSource().getTopKey()))
            consume();
    }
}
 
Example 5
Source File: ShardKeyFunctor.java    From datawave with Apache License 2.0 5 votes vote down vote up
/**
 * Determine whether this range should be considered by the bloom filter.
 * 
 * @param range
 * @return true if it is to be considered, false otherwise
 */
static boolean isRangeInBloomFilter(Range range) {
    
    /**
     * If the range has no start key or no end key, then ignore the bloom filters
     */
    if (range.getStartKey() == null || range.getEndKey() == null) {
        return false;
    }
    
    /**
     * If this key is not in the bloom filter, then ignore the bloom filters
     */
    if (!isKeyInBloomFilter(range.getStartKey())) {
        return false;
    }
    
    /**
     * If the start key and the end key are equal up to the depth being considered, then we should consider the bloom filter.
     */
    if (range.getStartKey().equals(range.getEndKey(), PartialKey.ROW_COLFAM_COLQUAL))
        return true;
    
    /**
     * If the end key is precisely the key immediately after the start key including everything up to the deleted flag, then we should consider the bloom
     * filter.
     */
    return range.getStartKey().followingKey(PartialKey.ROW_COLFAM_COLQUAL).equals(range.getEndKey(), PartialKey.ROW_COLFAM_COLQUAL_COLVIS_TIME)
                    && !range.isEndKeyInclusive();
}
 
Example 6
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 7
Source File: RecordIterator.java    From datawave with Apache License 2.0 5 votes vote down vote up
/**
 * @throws IOException
 * 
 */
private void seekLastSeen() throws IOException {
    
    try {
        if (lastSeenKey != null) {
            currentRange = new Range(lastSeenKey, false, currentRange.getEndKey(), currentRange.isEndKeyInclusive());
        }
    } catch (Exception e) {
        log.error(e);
    }
    
    globalIter.seek(currentRange, Collections.emptyList(), false);
}
 
Example 8
Source File: IndexIterator.java    From datawave with Apache License 2.0 5 votes vote down vote up
/**
 * Permute a "Document" Range to the equivalent "Field Index" Range for a Field:Term
 * 
 * @param r
 * @return
 */
protected Range buildIndexRange(Range r) {
    Key startKey = permuteRangeKey(r.getStartKey(), r.isStartKeyInclusive());
    Key endKey = permuteRangeKey(r.getEndKey(), r.isEndKeyInclusive());
    
    return new Range(startKey, r.isStartKeyInclusive(), endKey, r.isEndKeyInclusive());
}
 
Example 9
Source File: CreateUidsIterator.java    From datawave with Apache License 2.0 5 votes vote down vote up
/**
 * Method that ensures if we have to skip the current key, we do so with the contract provided by the create UID iterator.
 * 
 * @param range
 */
protected Range skipKey(Range range) {
    Key startKey = range.getStartKey();
    Key newKey = new Key(startKey.getRow(), startKey.getColumnFamily(), new Text(startKey.getColumnQualifier() + "\u0000\uffff"));
    return new Range(newKey, true, range.getEndKey(), range.isEndKeyInclusive());
    
}
 
Example 10
Source File: ShardIndexKeyFunctor.java    From datawave with Apache License 2.0 5 votes vote down vote up
/**
 * Determine whether this range should be considered by the bloom filter.
 * 
 * @param range
 * @return true if it is to be considered, false otherwise
 */
static boolean isRangeInBloomFilter(Range range) {
    
    /**
     * If the range has no start key or no end key, then ignore the bloom filters
     */
    if (range.getStartKey() == null || range.getEndKey() == null) {
        return false;
    }
    
    /**
     * If this key is not in the bloom filter, then ignore the bloom filters
     */
    if (!isKeyInBloomFilter(range.getStartKey())) {
        return false;
    }
    
    /**
     * If the start key and the end key are equal up to the depth being considered, then we should consider the bloom filter.
     */
    if (range.getStartKey().equals(range.getEndKey(), PartialKey.ROW_COLFAM))
        return true;
    
    /**
     * If the end key is precisely the key immediately after the start key including everything up to the deleted flag, then we should consider the bloom
     * filter.
     */
    return range.getStartKey().followingKey(PartialKey.ROW_COLFAM).equals(range.getEndKey(), PartialKey.ROW_COLFAM_COLQUAL_COLVIS_TIME)
                    && !range.isEndKeyInclusive();
}
 
Example 11
Source File: CreateUidsIteratorTest.java    From datawave with Apache License 2.0 4 votes vote down vote up
/**
 * Ensure that for a known set of data the iterator will correctly seek to each next value.
 *
 * @throws IOException
 */
@Test
public void testReseek() throws IOException {
    // Setup data for test.
    TreeMap<Key,Value> data = new TreeMap<>();
    List<String> docIds = Arrays.asList("doc1", "doc2", "doc3", "doc4");
    Uid.List.Builder builder = Uid.List.newBuilder();
    builder.addAllUID(docIds);
    builder.setCOUNT(docIds.size());
    builder.setIGNORE(false);
    Value hasDocs = new Value(builder.build().toByteArray());
    
    List<String> expectedDocs = new LinkedList<>();
    for (int ii = 1; ii < 50; ii++) {
        expectedDocs.add("date_" + ii);
        data.put(new Key("row", "cf", "date_" + ii + "\u0000A"), hasDocs);
    }
    data.put(new Key("row", "cf", "date_2\u0000B"), hasDocs);
    
    // Setup iterator.
    CreateUidsIterator iterator = new CreateUidsIterator();
    iterator.init(new SortedMapIterator(data), null, null);
    
    Key startKey = new Key("row", "cf", "date_0");
    Key endKey = new Key("row", "cf", "date_\uffff");
    Range range = new Range(startKey, true, endKey, false);
    
    iterator.seek(range, Collections.emptySet(), false);
    assertTrue(iterator.hasTop());
    
    IndexInfo indexInfo = new IndexInfo();
    indexInfo.readFields(new DataInputStream(new ByteArrayInputStream(iterator.getTopValue().get())));
    assertTrue(iterator.getTopKey().getColumnQualifier().toString().startsWith("date_1"));
    
    Key topKey = iterator.getTopKey();
    String id = topKey.getColumnQualifier().toString();
    expectedDocs.remove(id);
    for (int ii = 2; ii <= 49; ii++) {
        Range seekRange = new Range(iterator.getTopKey(), false, range.getEndKey(), range.isEndKeyInclusive());
        iterator.seek(seekRange, Collections.emptySet(), false);
        if (iterator.hasTop()) {
            topKey = iterator.getTopKey();
            id = topKey.getColumnQualifier().toString();
            expectedDocs.remove(id);
        }
    }
    assertEquals("Items remaining " + expectedDocs, 0, expectedDocs.size());
}
 
Example 12
Source File: TermFrequencyIndexIterator.java    From datawave with Apache License 2.0 4 votes vote down vote up
public TermFrequencyIndexIterator(Range fiRange, SortedKeyValueIterator<Key,Value> source, TimeFilter timeFilter, TypeMetadata typeMetadata,
                boolean buildDocument, Predicate<Key> datatypeFilter, FieldIndexAggregator aggregator) {
    this(fiRange.getStartKey(), fiRange.isStartKeyInclusive(), fiRange.getEndKey(), fiRange.isEndKeyInclusive(), source, timeFilter, typeMetadata,
                    buildDocument, datatypeFilter, aggregator);
}
 
Example 13
Source File: AccumuloSplitsProvider.java    From geowave with Apache License 2.0 4 votes vote down vote up
public static GeoWaveRowRange fromAccumuloRange(final Range range, final int partitionKeyLength) {
  if (partitionKeyLength <= 0) {
    return new GeoWaveRowRange(
        null,
        range.getStartKey() == null ? null : range.getStartKey().getRowData().getBackingArray(),
        range.getEndKey() == null ? null : range.getEndKey().getRowData().getBackingArray(),
        range.isStartKeyInclusive(),
        range.isEndKeyInclusive());
  } else {
    byte[] partitionKey;
    boolean partitionKeyDiffers = false;
    if ((range.getStartKey() == null) && (range.getEndKey() == null)) {
      return null;
    } else if (range.getStartKey() != null) {
      partitionKey =
          ArrayUtils.subarray(
              range.getStartKey().getRowData().getBackingArray(),
              0,
              partitionKeyLength);
      if (range.getEndKey() != null) {
        partitionKeyDiffers =
            !Arrays.equals(
                partitionKey,
                ArrayUtils.subarray(
                    range.getEndKey().getRowData().getBackingArray(),
                    0,
                    partitionKeyLength));
      }
    } else {
      partitionKey =
          ArrayUtils.subarray(
              range.getEndKey().getRowData().getBackingArray(),
              0,
              partitionKeyLength);
    }
    return new GeoWaveRowRange(
        partitionKey,
        range.getStartKey() == null ? null
            : ArrayUtils.subarray(
                range.getStartKey().getRowData().getBackingArray(),
                partitionKeyLength,
                range.getStartKey().getRowData().getBackingArray().length),
        partitionKeyDiffers ? null
            : range.getEndKey() == null ? null
                : ArrayUtils.subarray(
                    range.getEndKey().getRowData().getBackingArray(),
                    partitionKeyLength,
                    range.getEndKey().getRowData().getBackingArray().length),
        range.isStartKeyInclusive(),
        partitionKeyDiffers ? true : range.isEndKeyInclusive());
  }
}
 
Example 14
Source File: RangeStreamScanner.java    From datawave with Apache License 2.0 3 votes vote down vote up
/**
 * Override this for your specific implementation.
 * 
 * In this specific implementation our row key will be the term, the column family will be the field name, and the column family will be the shard,so we
 * should have the following as our last key
 * 
 * bar FOO:20130101_0
 * 
 * so we should append a null so that we we don't skip shards. similarly, an assumption is made of the key structure within this class.
 * 
 * @param lastKey
 * @param previousRange
 */
@Override
public Range buildNextRange(final Key lastKey, final Range previousRange) {
    
    /*
     * This path includes the following key from the shard_id onward. The reason we also append the hex 255 value is because we receive a key not unlike
     * foo:20130101_0. If our next search space is foo:20130101_0\x00 we will hit all data types within that range...again..and again...and again. To
     * account for this, we put \uffff after the null byte so that we start key is technically the last value within the provided shard, moving us to the
     * exact next key within our RangeStream
     */
    return new Range(new Key(lastKey.getRow(), lastKey.getColumnFamily(), new Text(lastKey.getColumnQualifier() + "\uffff")), true,
                    previousRange.getEndKey(), previousRange.isEndKeyInclusive());
}
 
Example 15
Source File: AnyFieldScanner.java    From datawave with Apache License 2.0 3 votes vote down vote up
/**
 * Override this for your specific implementation.
 * 
 * In this specific implementation our row key will be the term, the column family will be the field name, and the column family will be the shard,so we
 * should have the following as our last key
 * 
 * bar FOO:20130101_0
 * 
 * so we should append a null so that we we don't skip shards. similarly, an assumption is made of the key structure within this class.
 * 
 * @param lastKey
 * @param previousRange
 */
public Range buildNextRange(final Key lastKey, final Range previousRange) {
    
    /**
     * This will re-seek the next column family when performing any field expansion.
     */
    Range r = new Range(new Key(lastKey.getRow(), new Text(lastKey.getColumnFamily() + "\u0000\uffff")), true, previousRange.getEndKey(),
                    previousRange.isEndKeyInclusive());
    if (log.isTraceEnabled())
        log.trace(r);
    return r;
    
}
 
Example 16
Source File: BatchScannerSession.java    From datawave with Apache License 2.0 2 votes vote down vote up
/**
 * Override this for your specific implementation.
 * 
 * @param lastKey
 * @param previousRange
 */
public Range buildNextRange(final Key lastKey, final Range previousRange) {
    return new Range(lastKey.followingKey(PartialKey.ROW_COLFAM_COLQUAL_COLVIS_TIME), true, previousRange.getEndKey(), previousRange.isEndKeyInclusive());
}
 
Example 17
Source File: ScannerSession.java    From datawave with Apache License 2.0 2 votes vote down vote up
/**
 * Override this for your specific implementation.
 * 
 * @param lastKey
 * @param previousRange
 */
public Range buildNextRange(final Key lastKey, final Range previousRange) {
    return new Range(lastKey.followingKey(PartialKey.ROW_COLFAM_COLQUAL_COLVIS_TIME), true, previousRange.getEndKey(), previousRange.isEndKeyInclusive());
}
 
Example 18
Source File: Scan.java    From datawave with Apache License 2.0 2 votes vote down vote up
/**
 * Override this for your specific implementation.
 * 
 * @param lastKey
 * @param previousRange
 */
public Range buildNextRange(final Key lastKey, final Range previousRange) {
    return new Range(lastKey.followingKey(PartialKey.ROW_COLFAM_COLQUAL_COLVIS_TIME), true, previousRange.getEndKey(), previousRange.isEndKeyInclusive());
}
 
Example 19
Source File: SpanUtil.java    From fluo with Apache License 2.0 2 votes vote down vote up
/**
 * Converts an Accumulo Range to a Fluo Span
 * 
 * @param range Range
 * @return Span
 */
public static Span toSpan(Range range) {
  return new Span(toRowColumn(range.getStartKey()), range.isStartKeyInclusive(),
      toRowColumn(range.getEndKey()), range.isEndKeyInclusive());
}