Search in sources :

Example 86 with QueryBindingSet

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);
}
Also used : MapBindingSet(org.openrdf.query.impl.MapBindingSet) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) BindingSet(org.openrdf.query.BindingSet) VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 87 with QueryBindingSet

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);
}
Also used : QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet)

Example 88 with QueryBindingSet

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);
}
Also used : QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) BindingSet(org.openrdf.query.BindingSet) Statement(org.openrdf.model.Statement) URIImpl(org.openrdf.model.impl.URIImpl) PcjTableNameFactory(org.apache.rya.indexing.pcj.storage.accumulo.PcjTableNameFactory) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) LiteralImpl(org.openrdf.model.impl.LiteralImpl) NumericLiteralImpl(org.openrdf.model.impl.NumericLiteralImpl) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) NumericLiteralImpl(org.openrdf.model.impl.NumericLiteralImpl) StatementImpl(org.openrdf.model.impl.StatementImpl) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 89 with QueryBindingSet

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);
}
Also used : QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) BindingSet(org.openrdf.query.BindingSet) Statement(org.openrdf.model.Statement) URIImpl(org.openrdf.model.impl.URIImpl) PcjTableNameFactory(org.apache.rya.indexing.pcj.storage.accumulo.PcjTableNameFactory) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) LiteralImpl(org.openrdf.model.impl.LiteralImpl) NumericLiteralImpl(org.openrdf.model.impl.NumericLiteralImpl) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) NumericLiteralImpl(org.openrdf.model.impl.NumericLiteralImpl) StatementImpl(org.openrdf.model.impl.StatementImpl) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 90 with QueryBindingSet

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);
}
Also used : QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) BindingSet(org.openrdf.query.BindingSet) Statement(org.openrdf.model.Statement) URIImpl(org.openrdf.model.impl.URIImpl) PcjTableNameFactory(org.apache.rya.indexing.pcj.storage.accumulo.PcjTableNameFactory) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) LiteralImpl(org.openrdf.model.impl.LiteralImpl) NumericLiteralImpl(org.openrdf.model.impl.NumericLiteralImpl) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) NumericLiteralImpl(org.openrdf.model.impl.NumericLiteralImpl) StatementImpl(org.openrdf.model.impl.StatementImpl) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

QueryBindingSet (org.openrdf.query.algebra.evaluation.QueryBindingSet)107 Test (org.junit.Test)84 BindingSet (org.openrdf.query.BindingSet)79 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)52 RyaURI (org.apache.rya.api.domain.RyaURI)46 RyaStatement (org.apache.rya.api.domain.RyaStatement)45 SPARQLParser (org.openrdf.query.parser.sparql.SPARQLParser)42 StatementPattern (org.openrdf.query.algebra.StatementPattern)41 ParsedQuery (org.openrdf.query.parser.ParsedQuery)41 RyaType (org.apache.rya.api.domain.RyaType)39 LiteralImpl (org.openrdf.model.impl.LiteralImpl)32 ArrayList (java.util.ArrayList)30 HashSet (java.util.HashSet)28 URIImpl (org.openrdf.model.impl.URIImpl)27 StatementMetadata (org.apache.rya.api.domain.StatementMetadata)26 VisibilityBindingSet (org.apache.rya.api.model.VisibilityBindingSet)20 StatementMetadataNode (org.apache.rya.indexing.statement.metadata.matching.StatementMetadataNode)15 Statement (org.openrdf.model.Statement)15 TupleExpr (org.openrdf.query.algebra.TupleExpr)14 Collection (java.util.Collection)13