Search in sources :

Example 91 with RyaURI

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

the class MongoEntityStorageIT method update.

@Test
public void update() throws Exception {
    final EntityStorage storage = new MongoEntityStorage(super.getMongoClient(), RYA_INSTANCE_NAME);
    // Store Alice in the repository.
    final Entity alice = Entity.builder().setSubject(new RyaURI("urn:SSN/111-11-1111")).setExplicitType(new RyaURI("urn:person")).setProperty(new RyaURI("urn:person"), new Property(new RyaURI("urn:name"), new RyaType(XMLSchema.STRING, "Alice"))).setProperty(new RyaURI("urn:person"), new Property(new RyaURI("urn:age"), new RyaType(XMLSchema.INT, "30"))).setProperty(new RyaURI("urn:person"), new Property(new RyaURI("urn:eye"), new RyaType(XMLSchema.STRING, "blue"))).build();
    storage.create(alice);
    // Show Alice was stored.
    Optional<Entity> latest = storage.get(new RyaURI("urn:SSN/111-11-1111"));
    assertEquals(alice, latest.get());
    // Change Alice's eye color to brown.
    final Entity updated = Entity.builder(alice).setVersion(latest.get().getVersion() + 1).setProperty(new RyaURI("urn:person"), new Property(new RyaURI("urn:eye"), new RyaType(XMLSchema.STRING, "brown"))).build();
    storage.update(alice, updated);
    // Fetch the Alice object and ensure it has the new value.
    latest = storage.get(new RyaURI("urn:SSN/111-11-1111"));
    assertEquals(updated, latest.get());
}
Also used : Entity(org.apache.rya.indexing.entity.model.Entity) TypedEntity(org.apache.rya.indexing.entity.model.TypedEntity) RyaURI(org.apache.rya.api.domain.RyaURI) EntityStorage(org.apache.rya.indexing.entity.storage.EntityStorage) RyaType(org.apache.rya.api.domain.RyaType) Property(org.apache.rya.indexing.entity.model.Property) Test(org.junit.Test)

Example 92 with RyaURI

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

the class MongoEntityStorageIT method update_differentSubjects.

@Test(expected = EntityStorageException.class)
public void update_differentSubjects() throws Exception {
    // Two objects that do not have the same Subjects.
    final Entity old = Entity.builder().setSubject(new RyaURI("urn:SSN/111-11-1111")).setExplicitType(new RyaURI("urn:person")).build();
    final Entity updated = Entity.builder().setSubject(new RyaURI("urn:SSN/222-22-2222")).setExplicitType(new RyaURI("urn:person")).build();
    // The update will fail.
    final EntityStorage storage = new MongoEntityStorage(super.getMongoClient(), RYA_INSTANCE_NAME);
    storage.update(old, updated);
}
Also used : Entity(org.apache.rya.indexing.entity.model.Entity) TypedEntity(org.apache.rya.indexing.entity.model.TypedEntity) RyaURI(org.apache.rya.api.domain.RyaURI) EntityStorage(org.apache.rya.indexing.entity.storage.EntityStorage) Test(org.junit.Test)

Example 93 with RyaURI

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

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

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

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