Search in sources :

Example 81 with RyaStatement

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

the class EntityCentricIndexTest method testDeserializeSubjectRow.

@Test
public void testDeserializeSubjectRow() throws RyaTypeResolverException, IOException {
    RyaStatement deserialized = EntityCentricIndex.deserializeStatement(subjectCentricKey, value);
    Assert.assertEquals("Deserialization of subject-centric row failed to produce equivalent RyaStatement.", ryaStatement, deserialized);
}
Also used : RyaStatement(org.apache.rya.api.domain.RyaStatement) Test(org.junit.Test)

Example 82 with RyaStatement

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

the class StatementPatternStorageTest method testSimplePredicateRange.

public void testSimplePredicateRange() throws Exception {
    ryaDAO.add(new RyaStatement(new RyaURI(namespace, "a"), new RyaURI(namespace, "p"), new RyaType("l")));
    ryaDAO.add(new RyaStatement(new RyaURI(namespace, "b"), new RyaURI(namespace, "p"), new RyaType("l")));
    ryaDAO.add(new RyaStatement(new RyaURI(namespace, "c"), new RyaURI(namespace, "n"), new RyaType("l")));
    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);
    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 83 with RyaStatement

use of org.apache.rya.api.domain.RyaStatement 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 84 with RyaStatement

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

the class StatementPatternStorage method getNext.

@Override
public Tuple getNext() throws IOException {
    try {
        if (reader.nextKeyValue()) {
            Key key = (Key) reader.getCurrentKey();
            org.apache.accumulo.core.data.Value value = (org.apache.accumulo.core.data.Value) reader.getCurrentValue();
            ByteArrayDataInput input = ByteStreams.newDataInput(key.getRow().getBytes());
            RyaStatement ryaStatement = ryaContext.deserializeTriple(layout, new TripleRow(key.getRow().getBytes(), key.getColumnFamily().getBytes(), key.getColumnQualifier().getBytes()));
            Tuple tuple = TupleFactory.getInstance().newTuple(7);
            tuple.set(0, ryaStatement.getSubject().getData());
            tuple.set(1, ryaStatement.getPredicate().getData());
            tuple.set(2, ryaStatement.getObject().getData());
            tuple.set(3, (ryaStatement.getContext() != null) ? (ryaStatement.getContext().getData()) : (null));
            tuple.set(4, ryaStatement.getSubject().getDataType());
            tuple.set(5, ryaStatement.getPredicate().getDataType());
            tuple.set(6, ryaStatement.getObject().getDataType());
            return tuple;
        }
    } catch (Exception e) {
        throw new IOException(e);
    }
    return null;
}
Also used : RyaStatement(org.apache.rya.api.domain.RyaStatement) IOException(java.io.IOException) ByteArrayDataInput(com.google.common.io.ByteArrayDataInput) InferenceEngineException(org.apache.rya.rdftriplestore.inference.InferenceEngineException) MalformedQueryException(org.openrdf.query.MalformedQueryException) IOException(java.io.IOException) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) TripleRow(org.apache.rya.api.resolver.triple.TripleRow) Value(org.openrdf.model.Value) Key(org.apache.accumulo.core.data.Key) Tuple(org.apache.pig.data.Tuple)

Example 85 with RyaStatement

use of org.apache.rya.api.domain.RyaStatement 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)

Aggregations

RyaStatement (org.apache.rya.api.domain.RyaStatement)327 RyaURI (org.apache.rya.api.domain.RyaURI)184 Test (org.junit.Test)179 RyaType (org.apache.rya.api.domain.RyaType)115 RyaDAOException (org.apache.rya.api.persist.RyaDAOException)63 BindingSet (org.openrdf.query.BindingSet)58 QueryBindingSet (org.openrdf.query.algebra.evaluation.QueryBindingSet)49 ArrayList (java.util.ArrayList)47 TripleRow (org.apache.rya.api.resolver.triple.TripleRow)42 StatementPattern (org.openrdf.query.algebra.StatementPattern)40 HashSet (java.util.HashSet)39 ParsedQuery (org.openrdf.query.parser.ParsedQuery)39 SPARQLParser (org.openrdf.query.parser.sparql.SPARQLParser)39 StatementMetadata (org.apache.rya.api.domain.StatementMetadata)36 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)36 Map (java.util.Map)33 Statement (org.openrdf.model.Statement)27 Key (org.apache.accumulo.core.data.Key)21 AccumuloRdfConfiguration (org.apache.rya.accumulo.AccumuloRdfConfiguration)21 Value (org.apache.accumulo.core.data.Value)20