Search in sources :

Example 11 with PCJDetails

use of org.apache.rya.api.instance.RyaDetails.PCJIndexDetails.PCJDetails 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)

Example 12 with PCJDetails

use of org.apache.rya.api.instance.RyaDetails.PCJIndexDetails.PCJDetails in project incubator-rya by apache.

the class MongoPcjStorageIT method createPCJ.

@Test
public void createPCJ() throws Exception {
    // Setup the PCJ storage that will be tested against.
    try (final PrecomputedJoinStorage pcjStorage = new MongoPcjStorage(getMongoClient(), conf.getRyaInstanceName())) {
        // Create a PCJ.
        final MongoRyaInstanceDetailsRepository detailsRepo = new MongoRyaInstanceDetailsRepository(getMongoClient(), conf.getRyaInstanceName());
        detailsRepo.initialize(RyaDetails.builder().setRyaInstanceName(conf.getRyaInstanceName()).setRyaVersion("test").setEntityCentricIndexDetails(new EntityCentricIndexDetails(false)).setTemporalIndexDetails(new TemporalIndexDetails(false)).setFreeTextDetails(new FreeTextIndexDetails(false)).setProspectorDetails(new ProspectorDetails(Optional.absent())).setJoinSelectivityDetails(new JoinSelectivityDetails(Optional.absent())).setPCJIndexDetails(PCJIndexDetails.builder().setEnabled(true)).build());
        final String pcjId = pcjStorage.createPcj("SELECT * WHERE { ?a <http://isA> ?b } ");
        // Ensure the Rya details have been updated to include the PCJ's ID.
        final ImmutableMap<String, PCJDetails> detailsMap = detailsRepo.getRyaInstanceDetails().getPCJIndexDetails().getPCJDetails();
        final PCJDetails expectedDetails = PCJDetails.builder().setId(pcjId).build();
        assertEquals(expectedDetails, detailsMap.get(pcjId));
    }
}
Also used : ProspectorDetails(org.apache.rya.api.instance.RyaDetails.ProspectorDetails) EntityCentricIndexDetails(org.apache.rya.api.instance.RyaDetails.EntityCentricIndexDetails) TemporalIndexDetails(org.apache.rya.api.instance.RyaDetails.TemporalIndexDetails) PrecomputedJoinStorage(org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage) FreeTextIndexDetails(org.apache.rya.api.instance.RyaDetails.FreeTextIndexDetails) MongoRyaInstanceDetailsRepository(org.apache.rya.mongodb.instance.MongoRyaInstanceDetailsRepository) JoinSelectivityDetails(org.apache.rya.api.instance.RyaDetails.JoinSelectivityDetails) PCJDetails(org.apache.rya.api.instance.RyaDetails.PCJIndexDetails.PCJDetails) Test(org.junit.Test)

Example 13 with PCJDetails

use of org.apache.rya.api.instance.RyaDetails.PCJIndexDetails.PCJDetails 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)

Example 14 with PCJDetails

use of org.apache.rya.api.instance.RyaDetails.PCJIndexDetails.PCJDetails in project incubator-rya by apache.

the class MongoDetailsAdapter method toDBObject.

private static DBObject toDBObject(final PCJIndexDetails pcjIndexDetails) {
    requireNonNull(pcjIndexDetails);
    final BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
    // Is Enabled
    builder.add(PCJ_ENABLED_KEY, pcjIndexDetails.isEnabled());
    // Add the PCJDetail objects.
    final List<DBObject> pcjDetailsList = new ArrayList<>();
    for (final PCJDetails pcjDetails : pcjIndexDetails.getPCJDetails().values()) {
        pcjDetailsList.add(toDBObject(pcjDetails));
    }
    builder.add(PCJ_PCJS_KEY, pcjDetailsList.toArray());
    return builder.get();
}
Also used : BasicDBObjectBuilder(com.mongodb.BasicDBObjectBuilder) ArrayList(java.util.ArrayList) BasicDBObject(com.mongodb.BasicDBObject) DBObject(com.mongodb.DBObject) PCJDetails(org.apache.rya.api.instance.RyaDetails.PCJIndexDetails.PCJDetails)

Example 15 with PCJDetails

use of org.apache.rya.api.instance.RyaDetails.PCJIndexDetails.PCJDetails in project incubator-rya by apache.

the class MongoDetailsAdapterTest method toDBObject_pcjDetails.

@Test
public void toDBObject_pcjDetails() {
    final PCJDetails details = PCJDetails.builder().setId("pcjId").setLastUpdateTime(new Date()).setUpdateStrategy(PCJUpdateStrategy.INCREMENTAL).build();
    // Convert it into a Mongo DB Object.
    final BasicDBObject dbo = (BasicDBObject) MongoDetailsAdapter.toDBObject(details);
    // Convert the dbo back into the original object.
    final PCJDetails restored = MongoDetailsAdapter.toPCJDetails(dbo).build();
    // Ensure the restored value matches the original.
    assertEquals(details, restored);
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) Date(java.util.Date) PCJDetails(org.apache.rya.api.instance.RyaDetails.PCJIndexDetails.PCJDetails) Test(org.junit.Test)

Aggregations

PCJDetails (org.apache.rya.api.instance.RyaDetails.PCJIndexDetails.PCJDetails)16 Test (org.junit.Test)9 RyaDetails (org.apache.rya.api.instance.RyaDetails)8 PrecomputedJoinStorage (org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage)8 RyaDetailsRepository (org.apache.rya.api.instance.RyaDetailsRepository)6 AccumuloRyaInstanceDetailsRepository (org.apache.rya.accumulo.instance.AccumuloRyaInstanceDetailsRepository)5 RyaClientException (org.apache.rya.api.client.RyaClientException)5 AccumuloPcjStorage (org.apache.rya.indexing.pcj.storage.accumulo.AccumuloPcjStorage)5 RyaDetailsRepositoryException (org.apache.rya.api.instance.RyaDetailsRepository.RyaDetailsRepositoryException)4 BasicDBObject (com.mongodb.BasicDBObject)3 Date (java.util.Date)3 CreatePCJ (org.apache.rya.api.client.CreatePCJ)3 InstanceDoesNotExistException (org.apache.rya.api.client.InstanceDoesNotExistException)3 PCJIndexDetails (org.apache.rya.api.instance.RyaDetails.PCJIndexDetails)3 RyaDetailsUpdater (org.apache.rya.api.instance.RyaDetailsUpdater)3 RyaDetailsMutator (org.apache.rya.api.instance.RyaDetailsUpdater.RyaDetailsMutator)3 CouldNotApplyMutationException (org.apache.rya.api.instance.RyaDetailsUpdater.RyaDetailsMutator.CouldNotApplyMutationException)3 MongoRyaInstanceDetailsRepository (org.apache.rya.mongodb.instance.MongoRyaInstanceDetailsRepository)3 Connector (org.apache.accumulo.core.client.Connector)2 Install (org.apache.rya.api.client.Install)2