Search in sources :

Example 46 with AccumuloPcjStorage

use of org.apache.rya.indexing.pcj.storage.accumulo.AccumuloPcjStorage in project incubator-rya by apache.

the class AccumuloCreatePCJIT method createPCJ.

@Test
public void createPCJ() throws Exception {
    AccumuloConnectionDetails connectionDetails = createConnectionDetails();
    // Initialize the commands that will be used by this test.
    final CreatePCJ createPCJ = new AccumuloCreatePCJ(connectionDetails, accumuloConn);
    // Create a PCJ.
    final String sparql = "SELECT ?x " + "WHERE { " + "?x <http://talksTo> <http://Eve>. " + "?x <http://worksAt> <http://TacoJoint>." + "}";
    final String pcjId = createPCJ.createPCJ(getRyaInstanceName(), sparql);
    // Verify the RyaDetails were updated to include the new PCJ.
    final Optional<RyaDetails> ryaDetails = new AccumuloGetInstanceDetails(connectionDetails, accumuloConn).getDetails(getRyaInstanceName());
    final PCJDetails pcjDetails = ryaDetails.get().getPCJIndexDetails().getPCJDetails().get(pcjId);
    assertEquals(pcjId, pcjDetails.getId());
    assertFalse(pcjDetails.getLastUpdateTime().isPresent());
    assertEquals(PCJUpdateStrategy.INCREMENTAL, pcjDetails.getUpdateStrategy().get());
    try (final PrecomputedJoinStorage pcjStorage = new AccumuloPcjStorage(accumuloConn, getRyaInstanceName())) {
        final PcjMetadata pcjMetadata = pcjStorage.getPcjMetadata(pcjId);
        assertEquals(sparql, pcjMetadata.getSparql());
        assertEquals(0L, pcjMetadata.getCardinality());
        // Verify a Query ID was added for the query within the Fluo app.
        final List<String> fluoQueryIds = new ListQueryIds().listQueryIds(fluoClient);
        assertEquals(1, fluoQueryIds.size());
        // Insert some statements into Rya.
        final ValueFactory vf = ryaRepo.getValueFactory();
        ryaConn.add(vf.createURI("http://Alice"), vf.createURI("http://talksTo"), vf.createURI("http://Eve"));
        ryaConn.add(vf.createURI("http://Bob"), vf.createURI("http://talksTo"), vf.createURI("http://Eve"));
        ryaConn.add(vf.createURI("http://Charlie"), vf.createURI("http://talksTo"), vf.createURI("http://Eve"));
        ryaConn.add(vf.createURI("http://Eve"), vf.createURI("http://helps"), vf.createURI("http://Kevin"));
        ryaConn.add(vf.createURI("http://Bob"), vf.createURI("http://worksAt"), vf.createURI("http://TacoJoint"));
        ryaConn.add(vf.createURI("http://Charlie"), vf.createURI("http://worksAt"), vf.createURI("http://TacoJoint"));
        ryaConn.add(vf.createURI("http://Eve"), vf.createURI("http://worksAt"), vf.createURI("http://TacoJoint"));
        ryaConn.add(vf.createURI("http://David"), vf.createURI("http://worksAt"), vf.createURI("http://TacoJoint"));
        // Verify the correct results were exported.
        fluo.waitForObservers();
        final Set<BindingSet> results = Sets.newHashSet(pcjStorage.listResults(pcjId));
        final MapBindingSet bob = new MapBindingSet();
        bob.addBinding("x", vf.createURI("http://Bob"));
        final MapBindingSet charlie = new MapBindingSet();
        charlie.addBinding("x", vf.createURI("http://Charlie"));
        final Set<BindingSet> expected = Sets.<BindingSet>newHashSet(bob, charlie);
        assertEquals(expected, results);
    }
}
Also used : MapBindingSet(org.openrdf.query.impl.MapBindingSet) BindingSet(org.openrdf.query.BindingSet) AccumuloPcjStorage(org.apache.rya.indexing.pcj.storage.accumulo.AccumuloPcjStorage) CreatePCJ(org.apache.rya.api.client.CreatePCJ) RyaDetails(org.apache.rya.api.instance.RyaDetails) ValueFactory(org.openrdf.model.ValueFactory) PCJDetails(org.apache.rya.api.instance.RyaDetails.PCJIndexDetails.PCJDetails) ListQueryIds(org.apache.rya.indexing.pcj.fluo.api.ListQueryIds) PrecomputedJoinStorage(org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage) PcjMetadata(org.apache.rya.indexing.pcj.storage.PcjMetadata) MapBindingSet(org.openrdf.query.impl.MapBindingSet) Test(org.junit.Test)

Aggregations

AccumuloPcjStorage (org.apache.rya.indexing.pcj.storage.accumulo.AccumuloPcjStorage)46 PrecomputedJoinStorage (org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage)44 Test (org.junit.Test)32 Connector (org.apache.accumulo.core.client.Connector)26 FluoClient (org.apache.fluo.api.client.FluoClient)21 CreateFluoPcj (org.apache.rya.indexing.pcj.fluo.api.CreateFluoPcj)20 BindingSet (org.openrdf.query.BindingSet)20 MapBindingSet (org.openrdf.query.impl.MapBindingSet)18 HashSet (java.util.HashSet)15 RyaStatement (org.apache.rya.api.domain.RyaStatement)15 ValueFactory (org.openrdf.model.ValueFactory)13 RyaURI (org.apache.rya.api.domain.RyaURI)12 InsertTriples (org.apache.rya.indexing.pcj.fluo.api.InsertTriples)11 PcjMetadata (org.apache.rya.indexing.pcj.storage.PcjMetadata)10 ValueFactoryImpl (org.openrdf.model.impl.ValueFactoryImpl)9 FluoClientImpl (org.apache.fluo.core.client.FluoClientImpl)7 VisibilityBindingSet (org.apache.rya.api.model.VisibilityBindingSet)7 SailRepositoryConnection (org.openrdf.repository.sail.SailRepositoryConnection)7 PCJDetails (org.apache.rya.api.instance.RyaDetails.PCJIndexDetails.PCJDetails)6 MalformedQueryException (org.openrdf.query.MalformedQueryException)6