Search in sources :

Example 6 with StatementPatternMetadata

use of org.apache.rya.indexing.pcj.fluo.app.query.StatementPatternMetadata in project incubator-rya by apache.

the class StatementPatternIdCacheIT method statementPatternIdCacheTest.

/**
 * Ensure streamed matches are included in the result.
 */
@Test
public void statementPatternIdCacheTest() throws Exception {
    // A query that finds people who talk to Eve and work at Chipotle.
    final String sparql1 = "SELECT ?x WHERE { " + "?x <urn:pred1> <urn:obj1>. " + "?x <urn:pred2> <urn:obj2>." + "}";
    final String sparql2 = "SELECT ?x WHERE { " + "?x <urn:pred3> <urn:obj3>. " + "?x <urn:pred4> <urn:obj4>." + "}";
    try (FluoClient fluoClient = FluoFactory.newClient(super.getFluoConfiguration())) {
        String pcjId = FluoQueryUtils.createNewPcjId();
        // Tell the Fluo app to maintain the PCJ.
        FluoQuery query1 = new CreateFluoPcj().createPcj(pcjId, sparql1, new HashSet<>(), fluoClient);
        Set<String> spIds1 = new HashSet<>();
        for (StatementPatternMetadata metadata : query1.getStatementPatternMetadata()) {
            spIds1.add(metadata.getNodeId());
        }
        StatementPatternIdCache cache = new StatementPatternIdCache();
        assertEquals(spIds1, cache.getStatementPatternIds(fluoClient.newTransaction()));
        FluoQuery query2 = new CreateFluoPcj().createPcj(pcjId, sparql2, new HashSet<>(), fluoClient);
        Set<String> spIds2 = new HashSet<>();
        for (StatementPatternMetadata metadata : query2.getStatementPatternMetadata()) {
            spIds2.add(metadata.getNodeId());
        }
        assertEquals(Sets.union(spIds1, spIds2), cache.getStatementPatternIds(fluoClient.newTransaction()));
    }
}
Also used : FluoClient(org.apache.fluo.api.client.FluoClient) StatementPatternMetadata(org.apache.rya.indexing.pcj.fluo.app.query.StatementPatternMetadata) CreateFluoPcj(org.apache.rya.indexing.pcj.fluo.api.CreateFluoPcj) StatementPatternIdCache(org.apache.rya.indexing.pcj.fluo.app.query.StatementPatternIdCache) FluoQuery(org.apache.rya.indexing.pcj.fluo.app.query.FluoQuery) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 7 with StatementPatternMetadata

use of org.apache.rya.indexing.pcj.fluo.app.query.StatementPatternMetadata in project incubator-rya by apache.

the class CreateFluoPcj method importHistoricResultsIntoFluo.

private void importHistoricResultsIntoFluo(FluoClient fluo, FluoQuery fluoQuery, Connector accumulo, String ryaInstance) throws RyaDAOException {
    // Reuse the same set object while performing batch inserts.
    final Set<RyaStatement> queryBatch = new HashSet<>();
    // historic matches into Fluo.
    for (final StatementPatternMetadata patternMetadata : fluoQuery.getStatementPatternMetadata()) {
        // Get an iterator over all of the binding sets that match the
        // statement pattern.
        final StatementPattern pattern = FluoStringConverter.toStatementPattern(patternMetadata.getStatementPattern());
        queryBatch.add(spToRyaStatement(pattern));
    }
    // Create AccumuloRyaQueryEngine to query for historic results
    final AccumuloRdfConfiguration conf = new AccumuloRdfConfiguration();
    conf.setTablePrefix(ryaInstance);
    conf.setAuths(getAuths(accumulo));
    try (final AccumuloRyaQueryEngine queryEngine = new AccumuloRyaQueryEngine(accumulo, conf);
        CloseableIterable<RyaStatement> queryIterable = queryEngine.query(new BatchRyaQuery(queryBatch))) {
        final Set<RyaStatement> triplesBatch = new HashSet<>();
        // Insert batches of the binding sets into Fluo.
        for (final RyaStatement ryaStatement : queryIterable) {
            if (triplesBatch.size() == spInsertBatchSize) {
                writeBatch(fluo, triplesBatch);
                triplesBatch.clear();
            }
            triplesBatch.add(ryaStatement);
        }
        if (!triplesBatch.isEmpty()) {
            writeBatch(fluo, triplesBatch);
            triplesBatch.clear();
        }
    } catch (final IOException e) {
        log.warn("Ignoring IOException thrown while closing the AccumuloRyaQueryEngine used by CreatePCJ.", e);
    }
}
Also used : StatementPattern(org.openrdf.query.algebra.StatementPattern) StatementPatternMetadata(org.apache.rya.indexing.pcj.fluo.app.query.StatementPatternMetadata) BatchRyaQuery(org.apache.rya.api.persist.query.BatchRyaQuery) RyaStatement(org.apache.rya.api.domain.RyaStatement) AccumuloRyaQueryEngine(org.apache.rya.accumulo.query.AccumuloRyaQueryEngine) IOException(java.io.IOException) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) HashSet(java.util.HashSet)

Aggregations

StatementPatternMetadata (org.apache.rya.indexing.pcj.fluo.app.query.StatementPatternMetadata)7 FluoQuery (org.apache.rya.indexing.pcj.fluo.app.query.FluoQuery)4 RyaStatement (org.apache.rya.api.domain.RyaStatement)3 BigInteger (java.math.BigInteger)2 HashSet (java.util.HashSet)2 FluoClient (org.apache.fluo.api.client.FluoClient)2 Bytes (org.apache.fluo.api.data.Bytes)2 VisibilityBindingSet (org.apache.rya.api.model.VisibilityBindingSet)2 QueryReport (org.apache.rya.indexing.pcj.fluo.api.GetQueryReport.QueryReport)2 FilterMetadata (org.apache.rya.indexing.pcj.fluo.app.query.FilterMetadata)2 JoinMetadata (org.apache.rya.indexing.pcj.fluo.app.query.JoinMetadata)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Connector (org.apache.accumulo.core.client.Connector)1 Snapshot (org.apache.fluo.api.client.Snapshot)1 AccumuloRdfConfiguration (org.apache.rya.accumulo.AccumuloRdfConfiguration)1 AccumuloRyaQueryEngine (org.apache.rya.accumulo.query.AccumuloRyaQueryEngine)1 RyaURI (org.apache.rya.api.domain.RyaURI)1 BatchRyaQuery (org.apache.rya.api.persist.query.BatchRyaQuery)1