Search in sources :

Example 6 with ByteRange

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

the class AccumuloRyaQueryEngine method query.

@Override
public CloseableIterable<RyaStatement> query(RyaQuery ryaQuery) throws RyaDAOException {
    Preconditions.checkNotNull(ryaQuery);
    RyaStatement stmt = ryaQuery.getQuery();
    Preconditions.checkNotNull(stmt);
    // query configuration
    String[] auths = ryaQuery.getAuths();
    Authorizations authorizations = auths != null ? new Authorizations(auths) : configuration.getAuthorizations();
    Long ttl = ryaQuery.getTtl();
    Long currentTime = ryaQuery.getCurrentTime();
    Long maxResults = ryaQuery.getMaxResults();
    Integer batchSize = ryaQuery.getBatchSize();
    String regexSubject = ryaQuery.getRegexSubject();
    String regexPredicate = ryaQuery.getRegexPredicate();
    String regexObject = ryaQuery.getRegexObject();
    TableLayoutStrategy tableLayoutStrategy = configuration.getTableLayoutStrategy();
    try {
        // find triple pattern range
        TriplePatternStrategy strategy = ryaContext.retrieveStrategy(stmt);
        TABLE_LAYOUT layout;
        Range range;
        RyaURI subject = stmt.getSubject();
        RyaURI predicate = stmt.getPredicate();
        RyaType object = stmt.getObject();
        RyaURI context = stmt.getContext();
        String qualifier = stmt.getQualifer();
        TripleRowRegex tripleRowRegex = null;
        if (strategy != null) {
            // otherwise, full table scan is supported
            Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, ByteRange> entry = strategy.defineRange(subject, predicate, object, context, null);
            layout = entry.getKey();
            ByteRange byteRange = entry.getValue();
            range = new Range(new Text(byteRange.getStart()), new Text(byteRange.getEnd()));
        } else {
            range = new Range();
            layout = TABLE_LAYOUT.SPO;
            strategy = ryaContext.retrieveStrategy(layout);
        }
        byte[] objectTypeInfo = null;
        if (object != null) {
            // TODO: Not good to serialize this twice
            if (object instanceof RyaRange) {
                objectTypeInfo = RyaContext.getInstance().serializeType(((RyaRange) object).getStart())[1];
            } else {
                objectTypeInfo = RyaContext.getInstance().serializeType(object)[1];
            }
        }
        tripleRowRegex = strategy.buildRegex(regexSubject, regexPredicate, regexObject, null, objectTypeInfo);
        // use range to set scanner
        // populate scanner based on authorizations, ttl
        String table = layoutToTable(layout, tableLayoutStrategy);
        Scanner scanner = connector.createScanner(table, authorizations);
        scanner.setRange(range);
        if (batchSize != null) {
            scanner.setBatchSize(batchSize);
        }
        fillScanner(scanner, context, qualifier, ttl, currentTime, tripleRowRegex, ryaQuery.getConf());
        FluentCloseableIterable<RyaStatement> results = FluentCloseableIterable.from(new ScannerBaseCloseableIterable(scanner)).transform(keyValueToRyaStatementFunctionMap.get(layout));
        if (maxResults != null) {
            results = results.limit(maxResults.intValue());
        }
        return results;
    } catch (Exception e) {
        throw new RyaDAOException(e);
    }
}
Also used : TableLayoutStrategy(org.apache.rya.api.layout.TableLayoutStrategy) BatchScanner(org.apache.accumulo.core.client.BatchScanner) Scanner(org.apache.accumulo.core.client.Scanner) Authorizations(org.apache.accumulo.core.security.Authorizations) TriplePatternStrategy(org.apache.rya.api.query.strategy.TriplePatternStrategy) ByteRange(org.apache.rya.api.query.strategy.ByteRange) RyaStatement(org.apache.rya.api.domain.RyaStatement) Text(org.apache.hadoop.io.Text) RyaRange(org.apache.rya.api.domain.RyaRange) RyaRange(org.apache.rya.api.domain.RyaRange) Range(org.apache.accumulo.core.data.Range) ByteRange(org.apache.rya.api.query.strategy.ByteRange) RyaType(org.apache.rya.api.domain.RyaType) IOException(java.io.IOException) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) TABLE_LAYOUT(org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT) RyaURI(org.apache.rya.api.domain.RyaURI) TripleRowRegex(org.apache.rya.api.resolver.triple.TripleRowRegex) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 7 with ByteRange

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

the class HashedSpoWholeRowTriplePatternStrategyTest method testSpoRange.

public void testSpoRange() 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, rangeURI, null, null);
    assertContains(entry.getValue(), tripleRow.getRow());
    entry = strategy.defineRange(uri, uri, rangeURI2, 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 8 with ByteRange

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

the class HashedSpoWholeRowTriplePatternStrategyTest method testSpRange.

public void testSpRange() 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, rangeURI, null, null, null);
    assertContains(entry.getValue(), tripleRow.getRow());
    entry = strategy.defineRange(uri, rangeURI2, 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 9 with ByteRange

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

the class HashedSpoWholeRowTriplePatternStrategyTest method testSpoCustomType.

public void testSpoCustomType() 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, customType1, null, null);
    assertContains(entry.getValue(), tripleRow.getRow());
    entry = strategy.defineRange(uri, 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 10 with ByteRange

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

the class NullRowTriplePatternStrategyTest method testDefineRange.

/**
 * Test of defineRange method, of class NullRowTriplePatternStrategy.
 * @throws java.lang.Exception
 */
@Test
public void testDefineRange() throws Exception {
    RyaURI subject = null;
    RyaURI predicate = null;
    RyaType object = null;
    RyaURI context = null;
    RdfCloudTripleStoreConfiguration conf = new MockRdfConfiguration();
    NullRowTriplePatternStrategy instance = new NullRowTriplePatternStrategy();
    Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, ByteRange> expResult = new RdfCloudTripleStoreUtils.CustomEntry<>(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO, new ByteRange(new byte[] {}, LAST_BYTES));
    Map.Entry<RdfCloudTripleStoreConstants.TABLE_LAYOUT, ByteRange> result = instance.defineRange(subject, predicate, object, context, conf);
    assertEquals(expResult.getKey(), result.getKey());
    assertTrue(Arrays.equals(expResult.getValue().getStart(), result.getValue().getStart()));
    assertTrue(Arrays.equals(expResult.getValue().getEnd(), result.getValue().getEnd()));
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) ByteRange(org.apache.rya.api.query.strategy.ByteRange) RyaType(org.apache.rya.api.domain.RyaType) RdfCloudTripleStoreConfiguration(org.apache.rya.api.RdfCloudTripleStoreConfiguration) Map(java.util.Map) Test(org.junit.Test)

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