use of org.apache.rya.api.domain.RyaType in project incubator-rya by apache.
the class StatementPatternStorageTest method testContext.
public void testContext() throws Exception {
ryaDAO.add(new RyaStatement(new RyaURI(namespace, "a"), new RyaURI(namespace, "p"), new RyaType("l1")));
ryaDAO.add(new RyaStatement(new RyaURI(namespace, "a"), new RyaURI(namespace, "p"), new RyaType("l2"), new RyaURI(namespace, "g1")));
int count = 0;
List<StatementPatternStorage> storages = createStorages("accumulo://" + tablePrefix + "?instance=" + instance + "&user=" + user + "&password=" + pwd + "&predicate=<" + namespace + "p>&mock=true");
for (StatementPatternStorage storage : storages) {
while (true) {
Tuple next = storage.getNext();
if (next == null) {
break;
}
count++;
}
}
assertEquals(2, count);
count = 0;
storages = createStorages("accumulo://" + tablePrefix + "?instance=" + instance + "&user=" + user + "&password=" + pwd + "&predicate=<" + namespace + "p>&context=<" + namespace + "g1>&mock=true");
for (StatementPatternStorage storage : storages) {
while (true) {
Tuple next = storage.getNext();
if (next == null) {
break;
}
count++;
}
}
assertEquals(1, count);
ryaDAO.destroy();
}
use of org.apache.rya.api.domain.RyaType in project incubator-rya by apache.
the class StatementPatternStorage method createRange.
protected Map.Entry<TABLE_LAYOUT, Range> createRange(Value s_v, Value p_v, Value o_v) throws IOException {
RyaURI subject_rya = RdfToRyaConversions.convertResource((Resource) s_v);
RyaURI predicate_rya = RdfToRyaConversions.convertURI((URI) p_v);
RyaType object_rya = RdfToRyaConversions.convertValue(o_v);
TriplePatternStrategy strategy = ryaContext.retrieveStrategy(subject_rya, predicate_rya, object_rya, null);
if (strategy == null) {
return new RdfCloudTripleStoreUtils.CustomEntry<TABLE_LAYOUT, Range>(TABLE_LAYOUT.SPO, new Range());
}
Map.Entry<TABLE_LAYOUT, ByteRange> entry = strategy.defineRange(subject_rya, predicate_rya, object_rya, null, null);
ByteRange byteRange = entry.getValue();
return new RdfCloudTripleStoreUtils.CustomEntry<org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT, Range>(entry.getKey(), new Range(new Text(byteRange.getStart()), new Text(byteRange.getEnd())));
}
use of org.apache.rya.api.domain.RyaType 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();
}
use of org.apache.rya.api.domain.RyaType 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();
}
use of org.apache.rya.api.domain.RyaType 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();
}
Aggregations