Search in sources :

Example 16 with ByteRange

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

the class PoWholeRowTriplePatternStrategy method defineRange.

@Override
public Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, ByteRange> defineRange(final RyaURI subject, final RyaURI predicate, final RyaType object, final RyaURI context, final RdfCloudTripleStoreConfiguration conf) throws IOException {
    try {
        // r(p)(ng)
        if (!handles(subject, predicate, object, context)) {
            return null;
        }
        final RyaContext ryaContext = RyaContext.getInstance();
        final RdfCloudTripleStoreConstants.TABLE_LAYOUT table_layout = RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO;
        byte[] start, stop;
        if (object != null) {
            if (object instanceof RyaRange) {
                // p_r(o)
                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[] predBytes = predicate.getData().getBytes(StandardCharsets.UTF_8);
                start = Bytes.concat(predBytes, DELIM_BYTES, objStartBytes);
                stop = Bytes.concat(predBytes, DELIM_BYTES, objEndBytes, DELIM_BYTES, LAST_BYTES);
            } else {
                if (subject != null && subject instanceof RyaRange) {
                    // po_r(s)
                    RyaRange ru = (RyaRange) subject;
                    ru = ryaContext.transformRange(ru);
                    final byte[] subjStartBytes = ru.getStart().getData().getBytes(StandardCharsets.UTF_8);
                    final byte[] subjStopBytes = ru.getStop().getData().getBytes(StandardCharsets.UTF_8);
                    final byte[] predBytes = predicate.getData().getBytes(StandardCharsets.UTF_8);
                    final byte[] objBytes = ryaContext.serializeType(object)[0];
                    start = Bytes.concat(predBytes, DELIM_BYTES, objBytes, DELIM_BYTES, subjStartBytes);
                    stop = Bytes.concat(predBytes, DELIM_BYTES, objBytes, DELIM_BYTES, subjStopBytes, TYPE_DELIM_BYTES, LAST_BYTES);
                } else {
                    // po
                    // TODO: There must be a better way than creating multiple byte[]
                    final byte[] objBytes = ryaContext.serializeType(object)[0];
                    start = Bytes.concat(predicate.getData().getBytes(StandardCharsets.UTF_8), DELIM_BYTES, objBytes, DELIM_BYTES);
                    stop = Bytes.concat(start, LAST_BYTES);
                }
            }
        } else if (predicate instanceof RyaRange) {
            // r(p)
            RyaRange rv = (RyaRange) predicate;
            rv = ryaContext.transformRange(rv);
            start = rv.getStart().getData().getBytes(StandardCharsets.UTF_8);
            stop = Bytes.concat(rv.getStop().getData().getBytes(StandardCharsets.UTF_8), DELIM_BYTES, LAST_BYTES);
        } else {
            // p
            start = Bytes.concat(predicate.getData().getBytes(StandardCharsets.UTF_8), DELIM_BYTES);
            stop = Bytes.concat(start, LAST_BYTES);
        }
        return new RdfCloudTripleStoreUtils.CustomEntry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, ByteRange>(table_layout, new ByteRange(start, stop));
    } catch (final RyaTypeResolverException e) {
        throw new IOException(e);
    }
}
Also used : 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) RdfCloudTripleStoreConstants(org.apache.rya.api.RdfCloudTripleStoreConstants)

Example 17 with ByteRange

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

the class HashedSpoWholeRowTriplePatternStrategyTest method testS.

public void testS() throws Exception {
    Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = ryaTripleContext.serializeTriple(new RyaStatement(uri, uri, uri, null));
    TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO);
    Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, ByteRange> entry = strategy.defineRange(uri, null, null, null, null);
    assertContains(entry.getValue(), tripleRow.getRow());
    entry = strategy.defineRange(uri2, null, null, 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 18 with ByteRange

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

the class HashedSpoWholeRowTriplePatternStrategyTest method testSp.

public void testSp() throws Exception {
    Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = ryaTripleContext.serializeTriple(new RyaStatement(uri, uri, uri, null));
    TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO);
    Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, ByteRange> entry = strategy.defineRange(uri, uri, null, null, null);
    assertContains(entry.getValue(), tripleRow.getRow());
    entry = strategy.defineRange(uri, uri2, null, 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 19 with ByteRange

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

the class HashedSpoWholeRowTriplePatternStrategyTest method testSpo.

public void testSpo() throws Exception {
    Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = ryaTripleContext.serializeTriple(new RyaStatement(uri, uri, uri, null));
    TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO);
    Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, ByteRange> entry = strategy.defineRange(uri, uri, uri, null, null);
    assertContains(entry.getValue(), tripleRow.getRow());
    entry = strategy.defineRange(uri, 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 20 with ByteRange

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

the class HashedSpoWholeRowTriplePatternStrategyTest method testSpoRangeCustomType.

public void testSpoRangeCustomType() throws Exception {
    Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, TripleRow> serialize = ryaTripleContext.serializeTriple(new RyaStatement(uri, uri, customType1, null));
    TripleRow tripleRow = serialize.get(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO);
    Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, ByteRange> entry = strategy.defineRange(uri, uri, customTypeRange1, null, null);
    assertContains(entry.getValue(), tripleRow.getRow());
    entry = strategy.defineRange(uri, uri, customTypeRange2, 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)

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