Search in sources :

Example 21 with ByteRange

use of org.apache.rya.api.query.strategy.ByteRange in project incubator-rya by apache.

the class SpoWholeRowTriplePatternStrategy method defineRange.

@Override
public Map.Entry<TABLE_LAYOUT, ByteRange> defineRange(final RyaURI subject, final RyaURI predicate, final RyaType object, final RyaURI context, final RdfCloudTripleStoreConfiguration conf) throws IOException {
    try {
        // s_r(p)(ng)
        if (!handles(subject, predicate, object, context)) {
            return null;
        }
        final RyaContext ryaContext = RyaContext.getInstance();
        final TABLE_LAYOUT table_layout = TABLE_LAYOUT.SPO;
        byte[] start;
        byte[] stop;
        if (predicate != null) {
            if (object != null) {
                if (object instanceof RyaRange) {
                    // sp_r(o)
                    // range = sp_r(o.s)->sp_r(o.e) (remove last byte to remove type info)
                    RyaRange rv = (RyaRange) object;
                    rv = ryaContext.transformRange(rv);
                    final byte[] objStartBytes = ryaContext.serializeType(rv.getStart())[0];
                    final byte[] objEndBytes = ryaContext.serializeType(rv.getStop())[0];
                    final byte[] subjBytes = subject.getData().getBytes(StandardCharsets.UTF_8);
                    final byte[] predBytes = predicate.getData().getBytes(StandardCharsets.UTF_8);
                    start = Bytes.concat(subjBytes, DELIM_BYTES, predBytes, DELIM_BYTES, objStartBytes);
                    stop = Bytes.concat(subjBytes, DELIM_BYTES, predBytes, DELIM_BYTES, objEndBytes, DELIM_BYTES, LAST_BYTES);
                } else {
                    // spo
                    // range = spo->spo (remove last byte to remove type info)
                    // TODO: There must be a better way than creating multiple byte[]
                    final byte[] objBytes = ryaContext.serializeType(object)[0];
                    start = Bytes.concat(subject.getData().getBytes(StandardCharsets.UTF_8), DELIM_BYTES, predicate.getData().getBytes(StandardCharsets.UTF_8), DELIM_BYTES, objBytes, TYPE_DELIM_BYTES);
                    stop = Bytes.concat(start, LAST_BYTES);
                }
            } else if (predicate instanceof RyaRange) {
                // s_r(p)
                // range = s_r(p.s)->s_r(p.e)
                RyaRange rv = (RyaRange) predicate;
                rv = ryaContext.transformRange(rv);
                final byte[] subjBytes = subject.getData().getBytes(StandardCharsets.UTF_8);
                final byte[] predStartBytes = rv.getStart().getData().getBytes(StandardCharsets.UTF_8);
                final byte[] predStopBytes = rv.getStop().getData().getBytes(StandardCharsets.UTF_8);
                start = Bytes.concat(subjBytes, DELIM_BYTES, predStartBytes);
                stop = Bytes.concat(subjBytes, DELIM_BYTES, predStopBytes, DELIM_BYTES, LAST_BYTES);
            } else {
                // sp
                // range = sp
                start = Bytes.concat(subject.getData().getBytes(StandardCharsets.UTF_8), DELIM_BYTES, predicate.getData().getBytes(StandardCharsets.UTF_8), DELIM_BYTES);
                stop = Bytes.concat(start, LAST_BYTES);
            }
        } else if (subject instanceof RyaRange) {
            // r(s)
            // range = r(s.s) -> r(s.e)
            RyaRange ru = (RyaRange) subject;
            ru = ryaContext.transformRange(ru);
            start = ru.getStart().getData().getBytes(StandardCharsets.UTF_8);
            stop = Bytes.concat(ru.getStop().getData().getBytes(StandardCharsets.UTF_8), DELIM_BYTES, LAST_BYTES);
        } else {
            // s
            // range = s
            start = Bytes.concat(subject.getData().getBytes(StandardCharsets.UTF_8), DELIM_BYTES);
            stop = Bytes.concat(start, LAST_BYTES);
        }
        return new RdfCloudTripleStoreUtils.CustomEntry<TABLE_LAYOUT, ByteRange>(table_layout, new ByteRange(start, stop));
    } catch (final RyaTypeResolverException e) {
        throw new IOException(e);
    }
}
Also used : TABLE_LAYOUT(org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT) RyaContext(org.apache.rya.api.resolver.RyaContext) ByteRange(org.apache.rya.api.query.strategy.ByteRange) RyaRange(org.apache.rya.api.domain.RyaRange) RyaTypeResolverException(org.apache.rya.api.resolver.RyaTypeResolverException) IOException(java.io.IOException)

Example 22 with ByteRange

use of org.apache.rya.api.query.strategy.ByteRange in project incubator-rya by apache.

the class HashedPoWholeRowTriplePatternStrategyTest method testP.

public void testP() throws Exception {
    Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, ByteRange> entry = strategy.defineRange(null, uri, null, null, null);
    Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = ryaTripleContext.serializeTriple(new RyaStatement(uri, uri, uri, null));
    TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO);
    assertContains(entry.getValue(), tripleRow.getRow());
}
Also used : TripleRow(org.apache.rya.api.resolver.triple.TripleRow) ByteRange(org.apache.rya.api.query.strategy.ByteRange) RyaStatement(org.apache.rya.api.domain.RyaStatement) Map(java.util.Map)

Example 23 with ByteRange

use of org.apache.rya.api.query.strategy.ByteRange in project incubator-rya by apache.

the class HashedPoWholeRowTriplePatternStrategyTest method testPo.

public void testPo() throws Exception {
    Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = ryaTripleContext.serializeTriple(new RyaStatement(uri, uri, uri, null));
    TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO);
    Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, ByteRange> entry = strategy.defineRange(null, uri, uri, null, null);
    assertContains(entry.getValue(), tripleRow.getRow());
    entry = strategy.defineRange(null, uri, uri2, null, null);
    assertContainsFalse(entry.getValue(), tripleRow.getRow());
}
Also used : TripleRow(org.apache.rya.api.resolver.triple.TripleRow) ByteRange(org.apache.rya.api.query.strategy.ByteRange) RyaStatement(org.apache.rya.api.domain.RyaStatement) Map(java.util.Map)

Example 24 with ByteRange

use of org.apache.rya.api.query.strategy.ByteRange in project incubator-rya by apache.

the class HashedPoWholeRowTriplePatternStrategyTest method testPoCustomType.

public void testPoCustomType() throws Exception {
    Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = ryaTripleContext.serializeTriple(new RyaStatement(uri, uri, customType1, null));
    TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO);
    Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, ByteRange> entry = strategy.defineRange(null, uri, customType1, null, null);
    assertContains(entry.getValue(), tripleRow.getRow());
    entry = strategy.defineRange(null, uri, customType2, null, null);
    assertContainsFalse(entry.getValue(), tripleRow.getRow());
}
Also used : TripleRow(org.apache.rya.api.resolver.triple.TripleRow) ByteRange(org.apache.rya.api.query.strategy.ByteRange) RyaStatement(org.apache.rya.api.domain.RyaStatement) Map(java.util.Map)

Example 25 with ByteRange

use of org.apache.rya.api.query.strategy.ByteRange in project incubator-rya by apache.

the class AccumuloQueryRuleset method getRules.

/**
 * Get the rules that apply to all statements within a Range. The range may not
 * contain every row relevant to the associated rule(s), but every row within the
 * range is relevant to the rule(s).
 * @param layout Defines which table the range is meant to scan
 * @param range The Range of rows in that table
 * @return Any rules in this ruleset that match the given table and contain the given range
 * @throws IOException if the Range can't be resolved
 */
public List<CopyRule> getRules(final TABLE_LAYOUT layout, final Range range) throws IOException {
    final List<CopyRule> matchingRules = new LinkedList<>();
    for (final CopyRule rule : rules) {
        // Compare the rule to the given range
        final Map.Entry<TABLE_LAYOUT, ByteRange> entry = getRange(rule.getStatement());
        final TABLE_LAYOUT ruleLayout = entry.getKey();
        // If they apply to different tables, they are unrelated.
        if (!ruleLayout.equals(layout)) {
            continue;
        }
        // If the given range is contained in (or equal to) the rule's range, then the
        // rule matches and should be included.
        final ByteRange byteRange = entry.getValue();
        final Range ruleRange = new Range(new Text(byteRange.getStart()), new Text(byteRange.getEnd()));
        if (rangeContainsRange(ruleRange, range)) {
            matchingRules.add(rule);
        }
    }
    return matchingRules;
}
Also used : TABLE_LAYOUT(org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT) ByteRange(org.apache.rya.api.query.strategy.ByteRange) Text(org.apache.hadoop.io.Text) Range(org.apache.accumulo.core.data.Range) ByteRange(org.apache.rya.api.query.strategy.ByteRange) HashMap(java.util.HashMap) Map(java.util.Map) LinkedList(java.util.LinkedList)

Aggregations

ByteRange (org.apache.rya.api.query.strategy.ByteRange)26 Map (java.util.Map)20 RyaStatement (org.apache.rya.api.domain.RyaStatement)17 TripleRow (org.apache.rya.api.resolver.triple.TripleRow)13 TABLE_LAYOUT (org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT)9 IOException (java.io.IOException)8 RyaRange (org.apache.rya.api.domain.RyaRange)8 HashMap (java.util.HashMap)5 Range (org.apache.accumulo.core.data.Range)5 Text (org.apache.hadoop.io.Text)5 RyaURI (org.apache.rya.api.domain.RyaURI)5 TriplePatternStrategy (org.apache.rya.api.query.strategy.TriplePatternStrategy)5 RyaContext (org.apache.rya.api.resolver.RyaContext)5 RyaTypeResolverException (org.apache.rya.api.resolver.RyaTypeResolverException)5 BatchScanner (org.apache.accumulo.core.client.BatchScanner)3 Scanner (org.apache.accumulo.core.client.Scanner)3 Authorizations (org.apache.accumulo.core.security.Authorizations)3 RyaType (org.apache.rya.api.domain.RyaType)3 RyaDAOException (org.apache.rya.api.persist.RyaDAOException)3 TripleRowRegex (org.apache.rya.api.resolver.triple.TripleRowRegex)3