Search in sources :

Example 61 with RyaType

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();
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) RyaStatement(org.apache.rya.api.domain.RyaStatement) RyaType(org.apache.rya.api.domain.RyaType) Tuple(org.apache.pig.data.Tuple)

Example 62 with RyaType

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())));
}
Also used : TriplePatternStrategy(org.apache.rya.api.query.strategy.TriplePatternStrategy) ByteRange(org.apache.rya.api.query.strategy.ByteRange) Text(org.apache.hadoop.io.Text) RyaType(org.apache.rya.api.domain.RyaType) Range(org.apache.accumulo.core.data.Range) ByteRange(org.apache.rya.api.query.strategy.ByteRange) RyaURI(org.apache.rya.api.domain.RyaURI) TABLE_LAYOUT(org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT) Map(java.util.Map)

Example 63 with RyaType

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();
}
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 64 with RyaType

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();
}
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 65 with RyaType

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();
}
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)

Aggregations

RyaType (org.apache.rya.api.domain.RyaType)178 RyaURI (org.apache.rya.api.domain.RyaURI)146 RyaStatement (org.apache.rya.api.domain.RyaStatement)115 Test (org.junit.Test)109 BindingSet (org.openrdf.query.BindingSet)42 QueryBindingSet (org.openrdf.query.algebra.evaluation.QueryBindingSet)42 ArrayList (java.util.ArrayList)35 StatementPattern (org.openrdf.query.algebra.StatementPattern)35 ParsedQuery (org.openrdf.query.parser.ParsedQuery)35 SPARQLParser (org.openrdf.query.parser.sparql.SPARQLParser)35 StatementMetadata (org.apache.rya.api.domain.StatementMetadata)34 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)34 RyaDAOException (org.apache.rya.api.persist.RyaDAOException)28 Property (org.apache.rya.indexing.entity.model.Property)23 URIImpl (org.openrdf.model.impl.URIImpl)23 HashSet (java.util.HashSet)22 Entity (org.apache.rya.indexing.entity.model.Entity)20 Value (org.openrdf.model.Value)19 LiteralImpl (org.openrdf.model.impl.LiteralImpl)19 BatchWriter (org.apache.accumulo.core.client.BatchWriter)18