Search in sources :

Example 6 with MongoPcjStorage

use of org.apache.rya.indexing.pcj.storage.mongo.MongoPcjStorage in project incubator-rya by apache.

the class MongoCreatePCJIT method createPCJ.

@Test
public void createPCJ() throws Exception {
    final MongoConnectionDetails connectionDetails = getConnectionDetails();
    final RyaClient ryaClient = MongoRyaClientFactory.build(connectionDetails, getMongoClient());
    // Initialize the commands that will be used by this test.
    final CreatePCJ createPCJ = ryaClient.getCreatePCJ();
    final Install installRya = ryaClient.getInstall();
    final InstallConfiguration installConf = InstallConfiguration.builder().setEnablePcjIndex(true).build();
    installRya.install(conf.getRyaInstanceName(), installConf);
    System.out.println(getMongoClient().getDatabase(conf.getRyaInstanceName()).getCollection("instance_details").find().first().toJson());
    // Create a PCJ.
    final String sparql = "SELECT ?x " + "WHERE { " + "?x <http://talksTo> <http://Eve>. " + "?x <http://worksAt> <http://TacoJoint>." + "}";
    final String pcjId = createPCJ.createPCJ(conf.getRyaInstanceName(), sparql);
    // Verify the RyaDetails were updated to include the new PCJ.
    final Optional<RyaDetails> ryaDetails = ryaClient.getGetInstanceDetails().getDetails(conf.getRyaInstanceName());
    final ImmutableMap<String, PCJDetails> details = ryaDetails.get().getPCJIndexDetails().getPCJDetails();
    final PCJDetails pcjDetails = details.get(pcjId);
    assertEquals(pcjId, pcjDetails.getId());
    assertFalse(pcjDetails.getLastUpdateTime().isPresent());
    try (final PrecomputedJoinStorage pcjStorage = new MongoPcjStorage(getMongoClient(), conf.getRyaInstanceName())) {
        final PcjMetadata pcjMetadata = pcjStorage.getPcjMetadata(pcjId);
        // confirm that the pcj was added to the pcj store.
        assertEquals(sparql, pcjMetadata.getSparql());
        assertEquals(0L, pcjMetadata.getCardinality());
    }
}
Also used : CreatePCJ(org.apache.rya.api.client.CreatePCJ) AccumuloCreatePCJ(org.apache.rya.api.client.accumulo.AccumuloCreatePCJ) RyaDetails(org.apache.rya.api.instance.RyaDetails) RyaClient(org.apache.rya.api.client.RyaClient) InstallConfiguration(org.apache.rya.api.client.Install.InstallConfiguration) PCJDetails(org.apache.rya.api.instance.RyaDetails.PCJIndexDetails.PCJDetails) MongoPcjStorage(org.apache.rya.indexing.pcj.storage.mongo.MongoPcjStorage) PrecomputedJoinStorage(org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage) PcjMetadata(org.apache.rya.indexing.pcj.storage.PcjMetadata) Install(org.apache.rya.api.client.Install) Test(org.junit.Test)

Aggregations

MongoPcjStorage (org.apache.rya.indexing.pcj.storage.mongo.MongoPcjStorage)6 PrecomputedJoinStorage (org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage)4 PCJStorageException (org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage.PCJStorageException)4 RyaClientException (org.apache.rya.api.client.RyaClientException)3 ArrayList (java.util.ArrayList)2 InstanceDoesNotExistException (org.apache.rya.api.client.InstanceDoesNotExistException)2 RyaClient (org.apache.rya.api.client.RyaClient)2 PcjMetadata (org.apache.rya.indexing.pcj.storage.PcjMetadata)2 Test (org.junit.Test)2 BindingSet (org.openrdf.query.BindingSet)2 MalformedQueryException (org.openrdf.query.MalformedQueryException)2 MongoClient (com.mongodb.MongoClient)1 HashSet (java.util.HashSet)1 List (java.util.List)1 CreatePCJ (org.apache.rya.api.client.CreatePCJ)1 Install (org.apache.rya.api.client.Install)1 InstallConfiguration (org.apache.rya.api.client.Install.InstallConfiguration)1 AccumuloCreatePCJ (org.apache.rya.api.client.accumulo.AccumuloCreatePCJ)1 RyaDetails (org.apache.rya.api.instance.RyaDetails)1 PCJDetails (org.apache.rya.api.instance.RyaDetails.PCJIndexDetails.PCJDetails)1