Search in sources :

Example 1 with QueryIterator

use of datawave.query.iterator.QueryIterator in project datawave by NationalSecurityAgency.

the class JexlRule method accept.

/*
     * (non-Javadoc)
     * 
     * @see datawave.iterators.filter.ageoff.AppliedRule#accept(datawave.iterators.filter.ageoff.AgeOffPeriod, org.apache.accumulo.core.data.Key,
     * org.apache.accumulo.core.data.Value)
     */
@Override
public boolean accept(final SortedKeyValueIterator<Key, Value> iter) {
    // let it pass through
    if (null == iter || !iter.hasTop()) {
        isApplied = true;
        if (log.isDebugEnabled())
            log.debug("Returning false immediately as their is no top key in the source");
        return false;
    }
    if (isDocument(iter.getTopKey())) {
        isApplied = true;
        if (queryIter == null) {
            queryIter = new QueryIterator();
            try {
                queryIter.init(iter.deepCopy(environment), iterOptions, environment);
            } catch (IOException e) {
                log.debug("Failed to initialize queryIter with provided query", e);
                return false;
            }
        }
        try {
            Key topKey = iter.getTopKey();
            if (log.isDebugEnabled())
                log.debug(topKey);
            queryIter.seek(new Range(new Key(topKey.getRow(), topKey.getColumnFamily()), true, topKey.followingKey(PartialKey.ROW_COLFAM), false), Collections.emptyList(), false);
        } catch (IOException e) {
            log.error(e);
            // review
            return false;
        }
        isApplied = true;
        // amirite?
        if (queryIter.hasTop()) {
            if (log.isDebugEnabled())
                log.debug(queryIter.getTopKey());
            return true;
        } else {
            if (log.isDebugEnabled())
                log.debug("has no top ");
        }
        return false;
    } else {
        log.debug("false ");
        isApplied = false;
        return false;
    }
}
Also used : QueryIterator(datawave.query.iterator.QueryIterator) IOException(java.io.IOException) Range(org.apache.accumulo.core.data.Range) Key(org.apache.accumulo.core.data.Key) PartialKey(org.apache.accumulo.core.data.PartialKey)

Aggregations

QueryIterator (datawave.query.iterator.QueryIterator)1 IOException (java.io.IOException)1 Key (org.apache.accumulo.core.data.Key)1 PartialKey (org.apache.accumulo.core.data.PartialKey)1 Range (org.apache.accumulo.core.data.Range)1