Search in sources :

Example 16 with PcjTableNameFactory

use of org.apache.rya.indexing.pcj.storage.accumulo.PcjTableNameFactory in project incubator-rya by apache.

the class AccumuloIndexSetTest method accumuloIndexSetTestWithNoBindingSet.

@Test
public void accumuloIndexSetTestWithNoBindingSet() 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 HashSet<BindingSet>());
    Assert.assertEquals(false, results.hasNext());
}
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) 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 17 with PcjTableNameFactory

use of org.apache.rya.indexing.pcj.storage.accumulo.PcjTableNameFactory in project incubator-rya by apache.

the class AccumuloIndexSetTest method accumuloIndexSetTestAttemptJoinAccrossTypes.

@Test
public void accumuloIndexSetTestAttemptJoinAccrossTypes() throws Exception {
    // 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")));
    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 " + "{" + "?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 bs1 = new QueryBindingSet();
    bs1.addBinding("age", new LiteralImpl("16"));
    final QueryBindingSet bs2 = new QueryBindingSet();
    bs2.addBinding("age", new NumericLiteralImpl(14, XMLSchema.INTEGER));
    final Set<BindingSet> bSets = Sets.<BindingSet>newHashSet(bs1, bs2);
    final CloseableIteration<BindingSet, QueryEvaluationException> results = ais.evaluate(bSets);
    final Set<BindingSet> fetchedResults = new HashSet<>();
    while (results.hasNext()) {
        final BindingSet next = results.next();
        fetchedResults.add(next);
    }
    bs2.addBinding("name", new URIImpl("http://Alice"));
    Assert.assertEquals(Sets.<BindingSet>newHashSet(bs2), 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

PcjTableNameFactory (org.apache.rya.indexing.pcj.storage.accumulo.PcjTableNameFactory)17 Test (org.junit.Test)14 HashSet (java.util.HashSet)12 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)12 NumericLiteralImpl (org.openrdf.model.impl.NumericLiteralImpl)11 URIImpl (org.openrdf.model.impl.URIImpl)11 BindingSet (org.openrdf.query.BindingSet)11 QueryBindingSet (org.openrdf.query.algebra.evaluation.QueryBindingSet)11 Statement (org.openrdf.model.Statement)10 LiteralImpl (org.openrdf.model.impl.LiteralImpl)10 StatementImpl (org.openrdf.model.impl.StatementImpl)10 Connector (org.apache.accumulo.core.client.Connector)2 Authorizations (org.apache.accumulo.core.security.Authorizations)2 VisibilityBindingSet (org.apache.rya.api.model.VisibilityBindingSet)2 PrecomputedJoinStorage (org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage)2 AccumuloPcjStorage (org.apache.rya.indexing.pcj.storage.accumulo.AccumuloPcjStorage)2 RyaSailRepository (org.apache.rya.rdftriplestore.RyaSailRepository)2 ParsedQuery (org.openrdf.query.parser.ParsedQuery)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1