use of org.openrdf.query.impl.MapBindingSet in project incubator-rya by apache.
the class StatementOutputFormatterTest method missingObject.
@Test
public void missingObject() {
// Create the input binding set.
final ValueFactory vf = new ValueFactoryImpl();
final MapBindingSet bindingSet = new MapBindingSet();
bindingSet.addBinding("subject", vf.createURI("urn:Alice"));
bindingSet.addBinding("predicate", vf.createURI("urn:age"));
final VisibilityBindingSet visBs = new VisibilityBindingSet(bindingSet, "a");
// Mock the processor context that will be invoked.
final ProcessorContext context = mock(ProcessorContext.class);
// Run the test.
final StatementOutputFormatter formatter = new StatementOutputFormatter();
formatter.init(context);
formatter.process("key", ProcessorResult.make(new UnaryResult(visBs)));
// Verify the mock was never invoked.
verify(context, times(0)).forward(any(), any());
}
use of org.openrdf.query.impl.MapBindingSet in project incubator-rya by apache.
the class StatementOutputFormatterTest method binaryResult.
@Test
public void binaryResult() {
// Create the input binding set.
final ValueFactory vf = new ValueFactoryImpl();
final MapBindingSet bindingSet = new MapBindingSet();
bindingSet.addBinding("subject", vf.createURI("urn:Alice"));
bindingSet.addBinding("predicate", vf.createURI("urn:age"));
bindingSet.addBinding("object", vf.createLiteral(34));
final VisibilityBindingSet visBs = new VisibilityBindingSet(bindingSet, "a");
// Mock the processor context that will be invoked.
final ProcessorContext context = mock(ProcessorContext.class);
// Run the test.
final StatementOutputFormatter formatter = new StatementOutputFormatter();
formatter.init(context);
formatter.process("key", ProcessorResult.make(new BinaryResult(Side.LEFT, visBs)));
// Verify the mock was invoked with the expected output.
final VisibilityStatement expectedStmt = new VisibilityStatement(vf.createStatement(vf.createURI("urn:Alice"), vf.createURI("urn:age"), vf.createLiteral(34)), "a");
verify(context, times(1)).forward(eq("key"), eq(expectedStmt));
}
use of org.openrdf.query.impl.MapBindingSet in project incubator-rya by apache.
the class StatementOutputFormatterTest method unaryResult.
@Test
public void unaryResult() {
// Create the input binding set.
final ValueFactory vf = new ValueFactoryImpl();
final MapBindingSet bindingSet = new MapBindingSet();
bindingSet.addBinding("subject", vf.createURI("urn:Alice"));
bindingSet.addBinding("predicate", vf.createURI("urn:age"));
bindingSet.addBinding("object", vf.createLiteral(34));
final VisibilityBindingSet visBs = new VisibilityBindingSet(bindingSet, "a");
// Mock the processor context that will be invoked.
final ProcessorContext context = mock(ProcessorContext.class);
// Run the test.
final StatementOutputFormatter formatter = new StatementOutputFormatter();
formatter.init(context);
formatter.process("key", ProcessorResult.make(new UnaryResult(visBs)));
// Verify the mock was invoked with the expected output.
final VisibilityStatement expectedStmt = new VisibilityStatement(vf.createStatement(vf.createURI("urn:Alice"), vf.createURI("urn:age"), vf.createLiteral(34)), "a");
verify(context, times(1)).forward(eq("key"), eq(expectedStmt));
}
use of org.openrdf.query.impl.MapBindingSet in project incubator-rya by apache.
the class AccumuloBatchUpdatePCJIT method batchUpdate.
@Test
public void batchUpdate() throws Exception {
// Setup a Rya Client.
final AccumuloConnectionDetails connectionDetails = new AccumuloConnectionDetails(super.getUsername(), super.getPassword().toCharArray(), super.getInstanceName(), super.getZookeepers());
final RyaClient ryaClient = AccumuloRyaClientFactory.build(connectionDetails, super.getConnector());
// Install an instance of Rya on the mini accumulo cluster.
ryaClient.getInstall().install(RYA_INSTANCE_NAME, InstallConfiguration.builder().setEnablePcjIndex(true).build());
Sail sail = null;
try (final PrecomputedJoinStorage pcjStorage = new AccumuloPcjStorage(super.getConnector(), RYA_INSTANCE_NAME)) {
// Get a Sail connection backed by the installed Rya instance.
final AccumuloRdfConfiguration ryaConf = new AccumuloRdfConfiguration();
ryaConf.setTablePrefix(RYA_INSTANCE_NAME);
ryaConf.set(ConfigUtils.CLOUDBASE_USER, super.getUsername());
ryaConf.set(ConfigUtils.CLOUDBASE_PASSWORD, super.getPassword());
ryaConf.set(ConfigUtils.CLOUDBASE_ZOOKEEPERS, super.getZookeepers());
ryaConf.set(ConfigUtils.CLOUDBASE_INSTANCE, super.getInstanceName());
ryaConf.set(ConfigUtils.USE_PCJ, "true");
ryaConf.set(ConfigUtils.PCJ_STORAGE_TYPE, PrecomputedJoinStorageType.ACCUMULO.toString());
ryaConf.set(ConfigUtils.PCJ_UPDATER_TYPE, PrecomputedJoinUpdaterType.NO_UPDATE.toString());
sail = RyaSailFactory.getInstance(ryaConf);
// Load some statements into the Rya instance.
final ValueFactory vf = sail.getValueFactory();
final SailConnection sailConn = sail.getConnection();
sailConn.begin();
sailConn.addStatement(vf.createURI("urn:Alice"), vf.createURI("urn:likes"), vf.createURI("urn:icecream"));
sailConn.addStatement(vf.createURI("urn:Bob"), vf.createURI("urn:likes"), vf.createURI("urn:icecream"));
sailConn.addStatement(vf.createURI("urn:Charlie"), vf.createURI("urn:likes"), vf.createURI("urn:icecream"));
sailConn.addStatement(vf.createURI("urn:David"), vf.createURI("urn:likes"), vf.createURI("urn:icecream"));
sailConn.addStatement(vf.createURI("urn:Eve"), vf.createURI("urn:likes"), vf.createURI("urn:icecream"));
sailConn.addStatement(vf.createURI("urn:Frank"), vf.createURI("urn:likes"), vf.createURI("urn:icecream"));
sailConn.addStatement(vf.createURI("urn:George"), vf.createURI("urn:likes"), vf.createURI("urn:icecream"));
sailConn.addStatement(vf.createURI("urn:Hillary"), vf.createURI("urn:likes"), vf.createURI("urn:icecream"));
sailConn.addStatement(vf.createURI("urn:Alice"), vf.createURI("urn:hasEyeColor"), vf.createURI("urn:blue"));
sailConn.addStatement(vf.createURI("urn:Bob"), vf.createURI("urn:hasEyeColor"), vf.createURI("urn:blue"));
sailConn.addStatement(vf.createURI("urn:Charlie"), vf.createURI("urn:hasEyeColor"), vf.createURI("urn:blue"));
sailConn.addStatement(vf.createURI("urn:David"), vf.createURI("urn:hasEyeColor"), vf.createURI("urn:blue"));
sailConn.addStatement(vf.createURI("urn:Eve"), vf.createURI("urn:hasEyeColor"), vf.createURI("urn:blue"));
sailConn.addStatement(vf.createURI("urn:Frank"), vf.createURI("urn:hasEyeColor"), vf.createURI("urn:blue"));
sailConn.addStatement(vf.createURI("urn:George"), vf.createURI("urn:hasEyeColor"), vf.createURI("urn:green"));
sailConn.addStatement(vf.createURI("urn:Hillary"), vf.createURI("urn:hasEyeColor"), vf.createURI("urn:brown"));
sailConn.commit();
sailConn.close();
// Create a PCJ for a SPARQL query.
final String sparql = "SELECT ?name WHERE { ?name <urn:likes> <urn:icecream> . ?name <urn:hasEyeColor> <urn:blue> . }";
final String pcjId = pcjStorage.createPcj(sparql);
// Run the test.
ryaClient.getBatchUpdatePCJ().batchUpdate(RYA_INSTANCE_NAME, pcjId);
// Verify the correct results were loaded into the PCJ table.
final Set<BindingSet> expectedResults = new HashSet<>();
MapBindingSet bs = new MapBindingSet();
bs.addBinding("name", vf.createURI("urn:Alice"));
expectedResults.add(bs);
bs = new MapBindingSet();
bs.addBinding("name", vf.createURI("urn:Bob"));
expectedResults.add(bs);
bs = new MapBindingSet();
bs.addBinding("name", vf.createURI("urn:Charlie"));
expectedResults.add(bs);
bs = new MapBindingSet();
bs.addBinding("name", vf.createURI("urn:David"));
expectedResults.add(bs);
bs = new MapBindingSet();
bs.addBinding("name", vf.createURI("urn:Eve"));
expectedResults.add(bs);
bs = new MapBindingSet();
bs.addBinding("name", vf.createURI("urn:Frank"));
expectedResults.add(bs);
final Set<BindingSet> results = new HashSet<>();
try (CloseableIterator<BindingSet> resultsIt = pcjStorage.listResults(pcjId)) {
while (resultsIt.hasNext()) {
results.add(resultsIt.next());
}
}
assertEquals(expectedResults, results);
} finally {
if (sail != null) {
sail.shutDown();
}
}
}
use of org.openrdf.query.impl.MapBindingSet in project incubator-rya by apache.
the class AccumuloDeletePCJIT method deletePCJ.
@Test
public void deletePCJ() throws InstanceDoesNotExistException, RyaClientException, PCJStorageException, RepositoryException {
// Initialize the commands that will be used by this test.
final CreatePCJ createPCJ = new AccumuloCreatePCJ(createConnectionDetails(), 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 a Query ID was added for the query within the Fluo app.
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();
try (final PrecomputedJoinStorage pcjStorage = new AccumuloPcjStorage(accumuloConn, getRyaInstanceName())) {
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);
// Delete the PCJ.
final DeletePCJ deletePCJ = new AccumuloDeletePCJ(createConnectionDetails(), accumuloConn);
deletePCJ.deletePCJ(getRyaInstanceName(), pcjId);
// Ensure the PCJ's metadata has been removed from the storage.
assertTrue(pcjStorage.listPcjs().isEmpty());
// Ensure the PCJ has been removed from the Fluo application.
fluo.waitForObservers();
// Verify a Query ID was added for the query within the Fluo app.
fluoQueryIds = new ListQueryIds().listQueryIds(fluoClient);
assertEquals(0, fluoQueryIds.size());
}
}
Aggregations