use of org.openrdf.model.impl.URIImpl in project incubator-rya by apache.
the class PcjTablesWithMockTest method populatePcj.
@Test
public void populatePcj() throws RepositoryException, PcjException, TableNotFoundException, BindingSetConversionException {
// Load some Triples into Rya.
final Set<Statement> triples = new HashSet<>();
triples.add(new StatementImpl(new URIImpl("http://Alice"), new URIImpl("http://hasAge"), new NumericLiteralImpl(14, XMLSchema.INTEGER)));
triples.add(new StatementImpl(new URIImpl("http://Alice"), new URIImpl("http://playsSport"), new LiteralImpl("Soccer")));
triples.add(new StatementImpl(new URIImpl("http://Bob"), new URIImpl("http://hasAge"), new NumericLiteralImpl(16, XMLSchema.INTEGER)));
triples.add(new StatementImpl(new URIImpl("http://Bob"), new URIImpl("http://playsSport"), new LiteralImpl("Soccer")));
triples.add(new StatementImpl(new URIImpl("http://Charlie"), new URIImpl("http://hasAge"), new NumericLiteralImpl(12, XMLSchema.INTEGER)));
triples.add(new StatementImpl(new URIImpl("http://Charlie"), new URIImpl("http://playsSport"), new LiteralImpl("Soccer")));
triples.add(new StatementImpl(new URIImpl("http://Eve"), new URIImpl("http://hasAge"), new NumericLiteralImpl(43, XMLSchema.INTEGER)));
triples.add(new StatementImpl(new URIImpl("http://Eve"), new URIImpl("http://playsSport"), new LiteralImpl("Soccer")));
for (final Statement triple : triples) {
ryaConn.add(triple);
}
// Create a PCJ table that will include those triples in its results.
final String sparql = "SELECT ?name ?age " + "{" + "?name <http://hasAge> ?age." + "?name <http://playsSport> \"Soccer\" " + "}";
final String pcjTableName = new PcjTableNameFactory().makeTableName(RYA_TABLE_PREFIX, "testPcj");
final PcjTables pcjs = new PcjTables();
pcjs.createAndPopulatePcj(ryaConn, accumuloConn, pcjTableName, sparql, new String[] { "age", "name" }, Optional.<PcjVarOrderFactory>absent());
// Make sure the cardinality was updated.
final PcjMetadata metadata = pcjs.getPcjMetadata(accumuloConn, pcjTableName);
assertEquals(4, metadata.getCardinality());
}
use of org.openrdf.model.impl.URIImpl in project incubator-rya by apache.
the class MongoPcjDocumentsTest method metadataExists.
@Test
public void metadataExists() throws Exception {
final List<VariableOrder> varOrders = Lists.newArrayList(new VariableOrder("b", "a"), new VariableOrder("a", "b"));
final MongoPcjDocuments docConverter = new MongoPcjDocuments(getMongoClient(), conf.getRyaInstanceName());
final String sparql = "SELECT * WHERE { ?a <http://isA> ?b }";
docConverter.createPcj("pcjTest", sparql);
PcjMetadata actual = docConverter.getPcjMetadata("pcjTest");
PcjMetadata expected = new PcjMetadata(sparql, 0, varOrders);
assertEquals(expected, actual);
// Setup the binding set that will be converted.
final MapBindingSet originalBindingSet1 = new MapBindingSet();
originalBindingSet1.addBinding("x", new URIImpl("http://a"));
originalBindingSet1.addBinding("y", new URIImpl("http://b"));
originalBindingSet1.addBinding("z", new URIImpl("http://c"));
final VisibilityBindingSet results1 = new VisibilityBindingSet(originalBindingSet1, "A&B&C");
// Setup the binding set that will be converted.
final MapBindingSet originalBindingSet2 = new MapBindingSet();
originalBindingSet2.addBinding("x", new URIImpl("http://1"));
originalBindingSet2.addBinding("y", new URIImpl("http://2"));
originalBindingSet2.addBinding("z", new URIImpl("http://3"));
final VisibilityBindingSet results2 = new VisibilityBindingSet(originalBindingSet2, "A&B&C");
final List<VisibilityBindingSet> bindingSets = new ArrayList<>();
bindingSets.add(results1);
bindingSets.add(results2);
docConverter.addResults("pcjTest", bindingSets);
actual = docConverter.getPcjMetadata("pcjTest");
expected = new PcjMetadata(sparql, 2, varOrders);
assertEquals(expected, actual);
docConverter.purgePcjs("pcjTest");
actual = docConverter.getPcjMetadata("pcjTest");
expected = new PcjMetadata(sparql, 0, varOrders);
assertEquals(expected, actual);
}
use of org.openrdf.model.impl.URIImpl in project incubator-rya by apache.
the class PcjDocumentsIntegrationTest method listResults.
@Test
public void listResults() throws Exception {
final String sparql = "SELECT ?name ?age " + "{" + "FILTER(?age < 30) ." + "?name <http://hasAge> ?age." + "?name <http://playsSport> \"Soccer\" " + "}";
final String pcjTableName = "testPcj";
final MongoPcjDocuments pcjs = new MongoPcjDocuments(getMongoClient(), conf.getRyaInstanceName());
pcjs.createPcj(pcjTableName, sparql);
// Add a few results to the PCJ table.
final MapBindingSet alice = new MapBindingSet();
alice.addBinding("name", new URIImpl("http://Alice"));
alice.addBinding("age", new NumericLiteralImpl(14, XMLSchema.INTEGER));
final MapBindingSet bob = new MapBindingSet();
bob.addBinding("name", new URIImpl("http://Bob"));
bob.addBinding("age", new NumericLiteralImpl(16, XMLSchema.INTEGER));
final MapBindingSet charlie = new MapBindingSet();
charlie.addBinding("name", new URIImpl("http://Charlie"));
charlie.addBinding("age", new NumericLiteralImpl(12, XMLSchema.INTEGER));
pcjs.addResults(pcjTableName, Sets.<VisibilityBindingSet>newHashSet(new VisibilityBindingSet(alice), new VisibilityBindingSet(bob), new VisibilityBindingSet(charlie)));
// Fetch the Binding Sets that have been stored in the PCJ table.
final Set<BindingSet> results = new HashSet<>();
final CloseableIterator<BindingSet> resultsIt = pcjs.listResults(pcjTableName);
try {
while (resultsIt.hasNext()) {
results.add(resultsIt.next());
}
} finally {
resultsIt.close();
}
// Verify the fetched results match the expected ones.
final Set<BindingSet> expected = Sets.<BindingSet>newHashSet(alice, bob, charlie);
assertEquals(expected, results);
}
use of org.openrdf.model.impl.URIImpl in project incubator-rya by apache.
the class PcjDocumentsIntegrationTest method purge.
@Test
public void purge() throws Exception {
final String sparql = "SELECT ?name ?age " + "{" + "FILTER(?age < 30) ." + "?name <http://hasAge> ?age." + "?name <http://playsSport> \"Soccer\" " + "}";
final String pcjTableName = "testPcj";
final MongoPcjDocuments pcjs = new MongoPcjDocuments(getMongoClient(), conf.getRyaInstanceName());
pcjs.createPcj(pcjTableName, sparql);
// Add a few results to the PCJ table.
final MapBindingSet alice = new MapBindingSet();
alice.addBinding("name", new URIImpl("http://Alice"));
alice.addBinding("age", new NumericLiteralImpl(14, XMLSchema.INTEGER));
final MapBindingSet bob = new MapBindingSet();
bob.addBinding("name", new URIImpl("http://Bob"));
bob.addBinding("age", new NumericLiteralImpl(16, XMLSchema.INTEGER));
final MapBindingSet charlie = new MapBindingSet();
charlie.addBinding("name", new URIImpl("http://Charlie"));
charlie.addBinding("age", new NumericLiteralImpl(12, XMLSchema.INTEGER));
pcjs.addResults(pcjTableName, Sets.<VisibilityBindingSet>newHashSet(new VisibilityBindingSet(alice), new VisibilityBindingSet(bob), new VisibilityBindingSet(charlie)));
// Make sure the cardinality was updated.
PcjMetadata metadata = pcjs.getPcjMetadata(pcjTableName);
assertEquals(3, metadata.getCardinality());
// Purge the data.
pcjs.purgePcjs(pcjTableName);
// Make sure the cardinality was updated to 0.
metadata = pcjs.getPcjMetadata(pcjTableName);
assertEquals(0, metadata.getCardinality());
}
use of org.openrdf.model.impl.URIImpl in project incubator-rya by apache.
the class PcjDocumentsIntegrationTest method addResults.
/**
* Ensure when results have been written to the PCJ table that they are in Accumulo.
* <p>
* The method being tested is {@link PcjTables#addResults(Connector, String, java.util.Collection)}
*/
@Test
public void addResults() throws Exception {
final String sparql = "SELECT ?name ?age " + "{" + "FILTER(?age < 30) ." + "?name <http://hasAge> ?age." + "?name <http://playsSport> \"Soccer\" " + "}";
final String pcjTableName = "testPcj";
final MongoPcjDocuments pcjs = new MongoPcjDocuments(getMongoClient(), conf.getRyaInstanceName());
pcjs.createPcj(pcjTableName, sparql);
// Add a few results to the PCJ table.
final MapBindingSet alice = new MapBindingSet();
alice.addBinding("name", new URIImpl("http://Alice"));
alice.addBinding("age", new NumericLiteralImpl(14, XMLSchema.INTEGER));
final MapBindingSet bob = new MapBindingSet();
bob.addBinding("name", new URIImpl("http://Bob"));
bob.addBinding("age", new NumericLiteralImpl(16, XMLSchema.INTEGER));
final MapBindingSet charlie = new MapBindingSet();
charlie.addBinding("name", new URIImpl("http://Charlie"));
charlie.addBinding("age", new NumericLiteralImpl(12, XMLSchema.INTEGER));
final Set<BindingSet> expected = Sets.<BindingSet>newHashSet(alice, bob, charlie);
pcjs.addResults(pcjTableName, Sets.<VisibilityBindingSet>newHashSet(new VisibilityBindingSet(alice), new VisibilityBindingSet(bob), new VisibilityBindingSet(charlie)));
// Make sure the cardinality was updated.
final PcjMetadata metadata = pcjs.getPcjMetadata(pcjTableName);
assertEquals(3, metadata.getCardinality());
// Scan Accumulo for the stored results.
final Collection<BindingSet> fetchedResults = loadPcjResults(pcjTableName);
assertEquals(expected, fetchedResults);
}
Aggregations