Search in sources :

Example 96 with RyaURI

use of org.apache.rya.api.domain.RyaURI in project incubator-rya by apache.

the class MergeJoinTest method testSimpleMergeJoinPredicateOnly.

@Test
public void testSimpleMergeJoinPredicateOnly() throws Exception {
    // add data
    RyaURI pred1 = new RyaURI(litdupsNS, "pred1");
    RyaURI pred2 = new RyaURI(litdupsNS, "pred2");
    RyaType one = new RyaType("1");
    RyaURI subj1 = new RyaURI(litdupsNS, "subj1");
    RyaURI subj2 = new RyaURI(litdupsNS, "subj2");
    RyaURI subj3 = new RyaURI(litdupsNS, "subj3");
    RyaURI subj4 = new RyaURI(litdupsNS, "subj4");
    dao.add(new RyaStatement(subj1, pred1, one));
    dao.add(new RyaStatement(subj1, pred2, one));
    dao.add(new RyaStatement(subj2, pred1, one));
    dao.add(new RyaStatement(subj2, pred2, one));
    dao.add(new RyaStatement(subj3, pred1, one));
    dao.add(new RyaStatement(subj3, pred2, one));
    dao.add(new RyaStatement(subj4, pred1, one));
    dao.add(new RyaStatement(subj4, pred2, one));
    // 1 join
    MergeJoin mergeJoin = new MergeJoin(dao.getQueryEngine());
    CloseableIteration<RyaStatement, RyaDAOException> join = mergeJoin.join(null, pred1, pred2);
    int count = 0;
    while (join.hasNext()) {
        RyaStatement next = join.next();
        count++;
    }
    assertEquals(4, count);
    join.close();
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) MergeJoin(org.apache.rya.api.persist.query.join.MergeJoin) RyaType(org.apache.rya.api.domain.RyaType) Test(org.junit.Test)

Example 97 with RyaURI

use of org.apache.rya.api.domain.RyaURI in project incubator-rya by apache.

the class MergeJoinTest method testSimpleMergeJoin.

@Test
public void testSimpleMergeJoin() throws Exception {
    // add data
    RyaURI pred = new RyaURI(litdupsNS, "pred1");
    RyaType one = new RyaType("1");
    RyaType two = new RyaType("2");
    RyaURI subj1 = new RyaURI(litdupsNS, "subj1");
    RyaURI subj2 = new RyaURI(litdupsNS, "subj2");
    RyaURI subj3 = new RyaURI(litdupsNS, "subj3");
    RyaURI subj4 = new RyaURI(litdupsNS, "subj4");
    dao.add(new RyaStatement(subj1, pred, one));
    dao.add(new RyaStatement(subj1, pred, two));
    dao.add(new RyaStatement(subj2, pred, one));
    dao.add(new RyaStatement(subj2, pred, two));
    dao.add(new RyaStatement(subj3, pred, one));
    dao.add(new RyaStatement(subj3, pred, two));
    dao.add(new RyaStatement(subj4, pred, one));
    dao.add(new RyaStatement(subj4, pred, two));
    // 1 join
    MergeJoin mergeJoin = new MergeJoin(dao.getQueryEngine());
    CloseableIteration<RyaURI, RyaDAOException> join = mergeJoin.join(null, new CustomEntry<RyaURI, RyaType>(pred, one), new CustomEntry<RyaURI, RyaType>(pred, two));
    Set<RyaURI> uris = new HashSet<RyaURI>();
    while (join.hasNext()) {
        uris.add(join.next());
    }
    assertTrue(uris.contains(subj1));
    assertTrue(uris.contains(subj2));
    assertTrue(uris.contains(subj3));
    assertTrue(uris.contains(subj4));
    join.close();
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) MergeJoin(org.apache.rya.api.persist.query.join.MergeJoin) RyaType(org.apache.rya.api.domain.RyaType) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 98 with RyaURI

use of org.apache.rya.api.domain.RyaURI in project incubator-rya by apache.

the class MergeJoinTest method testSimpleMergeJoinMultiWay.

@Test
public void testSimpleMergeJoinMultiWay() throws Exception {
    // add data
    RyaURI pred = new RyaURI(litdupsNS, "pred1");
    RyaType one = new RyaType("1");
    RyaType two = new RyaType("2");
    RyaType three = new RyaType("3");
    RyaType four = new RyaType("4");
    RyaURI subj1 = new RyaURI(litdupsNS, "subj1");
    RyaURI subj2 = new RyaURI(litdupsNS, "subj2");
    RyaURI subj3 = new RyaURI(litdupsNS, "subj3");
    RyaURI subj4 = new RyaURI(litdupsNS, "subj4");
    dao.add(new RyaStatement(subj1, pred, one));
    dao.add(new RyaStatement(subj1, pred, two));
    dao.add(new RyaStatement(subj1, pred, three));
    dao.add(new RyaStatement(subj1, pred, four));
    dao.add(new RyaStatement(subj2, pred, one));
    dao.add(new RyaStatement(subj2, pred, two));
    dao.add(new RyaStatement(subj2, pred, three));
    dao.add(new RyaStatement(subj2, pred, four));
    dao.add(new RyaStatement(subj3, pred, one));
    dao.add(new RyaStatement(subj3, pred, two));
    dao.add(new RyaStatement(subj3, pred, three));
    dao.add(new RyaStatement(subj3, pred, four));
    dao.add(new RyaStatement(subj4, pred, one));
    dao.add(new RyaStatement(subj4, pred, two));
    dao.add(new RyaStatement(subj4, pred, three));
    dao.add(new RyaStatement(subj4, pred, four));
    // 1 join
    MergeJoin mergeJoin = new MergeJoin(dao.getQueryEngine());
    CloseableIteration<RyaURI, RyaDAOException> join = mergeJoin.join(null, new CustomEntry<RyaURI, RyaType>(pred, one), new CustomEntry<RyaURI, RyaType>(pred, two), new CustomEntry<RyaURI, RyaType>(pred, three), new CustomEntry<RyaURI, RyaType>(pred, four));
    Set<RyaURI> uris = new HashSet<RyaURI>();
    while (join.hasNext()) {
        uris.add(join.next());
    }
    assertTrue(uris.contains(subj1));
    assertTrue(uris.contains(subj2));
    assertTrue(uris.contains(subj3));
    assertTrue(uris.contains(subj4));
    join.close();
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) MergeJoin(org.apache.rya.api.persist.query.join.MergeJoin) RyaType(org.apache.rya.api.domain.RyaType) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 99 with RyaURI

use of org.apache.rya.api.domain.RyaURI in project incubator-rya by apache.

the class MergeJoinTest method testMergeJoinMultiWayNone2.

@Test
public void testMergeJoinMultiWayNone2() throws Exception {
    // add data
    RyaURI pred = new RyaURI(litdupsNS, "pred1");
    RyaType zero = new RyaType("0");
    RyaType one = new RyaType("1");
    RyaType two = new RyaType("2");
    RyaType three = new RyaType("3");
    RyaType four = new RyaType("4");
    RyaURI subj1 = new RyaURI(litdupsNS, "subj1");
    RyaURI subj2 = new RyaURI(litdupsNS, "subj2");
    RyaURI subj3 = new RyaURI(litdupsNS, "subj3");
    RyaURI subj4 = new RyaURI(litdupsNS, "subj4");
    dao.add(new RyaStatement(subj1, pred, one));
    dao.add(new RyaStatement(subj1, pred, four));
    dao.add(new RyaStatement(subj2, pred, zero));
    dao.add(new RyaStatement(subj2, pred, one));
    dao.add(new RyaStatement(subj2, pred, four));
    dao.add(new RyaStatement(subj3, pred, two));
    dao.add(new RyaStatement(subj3, pred, four));
    dao.add(new RyaStatement(subj4, pred, one));
    dao.add(new RyaStatement(subj4, pred, two));
    // 1 join
    MergeJoin mergeJoin = new MergeJoin(dao.getQueryEngine());
    CloseableIteration<RyaURI, RyaDAOException> join = mergeJoin.join(null, new CustomEntry<RyaURI, RyaType>(pred, one), new CustomEntry<RyaURI, RyaType>(pred, two), new CustomEntry<RyaURI, RyaType>(pred, three), new CustomEntry<RyaURI, RyaType>(pred, four));
    assertFalse(join.hasNext());
    join.close();
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) MergeJoin(org.apache.rya.api.persist.query.join.MergeJoin) RyaType(org.apache.rya.api.domain.RyaType) Test(org.junit.Test)

Example 100 with RyaURI

use of org.apache.rya.api.domain.RyaURI in project incubator-rya by apache.

the class StatementPatternEvalTest method simpleQueryWithBindingSetSameContext.

@Test
public void simpleQueryWithBindingSetSameContext() throws MalformedQueryException, QueryEvaluationException, RyaDAOException {
    // query is used to build statement that will be evaluated
    String query = "select ?x ?c where{ graph ?c  {?x <uri:talksTo> <uri:Bob>. }}";
    SPARQLParser parser = new SPARQLParser();
    ParsedQuery pq = parser.parseQuery(query, null);
    List<StatementPattern> spList = StatementPatternCollector.process(pq.getTupleExpr());
    RyaStatement statement1 = new RyaStatement(new RyaURI("uri:Joe"), new RyaURI("uri:talksTo"), new RyaType("uri:Bob"), new RyaURI("uri:context1"), "", new StatementMetadata());
    dao.add(statement1);
    RyaStatement statement2 = new RyaStatement(new RyaURI("uri:Doug"), new RyaURI("uri:talksTo"), new RyaType("uri:Bob"), new RyaURI("uri:context2"), "", new StatementMetadata());
    dao.add(statement2);
    RyaStatement statement3 = new RyaStatement(new RyaURI("uri:Eric"), new RyaURI("uri:talksTo"), new RyaType("uri:Bob"), new RyaURI("uri:context3"), "", new StatementMetadata());
    dao.add(statement3);
    QueryBindingSet bsConstraint1 = new QueryBindingSet();
    bsConstraint1.addBinding("c", new URIImpl("uri:context1"));
    QueryBindingSet bsConstraint2 = new QueryBindingSet();
    bsConstraint2.addBinding("c", new URIImpl("uri:context1"));
    CloseableIteration<BindingSet, QueryEvaluationException> iteration = eval.evaluate(spList.get(0), Arrays.asList(bsConstraint1, bsConstraint2));
    List<BindingSet> bsList = new ArrayList<>();
    while (iteration.hasNext()) {
        bsList.add(iteration.next());
    }
    Assert.assertEquals(1, bsList.size());
    QueryBindingSet expected = new QueryBindingSet();
    expected.addBinding("x", new URIImpl("uri:Joe"));
    expected.addBinding("c", new URIImpl("uri:context1"));
    Assert.assertEquals(expected, bsList.get(0));
    dao.delete(Arrays.asList(statement1, statement2, statement3).iterator(), conf);
}
Also used : QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) BindingSet(org.openrdf.query.BindingSet) SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) ParsedQuery(org.openrdf.query.parser.ParsedQuery) StatementMetadata(org.apache.rya.api.domain.StatementMetadata) ArrayList(java.util.ArrayList) RyaStatement(org.apache.rya.api.domain.RyaStatement) URIImpl(org.openrdf.model.impl.URIImpl) RyaType(org.apache.rya.api.domain.RyaType) QueryBindingSet(org.openrdf.query.algebra.evaluation.QueryBindingSet) StatementPattern(org.openrdf.query.algebra.StatementPattern) RyaURI(org.apache.rya.api.domain.RyaURI) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) Test(org.junit.Test)

Aggregations

RyaURI (org.apache.rya.api.domain.RyaURI)287 Test (org.junit.Test)190 RyaStatement (org.apache.rya.api.domain.RyaStatement)183 RyaType (org.apache.rya.api.domain.RyaType)146 BindingSet (org.openrdf.query.BindingSet)56 ArrayList (java.util.ArrayList)52 StatementPattern (org.openrdf.query.algebra.StatementPattern)50 QueryBindingSet (org.openrdf.query.algebra.evaluation.QueryBindingSet)49 HashSet (java.util.HashSet)43 RyaDAOException (org.apache.rya.api.persist.RyaDAOException)43 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)42 ParsedQuery (org.openrdf.query.parser.ParsedQuery)42 SPARQLParser (org.openrdf.query.parser.sparql.SPARQLParser)42 StatementMetadata (org.apache.rya.api.domain.StatementMetadata)35 Entity (org.apache.rya.indexing.entity.model.Entity)30 Property (org.apache.rya.indexing.entity.model.Property)28 URIImpl (org.openrdf.model.impl.URIImpl)25 EntityStorage (org.apache.rya.indexing.entity.storage.EntityStorage)22 AccumuloRdfConfiguration (org.apache.rya.accumulo.AccumuloRdfConfiguration)21 TripleRow (org.apache.rya.api.resolver.triple.TripleRow)21