use of org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage 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);
}
}
use of org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage in project incubator-rya by apache.
the class MongoPcjStorageIT method listPcjs.
@Test
public void listPcjs() throws Exception {
try (final PrecomputedJoinStorage pcjStorage = new MongoPcjStorage(getMongoClient(), conf.getRyaInstanceName())) {
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());
// Create a few PCJs and hold onto their IDs.
final List<String> expectedIds = new ArrayList<>();
String pcjId = pcjStorage.createPcj("SELECT * WHERE { ?a <http://isA> ?b } ");
expectedIds.add(pcjId);
pcjId = pcjStorage.createPcj("SELECT * WHERE { ?a <http://isA> ?b } ");
expectedIds.add(pcjId);
pcjId = pcjStorage.createPcj("SELECT * WHERE { ?a <http://isA> ?b } ");
expectedIds.add(pcjId);
// Fetch the PCJ names
final List<String> pcjIds = pcjStorage.listPcjs();
// Ensure the expected IDs match the fetched IDs.
Collections.sort(expectedIds);
Collections.sort(pcjIds);
assertEquals(expectedIds, pcjIds);
}
}
use of org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage 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));
}
}
use of org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage in project incubator-rya by apache.
the class MongoPcjStorageIT method addResults.
@Test
public void addResults() throws Exception {
try (final PrecomputedJoinStorage pcjStorage = new MongoPcjStorage(getMongoClient(), conf.getRyaInstanceName())) {
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());
// Create a PCJ.
final String sparql = "SELECT * WHERE { ?a <http://isA> ?b }";
final String pcjId = pcjStorage.createPcj(sparql);
// Add some binding sets to it.
final Set<VisibilityBindingSet> results = new HashSet<>();
final MapBindingSet aliceBS = new MapBindingSet();
aliceBS.addBinding("a", new URIImpl("http://Alice"));
aliceBS.addBinding("b", new URIImpl("http://Person"));
results.add(new VisibilityBindingSet(aliceBS, ""));
final MapBindingSet charlieBS = new MapBindingSet();
charlieBS.addBinding("a", new URIImpl("http://Charlie"));
charlieBS.addBinding("b", new URIImpl("http://Comedian"));
results.add(new VisibilityBindingSet(charlieBS, ""));
pcjStorage.addResults(pcjId, results);
// Make sure the PCJ metadata was updated.
final PcjMetadata metadata = pcjStorage.getPcjMetadata(pcjId);
final Set<VariableOrder> varOrders = new ShiftVarOrderFactory().makeVarOrders(sparql);
final PcjMetadata expectedMetadata = new PcjMetadata(sparql, 2L, varOrders);
assertEquals(expectedMetadata, metadata);
}
}
use of org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage 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());
}
}
Aggregations