use of org.apache.rya.api.domain.RyaStatement in project incubator-rya by apache.
the class StatementPatternEvalTest method simpleQueryWithoutBindingSets.
@Test
public void simpleQueryWithoutBindingSets() 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();
CloseableIteration<BindingSet, QueryEvaluationException> iteration = eval.evaluate(spList.get(0), Arrays.asList(bsConstraint1));
List<BindingSet> bsList = new ArrayList<>();
while (iteration.hasNext()) {
bsList.add(iteration.next());
}
Assert.assertEquals(3, bsList.size());
QueryBindingSet expected1 = new QueryBindingSet();
expected1.addBinding("x", new URIImpl("uri:Joe"));
expected1.addBinding("c", new URIImpl("uri:context1"));
QueryBindingSet expected2 = new QueryBindingSet();
expected2.addBinding("x", new URIImpl("uri:Doug"));
expected2.addBinding("c", new URIImpl("uri:context2"));
QueryBindingSet expected3 = new QueryBindingSet();
expected3.addBinding("x", new URIImpl("uri:Eric"));
expected3.addBinding("c", new URIImpl("uri:context3"));
Set<BindingSet> expected = new HashSet<>(Arrays.asList(expected1, expected2, expected3));
Set<BindingSet> actual = new HashSet<>(bsList);
Assert.assertEquals(expected, actual);
dao.delete(Arrays.asList(statement1, statement2, statement3).iterator(), conf);
}
use of org.apache.rya.api.domain.RyaStatement in project incubator-rya by apache.
the class IterativeJoinTest method testSimpleIterativeJoin.
@Test
public void testSimpleIterativeJoin() 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
IterativeJoin iterJoin = new IterativeJoin(dao.getQueryEngine());
CloseableIteration<RyaURI, RyaDAOException> join = iterJoin.join(null, new RdfCloudTripleStoreUtils.CustomEntry<RyaURI, RyaType>(pred, one), new RdfCloudTripleStoreUtils.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();
}
use of org.apache.rya.api.domain.RyaStatement in project incubator-rya by apache.
the class IterativeJoinTest method testSimpleIterativeJoinPredicateOnly2.
@Test
public void testSimpleIterativeJoinPredicateOnly2() throws Exception {
// add data
RyaURI pred1 = new RyaURI(litdupsNS, "pred1");
RyaURI pred2 = new RyaURI(litdupsNS, "pred2");
RyaType one = new RyaType("1");
RyaType two = new RyaType("2");
RyaType three = new RyaType("3");
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, pred1, two));
dao.add(new RyaStatement(subj1, pred1, three));
dao.add(new RyaStatement(subj1, pred2, one));
dao.add(new RyaStatement(subj1, pred2, two));
dao.add(new RyaStatement(subj1, pred2, three));
dao.add(new RyaStatement(subj2, pred1, one));
dao.add(new RyaStatement(subj2, pred1, two));
dao.add(new RyaStatement(subj2, pred1, three));
dao.add(new RyaStatement(subj2, pred2, one));
dao.add(new RyaStatement(subj2, pred2, two));
dao.add(new RyaStatement(subj2, pred2, three));
dao.add(new RyaStatement(subj3, pred1, one));
dao.add(new RyaStatement(subj3, pred1, two));
dao.add(new RyaStatement(subj3, pred1, three));
dao.add(new RyaStatement(subj3, pred2, one));
dao.add(new RyaStatement(subj3, pred2, two));
dao.add(new RyaStatement(subj3, pred2, three));
dao.add(new RyaStatement(subj4, pred1, one));
dao.add(new RyaStatement(subj4, pred1, two));
dao.add(new RyaStatement(subj4, pred1, three));
dao.add(new RyaStatement(subj4, pred2, one));
dao.add(new RyaStatement(subj4, pred2, two));
dao.add(new RyaStatement(subj4, pred2, three));
// 1 join
IterativeJoin ijoin = new IterativeJoin(dao.getQueryEngine());
CloseableIteration<RyaStatement, RyaDAOException> join = ijoin.join(null, pred1, pred2);
int count = 0;
while (join.hasNext()) {
RyaStatement next = join.next();
count++;
}
assertEquals(12, count);
join.close();
}
use of org.apache.rya.api.domain.RyaStatement in project incubator-rya by apache.
the class HashJoinTest 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
HashJoin hjoin = new HashJoin(dao.getQueryEngine());
CloseableIteration<RyaURI, RyaDAOException> join = hjoin.join(null, new RdfCloudTripleStoreUtils.CustomEntry<RyaURI, RyaType>(pred, one), new RdfCloudTripleStoreUtils.CustomEntry<RyaURI, RyaType>(pred, two), new RdfCloudTripleStoreUtils.CustomEntry<RyaURI, RyaType>(pred, three), new RdfCloudTripleStoreUtils.CustomEntry<RyaURI, RyaType>(pred, four));
assertFalse(join.hasNext());
join.close();
}
use of org.apache.rya.api.domain.RyaStatement in project incubator-rya by apache.
the class HashJoinTest method testSimpleMergeJoinPredicateOnly2.
@Test
public void testSimpleMergeJoinPredicateOnly2() throws Exception {
// add data
RyaURI pred1 = new RyaURI(litdupsNS, "pred1");
RyaURI pred2 = new RyaURI(litdupsNS, "pred2");
RyaType one = new RyaType("1");
RyaType two = new RyaType("2");
RyaType three = new RyaType("3");
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, pred1, two));
dao.add(new RyaStatement(subj1, pred1, three));
dao.add(new RyaStatement(subj1, pred2, one));
dao.add(new RyaStatement(subj1, pred2, two));
dao.add(new RyaStatement(subj1, pred2, three));
dao.add(new RyaStatement(subj2, pred1, one));
dao.add(new RyaStatement(subj2, pred1, two));
dao.add(new RyaStatement(subj2, pred1, three));
dao.add(new RyaStatement(subj2, pred2, one));
dao.add(new RyaStatement(subj2, pred2, two));
dao.add(new RyaStatement(subj2, pred2, three));
dao.add(new RyaStatement(subj3, pred1, one));
dao.add(new RyaStatement(subj3, pred1, two));
dao.add(new RyaStatement(subj3, pred1, three));
dao.add(new RyaStatement(subj3, pred2, one));
dao.add(new RyaStatement(subj3, pred2, two));
dao.add(new RyaStatement(subj3, pred2, three));
dao.add(new RyaStatement(subj4, pred1, one));
dao.add(new RyaStatement(subj4, pred1, two));
dao.add(new RyaStatement(subj4, pred1, three));
dao.add(new RyaStatement(subj4, pred2, one));
dao.add(new RyaStatement(subj4, pred2, two));
dao.add(new RyaStatement(subj4, pred2, three));
// 1 join
HashJoin ijoin = new HashJoin(dao.getQueryEngine());
CloseableIteration<RyaStatement, RyaDAOException> join = ijoin.join(null, pred1, pred2);
int count = 0;
while (join.hasNext()) {
RyaStatement next = join.next();
count++;
}
assertEquals(12, count);
join.close();
}
Aggregations