Search in sources :

Example 1 with StatementPatternIdCache

use of org.apache.rya.indexing.pcj.fluo.app.query.StatementPatternIdCache 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)

Aggregations

HashSet (java.util.HashSet)1 FluoClient (org.apache.fluo.api.client.FluoClient)1 CreateFluoPcj (org.apache.rya.indexing.pcj.fluo.api.CreateFluoPcj)1 FluoQuery (org.apache.rya.indexing.pcj.fluo.app.query.FluoQuery)1 StatementPatternIdCache (org.apache.rya.indexing.pcj.fluo.app.query.StatementPatternIdCache)1 StatementPatternMetadata (org.apache.rya.indexing.pcj.fluo.app.query.StatementPatternMetadata)1 Test (org.junit.Test)1