use of org.apache.rya.indexing.pcj.storage.accumulo.PcjTableNameFactory in project incubator-rya by apache.
the class PcjDocumentsIntegrationTest method listPcjs.
@Test
public void listPcjs() throws Exception {
// Set up the table names that will be used.
final String instance1 = "instance1_";
final String instance2 = "instance2_";
final String instance1_table1 = new PcjTableNameFactory().makeTableName(instance1, "table1");
final String instance1_table2 = new PcjTableNameFactory().makeTableName(instance1, "table2");
final String instance1_table3 = new PcjTableNameFactory().makeTableName(instance1, "table3");
final String instance2_table1 = new PcjTableNameFactory().makeTableName(instance2, "table1");
// Create the PCJ Tables that are in instance 1 and instance 2.
final String sparql = "SELECT ?x WHERE { ?x <http://isA> <http://Food> }";
final MongoPcjDocuments pcjs1 = new MongoPcjDocuments(getMongoClient(), instance1);
final MongoPcjDocuments pcjs2 = new MongoPcjDocuments(getMongoClient(), instance2);
pcjs1.createPcj(instance1_table1, sparql);
pcjs1.createPcj(instance1_table2, sparql);
pcjs1.createPcj(instance1_table3, sparql);
pcjs2.createPcj(instance2_table1, sparql);
// Ensure all of the names have been stored for instance 1 and 2.
final Set<String> expected1 = Sets.newHashSet(instance1_table1, instance1_table2, instance1_table3);
final Set<String> instance1Tables = Sets.newHashSet(pcjs1.listPcjDocuments());
assertEquals(expected1, instance1Tables);
final Set<String> expected2 = Sets.newHashSet(instance2_table1);
final Set<String> instance2Tables = Sets.newHashSet(pcjs2.listPcjDocuments());
assertEquals(expected2, instance2Tables);
}
use of org.apache.rya.indexing.pcj.storage.accumulo.PcjTableNameFactory in project incubator-rya by apache.
the class AccumuloIndexSetTest method accumuloIndexSetTestWithTwoDirectProductBindingSet.
@Test
public void accumuloIndexSetTestWithTwoDirectProductBindingSet() throws RepositoryException, PcjException, TableNotFoundException, RyaTypeResolverException, MalformedQueryException, SailException, QueryEvaluationException, AccumuloException, AccumuloSecurityException {
// 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 will include those triples in its results.
final String sparql = "SELECT ?name ?age " + "{" + "FILTER(?age < 30) ." + "?name <http://hasAge> ?age." + "?name <http://playsSport> \"Soccer\" " + "}";
final String pcjTableName = new PcjTableNameFactory().makeTableName(prefix, "testPcj");
// Create and populate the PCJ table.
PcjIntegrationTestingUtil.createAndPopulatePcj(ryaConn, accumuloConn, pcjTableName, sparql, new String[] { "name", "age" }, Optional.<PcjVarOrderFactory>absent());
final AccumuloIndexSet ais = new AccumuloIndexSet(conf, pcjTableName);
final QueryBindingSet bs = new QueryBindingSet();
bs.addBinding("birthDate", new LiteralImpl("1983-03-17", new URIImpl("http://www.w3.org/2001/XMLSchema#date")));
bs.addBinding("location", new URIImpl("http://Virginia"));
final QueryBindingSet bs2 = new QueryBindingSet();
bs2.addBinding("birthDate", new LiteralImpl("1983-04-18", new URIImpl("http://www.w3.org/2001/XMLSchema#date")));
bs2.addBinding("location", new URIImpl("http://Georgia"));
final Set<BindingSet> bSets = Sets.<BindingSet>newHashSet(bs, bs2);
final CloseableIteration<BindingSet, QueryEvaluationException> results = ais.evaluate(bSets);
final QueryBindingSet alice1 = new QueryBindingSet();
alice1.addBinding("name", new URIImpl("http://Alice"));
alice1.addBinding("age", new NumericLiteralImpl(14, XMLSchema.INTEGER));
alice1.addAll(bs);
final QueryBindingSet bob1 = new QueryBindingSet();
bob1.addBinding("name", new URIImpl("http://Bob"));
bob1.addBinding("age", new NumericLiteralImpl(16, XMLSchema.INTEGER));
bob1.addAll(bs);
final QueryBindingSet charlie1 = new QueryBindingSet();
charlie1.addBinding("name", new URIImpl("http://Charlie"));
charlie1.addBinding("age", new NumericLiteralImpl(12, XMLSchema.INTEGER));
charlie1.addAll(bs);
final QueryBindingSet alice2 = new QueryBindingSet();
alice2.addBinding("name", new URIImpl("http://Alice"));
alice2.addBinding("age", new NumericLiteralImpl(14, XMLSchema.INTEGER));
alice2.addAll(bs2);
final QueryBindingSet bob2 = new QueryBindingSet();
bob2.addBinding("name", new URIImpl("http://Bob"));
bob2.addBinding("age", new NumericLiteralImpl(16, XMLSchema.INTEGER));
bob2.addAll(bs2);
final QueryBindingSet charlie2 = new QueryBindingSet();
charlie2.addBinding("name", new URIImpl("http://Charlie"));
charlie2.addBinding("age", new NumericLiteralImpl(12, XMLSchema.INTEGER));
charlie2.addAll(bs2);
final Set<BindingSet> fetchedResults = new HashSet<>();
while (results.hasNext()) {
final BindingSet next = results.next();
System.out.println(next);
fetchedResults.add(next);
}
Assert.assertEquals(Sets.<BindingSet>newHashSet(alice1, bob1, charlie1, alice2, bob2, charlie2), fetchedResults);
}
use of org.apache.rya.indexing.pcj.storage.accumulo.PcjTableNameFactory in project incubator-rya by apache.
the class AccumuloIndexSetTest method accumuloIndexSetTestWithEmptyBindingSet.
/**
* TODO doc
* @throws QueryEvaluationException
* @throws SailException
* @throws MalformedQueryException
* @throws AccumuloSecurityException
* @throws AccumuloException
*/
@Test
public void accumuloIndexSetTestWithEmptyBindingSet() throws RepositoryException, PcjException, TableNotFoundException, RyaTypeResolverException, MalformedQueryException, SailException, QueryEvaluationException, AccumuloException, AccumuloSecurityException {
// 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 will include those triples in its results.
final String sparql = "SELECT ?name ?age " + "{" + "FILTER(?age < 30) ." + "?name <http://hasAge> ?age." + "?name <http://playsSport> \"Soccer\" " + "}";
final String pcjTableName = new PcjTableNameFactory().makeTableName(prefix, "testPcj");
// Create and populate the PCJ table.
PcjIntegrationTestingUtil.createAndPopulatePcj(ryaConn, accumuloConn, pcjTableName, sparql, new String[] { "name", "age" }, Optional.<PcjVarOrderFactory>absent());
final AccumuloIndexSet ais = new AccumuloIndexSet(conf, pcjTableName);
final CloseableIteration<BindingSet, QueryEvaluationException> results = ais.evaluate(new QueryBindingSet());
final Set<BindingSet> fetchedResults = new HashSet<BindingSet>();
while (results.hasNext()) {
fetchedResults.add(results.next());
}
// Ensure the expected results match those that were stored.
final QueryBindingSet alice = new QueryBindingSet();
alice.addBinding("name", new URIImpl("http://Alice"));
alice.addBinding("age", new NumericLiteralImpl(14, XMLSchema.INTEGER));
final QueryBindingSet bob = new QueryBindingSet();
bob.addBinding("name", new URIImpl("http://Bob"));
bob.addBinding("age", new NumericLiteralImpl(16, XMLSchema.INTEGER));
final QueryBindingSet charlie = new QueryBindingSet();
charlie.addBinding("name", new URIImpl("http://Charlie"));
charlie.addBinding("age", new NumericLiteralImpl(12, XMLSchema.INTEGER));
final Set<BindingSet> expectedResults = Sets.<BindingSet>newHashSet(alice, bob, charlie);
Assert.assertEquals(expectedResults, fetchedResults);
}
use of org.apache.rya.indexing.pcj.storage.accumulo.PcjTableNameFactory in project incubator-rya by apache.
the class AccumuloIndexSetTest method accumuloIndexSetTestWithTwoBindingSets.
@Test
public void accumuloIndexSetTestWithTwoBindingSets() throws RepositoryException, PcjException, TableNotFoundException, RyaTypeResolverException, MalformedQueryException, SailException, QueryEvaluationException, AccumuloException, AccumuloSecurityException {
// 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 will include those triples in its results.
final String sparql = "SELECT ?name ?age " + "{" + "FILTER(?age < 30) ." + "?name <http://hasAge> ?age." + "?name <http://playsSport> \"Soccer\" " + "}";
final String pcjTableName = new PcjTableNameFactory().makeTableName(prefix, "testPcj");
// Create and populate the PCJ table.
PcjIntegrationTestingUtil.createAndPopulatePcj(ryaConn, accumuloConn, pcjTableName, sparql, new String[] { "name", "age" }, Optional.<PcjVarOrderFactory>absent());
final AccumuloIndexSet ais = new AccumuloIndexSet(conf, pcjTableName);
final QueryBindingSet bs = new QueryBindingSet();
bs.addBinding("birthDate", new LiteralImpl("1983-03-17", new URIImpl("http://www.w3.org/2001/XMLSchema#date")));
bs.addBinding("name", new URIImpl("http://Alice"));
final QueryBindingSet bs2 = new QueryBindingSet();
bs2.addBinding("birthDate", new LiteralImpl("1983-04-18", new URIImpl("http://www.w3.org/2001/XMLSchema#date")));
bs2.addBinding("name", new URIImpl("http://Bob"));
final Set<BindingSet> bSets = Sets.<BindingSet>newHashSet(bs, bs2);
final CloseableIteration<BindingSet, QueryEvaluationException> results = ais.evaluate(bSets);
final QueryBindingSet alice = new QueryBindingSet();
alice.addBinding("name", new URIImpl("http://Alice"));
alice.addBinding("age", new NumericLiteralImpl(14, XMLSchema.INTEGER));
alice.addBinding("birthDate", new LiteralImpl("1983-03-17", new URIImpl("http://www.w3.org/2001/XMLSchema#date")));
final QueryBindingSet bob = new QueryBindingSet();
bob.addBinding("name", new URIImpl("http://Bob"));
bob.addBinding("age", new NumericLiteralImpl(16, XMLSchema.INTEGER));
bob.addBinding("birthDate", new LiteralImpl("1983-04-18", new URIImpl("http://www.w3.org/2001/XMLSchema#date")));
final Set<BindingSet> fetchedResults = new HashSet<>();
while (results.hasNext()) {
final BindingSet next = results.next();
System.out.println(next);
fetchedResults.add(next);
}
Assert.assertEquals(Sets.<BindingSet>newHashSet(alice, bob), fetchedResults);
}
use of org.apache.rya.indexing.pcj.storage.accumulo.PcjTableNameFactory in project incubator-rya by apache.
the class AccumuloIndexSetTest method accumuloIndexSetTestWithTwoDirectProductBindingSetsWithMapping.
@Test
public void accumuloIndexSetTestWithTwoDirectProductBindingSetsWithMapping() throws RepositoryException, PcjException, TableNotFoundException, RyaTypeResolverException, MalformedQueryException, SailException, QueryEvaluationException, AccumuloException, AccumuloSecurityException {
// 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 will include those triples in its results.
final String sparql = "SELECT ?name ?age " + "{" + "FILTER(?age < 30) ." + "?name <http://hasAge> ?age." + "?name <http://playsSport> \"Soccer\" " + "}";
final String pcjTableName = new PcjTableNameFactory().makeTableName(prefix, "testPcj");
// Create and populate the PCJ table.
PcjIntegrationTestingUtil.createAndPopulatePcj(ryaConn, accumuloConn, pcjTableName, sparql, new String[] { "name", "age" }, Optional.<PcjVarOrderFactory>absent());
final String sparql2 = "SELECT ?x ?y " + "{" + "FILTER(?y < 30) ." + "?x <http://hasAge> ?y." + "?x <http://playsSport> \"Soccer\" " + "}";
final SPARQLParser p = new SPARQLParser();
final ParsedQuery pq = p.parseQuery(sparql2, null);
final Map<String, String> map = new HashMap<>();
map.put("x", "name");
map.put("y", "age");
final AccumuloIndexSet ais = new AccumuloIndexSet(conf, pcjTableName);
ais.setProjectionExpr((Projection) pq.getTupleExpr());
ais.setTableVarMap(map);
ais.setSupportedVariableOrderMap(Lists.<String>newArrayList("x;y", "y;x"));
final QueryBindingSet bs = new QueryBindingSet();
bs.addBinding("birthDate", new LiteralImpl("1983-03-17", new URIImpl("http://www.w3.org/2001/XMLSchema#date")));
bs.addBinding("x", new URIImpl("http://Alice"));
final QueryBindingSet bs2 = new QueryBindingSet();
bs2.addBinding("birthDate", new LiteralImpl("1983-04-18", new URIImpl("http://www.w3.org/2001/XMLSchema#date")));
bs2.addBinding("x", new URIImpl("http://Bob"));
final Set<BindingSet> bSets = Sets.<BindingSet>newHashSet(bs, bs2);
final CloseableIteration<BindingSet, QueryEvaluationException> results = ais.evaluate(bSets);
final QueryBindingSet alice = new QueryBindingSet();
alice.addBinding("x", new URIImpl("http://Alice"));
alice.addBinding("y", new NumericLiteralImpl(14, XMLSchema.INTEGER));
alice.addBinding("birthDate", new LiteralImpl("1983-03-17", new URIImpl("http://www.w3.org/2001/XMLSchema#date")));
final QueryBindingSet bob = new QueryBindingSet();
bob.addBinding("x", new URIImpl("http://Bob"));
bob.addBinding("y", new NumericLiteralImpl(16, XMLSchema.INTEGER));
bob.addBinding("birthDate", new LiteralImpl("1983-04-18", new URIImpl("http://www.w3.org/2001/XMLSchema#date")));
final Set<BindingSet> fetchedResults = new HashSet<>();
while (results.hasNext()) {
final BindingSet next = results.next();
System.out.println(next);
fetchedResults.add(next);
}
Assert.assertEquals(Sets.<BindingSet>newHashSet(alice, bob), fetchedResults);
}
Aggregations