use of org.openrdf.query.algebra.evaluation.QueryBindingSet in project incubator-rya by apache.
the class AccumuloPeriodicQueryResultStorageIT method testAddListDelete.
@Test
public void testAddListDelete() throws Exception {
String sparql = "select ?x where { ?x <urn:pred> ?y.}";
String id = periodicStorage.createPeriodicQuery(sparql);
Set<BindingSet> expected = new HashSet<>();
Set<VisibilityBindingSet> storageSet = new HashSet<>();
// add result matching user's visibility
QueryBindingSet bs = new QueryBindingSet();
bs.addBinding("periodicBinId", vf.createLiteral(1L));
bs.addBinding("x", vf.createURI("uri:uri123"));
expected.add(bs);
storageSet.add(new VisibilityBindingSet(bs, "U"));
// add result with different visibility that is not expected
bs = new QueryBindingSet();
bs.addBinding("periodicBinId", vf.createLiteral(1L));
bs.addBinding("x", vf.createURI("uri:uri456"));
storageSet.add(new VisibilityBindingSet(bs, "V"));
periodicStorage.addPeriodicQueryResults(id, storageSet);
Set<BindingSet> actual = new HashSet<>();
try (CloseableIterator<BindingSet> iter = periodicStorage.listResults(id, Optional.of(1L))) {
iter.forEachRemaining(x -> actual.add(x));
}
Assert.assertEquals(expected, actual);
periodicStorage.deletePeriodicQueryResults(id, 1L);
Set<BindingSet> actual2 = new HashSet<>();
try (CloseableIterator<BindingSet> iter = periodicStorage.listResults(id, Optional.of(1L))) {
iter.forEachRemaining(x -> actual2.add(x));
}
Assert.assertEquals(new HashSet<>(), actual2);
periodicStorage.deletePeriodicQuery(id);
}
use of org.openrdf.query.algebra.evaluation.QueryBindingSet in project incubator-rya by apache.
the class CopyRule method accept.
/**
* Return whether a concrete statement satisfies a condition.
* @param stmt A statement from the input
* @param condition The condition to test. Expects variables expressed using the standard variable
* names used by this class, so it must be a rule's condition or derived from rules' conditions.
* @param strategy The evaluation strategy to apply
* @return True if the statement matches the condition
* @throws ValueExprEvaluationException
* @throws QueryEvaluationException
*/
public static boolean accept(final Statement stmt, final ValueExpr condition, final EvaluationStrategy strategy) throws ValueExprEvaluationException, QueryEvaluationException {
final QueryBindingSet bindings = new QueryBindingSet();
bindings.addBinding(SUBJ_VAR.getName(), stmt.getSubject());
bindings.addBinding(PRED_VAR.getName(), stmt.getPredicate());
bindings.addBinding(OBJ_VAR.getName(), stmt.getObject());
if (stmt.getContext() != null) {
bindings.addBinding(CON_VAR.getName(), stmt.getContext());
}
return strategy.isTrue(condition, bindings);
}
use of org.openrdf.query.algebra.evaluation.QueryBindingSet 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.openrdf.query.algebra.evaluation.QueryBindingSet 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.openrdf.query.algebra.evaluation.QueryBindingSet 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);
}
Aggregations