Search in sources :

Example 1 with KeyParts

use of org.apache.rya.indexing.KeyParts in project incubator-rya by apache.

the class AccumuloTemporalIndexer method queryInstantInsideInterval.

/**
 * Get instances inside a given interval.
 * Returns after interval's beginning time, and before ending time,
 * exclusive (don't match the beginning and ending).
 */
@Override
public CloseableIteration<Statement, QueryEvaluationException> queryInstantInsideInterval(final TemporalInterval queryInterval, final StatementConstraints constraints) throws QueryEvaluationException {
    // get rows where the time is after the given interval's beginning time and before the ending time.
    final TemporalInterval theQueryInterval = queryInterval;
    final Query query = new Query() {

        private final TemporalInterval queryInterval = theQueryInterval;

        @Override
        public Range getRange(final KeyParts keyParts) {
            final Text start = Range.followingPrefix(new Text(keyParts.getQueryKey(queryInterval.getHasBeginning())));
            // <-- end specific logic
            final Text endAt = new Text(keyParts.getQueryKey(queryInterval.getHasEnd()));
            // System.out.println("Scanning queryInstantInsideInterval: from excluding:" + KeyParts.toHumanString(start) + " up to:" + KeyParts.toHumanString(endAt));
            return new Range(start, false, endAt, false);
        }
    };
    final ScannerBase scanner = query.doQuery(queryInterval.getHasBeginning(), constraints);
    return getContextIteratorWrapper(scanner, constraints.getContext());
}
Also used : ScannerBase(org.apache.accumulo.core.client.ScannerBase) Text(org.apache.hadoop.io.Text) KeyParts(org.apache.rya.indexing.KeyParts) Range(org.apache.accumulo.core.data.Range) TemporalInterval(org.apache.rya.indexing.TemporalInterval)

Example 2 with KeyParts

use of org.apache.rya.indexing.KeyParts in project incubator-rya by apache.

the class AccumuloTemporalIndexer method queryInstantAfterInstant.

/**
 * get statements where the date object is after the given queryInstant.
 */
@Override
public CloseableIteration<Statement, QueryEvaluationException> queryInstantAfterInstant(final TemporalInstant queryInstant, final StatementConstraints constraints) throws QueryEvaluationException {
    final Query query = new Query() {

        @Override
        public Range getRange(final KeyParts keyParts) {
            // <-- specific logic
            final Text start = Range.followingPrefix(keyParts.getQueryKey());
            // no constraints                            // <-- specific logic
            Text endAt = null;
            if (keyParts.constraintPrefix != null) {
                endAt = Range.followingPrefix(keyParts.constraintPrefix);
            }
            // System.out.println("Scanning queryInstantAfterInstant from after:" + KeyParts.toHumanString(start) + " up to:" + KeyParts.toHumanString(endAt));
            return new Range(start, true, endAt, false);
        }
    };
    final ScannerBase scanner = query.doQuery(queryInstant, constraints);
    return getContextIteratorWrapper(scanner, constraints.getContext());
}
Also used : ScannerBase(org.apache.accumulo.core.client.ScannerBase) Text(org.apache.hadoop.io.Text) KeyParts(org.apache.rya.indexing.KeyParts) Range(org.apache.accumulo.core.data.Range)

Example 3 with KeyParts

use of org.apache.rya.indexing.KeyParts in project incubator-rya by apache.

the class AccumuloTemporalIndexer method addInstant.

/**
 * Index a new instant
 * Make indexes that handle this expression:
 *     hash( s? p? ) ?o
 *         == o union hash(s)o union hash(p)o  union hash(sp)o
 *
 * @param writer
 * @param cv
 * @param instant
 * @throws MutationsRejectedException
 */
public void addInstant(final BatchWriter writer, final TemporalInstant instant, final Statement statement) throws MutationsRejectedException {
    final KeyParts keyParts = new KeyParts(statement, instant);
    for (final KeyParts k : keyParts) {
        final Mutation m = new Mutation(k.getStoreKey());
        m.put(k.cf, k.cq, k.getValue());
        writer.addMutation(m);
    }
}
Also used : Mutation(org.apache.accumulo.core.data.Mutation) KeyParts(org.apache.rya.indexing.KeyParts)

Example 4 with KeyParts

use of org.apache.rya.indexing.KeyParts in project incubator-rya by apache.

the class AccumuloTemporalIndexer method queryInstantEqualsInstant.

/**
 * statements where the datetime is exactly the same as the queryInstant.
 */
@Override
public CloseableIteration<Statement, QueryEvaluationException> queryInstantEqualsInstant(final TemporalInstant queryInstant, final StatementConstraints constraints) throws QueryEvaluationException {
    // get rows where the repository time is equal to the given time in queryInstant.
    final Query query = new Query() {

        @Override
        public Range getRange(final KeyParts keyParts) {
            // <-- specific logic
            return Range.prefix(keyParts.getQueryKey());
        }
    };
    final ScannerBase scanner = query.doQuery(queryInstant, constraints);
    // TODO currently context constraints are filtered on the client.
    return getContextIteratorWrapper(scanner, constraints.getContext());
}
Also used : ScannerBase(org.apache.accumulo.core.client.ScannerBase) KeyParts(org.apache.rya.indexing.KeyParts)

Example 5 with KeyParts

use of org.apache.rya.indexing.KeyParts in project incubator-rya by apache.

the class AccumuloTemporalIndexer method removeInstant.

/**
 * Remove an interval instant
 *
 * @param writer
 * @param cv
 * @param instant
 * @throws MutationsRejectedException
 */
public void removeInstant(final BatchWriter writer, final TemporalInstant instant, final Statement statement) throws MutationsRejectedException {
    final KeyParts keyParts = new KeyParts(statement, instant);
    for (final KeyParts k : keyParts) {
        final Mutation m = new Mutation(k.getStoreKey());
        m.putDelete(k.cf, k.cq);
        writer.addMutation(m);
    }
}
Also used : Mutation(org.apache.accumulo.core.data.Mutation) KeyParts(org.apache.rya.indexing.KeyParts)

Aggregations

KeyParts (org.apache.rya.indexing.KeyParts)6 ScannerBase (org.apache.accumulo.core.client.ScannerBase)4 Range (org.apache.accumulo.core.data.Range)3 Text (org.apache.hadoop.io.Text)3 Mutation (org.apache.accumulo.core.data.Mutation)2 TemporalInterval (org.apache.rya.indexing.TemporalInterval)1