use of org.apache.rya.indexing.entity.storage.mongo.MongoEntityStorage in project incubator-rya by apache.
the class EntityQueryNodeIT method evaluate_constantSubject.
@Test
public void evaluate_constantSubject() throws Exception {
final EntityStorage storage = new MongoEntityStorage(super.getMongoClient(), "testDB");
final ValueFactory vf = ValueFactoryImpl.getInstance();
final RyaURI subject = new RyaURI("urn:SSN:111-11-1111");
final Entity entity = Entity.builder().setSubject(subject).setExplicitType(PERSON_TYPE.getId()).setProperty(PERSON_TYPE.getId(), new Property(new RyaURI("urn:age"), RdfToRyaConversions.convertLiteral(vf.createLiteral(20)))).setProperty(PERSON_TYPE.getId(), new Property(new RyaURI("urn:eye"), RdfToRyaConversions.convertLiteral(vf.createLiteral("blue")))).setProperty(PERSON_TYPE.getId(), new Property(new RyaURI("urn:name"), RdfToRyaConversions.convertLiteral(vf.createLiteral("Bob")))).build();
storage.create(entity);
// A set of patterns that match a sepecific Entity subject.
final List<StatementPattern> patterns = getSPs("SELECT * WHERE { " + "<urn:SSN:111-11-1111> <" + RDF.TYPE + "> <urn:person> ." + "<urn:SSN:111-11-1111> <urn:age> ?age . " + "<urn:SSN:111-11-1111> <urn:eye> ?eye . " + "<urn:SSN:111-11-1111> <urn:name> ?name . " + "}");
final EntityQueryNode node = new EntityQueryNode(PERSON_TYPE, patterns, storage);
final CloseableIteration<BindingSet, QueryEvaluationException> rez = node.evaluate(new MapBindingSet());
final MapBindingSet expected = new MapBindingSet();
expected.addBinding("age", vf.createLiteral("20"));
expected.addBinding("eye", vf.createLiteral("blue"));
expected.addBinding("name", vf.createLiteral("Bob"));
while (rez.hasNext()) {
assertEquals(expected, rez.next());
break;
}
}
use of org.apache.rya.indexing.entity.storage.mongo.MongoEntityStorage in project incubator-rya by apache.
the class MongoEntityIndexerIT method deleteStatement_deletesType.
@Test
public void deleteStatement_deletesType() throws Exception {
try (MongoEntityIndexer indexer = new MongoEntityIndexer()) {
indexer.setConf(conf);
indexer.init();
// Load the type into the TypeStorage.
final TypeStorage types = new MongoTypeStorage(getMongoClient(), conf.getRyaInstanceName());
types.create(PERSON_TYPE);
types.create(EMPLOYEE_TYPE);
// Index a bunch of RyaStatements.
final RyaURI aliceSSN = new RyaURI("urn:SSN/111-11-1111");
indexer.storeStatements(Sets.newHashSet(new RyaStatement(aliceSSN, new RyaURI(RDF.TYPE.toString()), new RyaType(XMLSchema.ANYURI, "urn:person")), new RyaStatement(aliceSSN, new RyaURI("urn:name"), new RyaType(XMLSchema.STRING, "Alice")), new RyaStatement(aliceSSN, new RyaURI("urn:age"), new RyaType(XMLSchema.INT, "30")), new RyaStatement(aliceSSN, new RyaURI("urn:eye"), new RyaType(XMLSchema.STRING, "blue"))));
// Remove the explicit type from Alice.
indexer.deleteStatement(new RyaStatement(aliceSSN, new RyaURI(RDF.TYPE.toString()), new RyaType(XMLSchema.ANYURI, "urn:person")));
// Fetch the Entity from storage and ensure it looks correct.
final EntityStorage entities = new MongoEntityStorage(getMongoClient(), conf.getRyaInstanceName());
final Entity entity = entities.get(new RyaURI("urn:SSN/111-11-1111")).get();
final Entity expected = Entity.builder().setSubject(aliceSSN).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"))).setProperty(new RyaURI("urn:employee"), new Property(new RyaURI("urn:name"), new RyaType(XMLSchema.STRING, "Alice"))).setVersion(entity.getVersion()).build();
assertEquals(expected, entity);
}
}
use of org.apache.rya.indexing.entity.storage.mongo.MongoEntityStorage in project incubator-rya by apache.
the class MongoEntityIndexerIT method addStatement_manyUpdates.
@Test
public void addStatement_manyUpdates() throws Exception {
try (MongoEntityIndexer indexer = new MongoEntityIndexer()) {
indexer.setConf(conf);
indexer.init();
// Load the types into the TypeStorage.
final TypeStorage types = new MongoTypeStorage(getMongoClient(), conf.getRyaInstanceName());
types.create(PERSON_TYPE);
types.create(EMPLOYEE_TYPE);
// Index a bunch of RyaStatements.
final RyaURI aliceSSN = new RyaURI("urn:SSN/111-11-1111");
indexer.storeStatement(new RyaStatement(aliceSSN, new RyaURI(RDF.TYPE.toString()), new RyaType(XMLSchema.ANYURI, "urn:person")));
indexer.storeStatement(new RyaStatement(aliceSSN, new RyaURI("urn:name"), new RyaType(XMLSchema.STRING, "Alice")));
indexer.storeStatement(new RyaStatement(aliceSSN, new RyaURI("urn:age"), new RyaType(XMLSchema.INT, "30")));
indexer.storeStatement(new RyaStatement(aliceSSN, new RyaURI("urn:eye"), new RyaType(XMLSchema.STRING, "blue")));
// Fetch the Entity from storage and ensure it looks correct.
final EntityStorage entities = new MongoEntityStorage(getMongoClient(), conf.getRyaInstanceName());
final Entity entity = entities.get(new RyaURI("urn:SSN/111-11-1111")).get();
final Entity expected = Entity.builder().setSubject(aliceSSN).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"))).setProperty(new RyaURI("urn:employee"), new Property(new RyaURI("urn:name"), new RyaType(XMLSchema.STRING, "Alice"))).setVersion(entity.getVersion()).build();
assertEquals(expected, entity);
}
}
use of org.apache.rya.indexing.entity.storage.mongo.MongoEntityStorage in project incubator-rya by apache.
the class MongoEntityIndexerIT method addStatements.
@Test
public void addStatements() throws Exception {
try (MongoEntityIndexer indexer = new MongoEntityIndexer()) {
indexer.setConf(conf);
indexer.init();
// Load the types into the TypeStorage.
final TypeStorage types = new MongoTypeStorage(getMongoClient(), conf.getRyaInstanceName());
types.create(PERSON_TYPE);
types.create(EMPLOYEE_TYPE);
// Index a bunch of RyaStatements.
final RyaURI aliceSSN = new RyaURI("urn:SSN/111-11-1111");
final RyaURI bobSSN = new RyaURI("urn:SSN/222-22-2222");
indexer.storeStatements(Sets.newHashSet(new RyaStatement(aliceSSN, new RyaURI(RDF.TYPE.toString()), new RyaType(XMLSchema.ANYURI, "urn:person")), new RyaStatement(aliceSSN, new RyaURI("urn:name"), new RyaType(XMLSchema.STRING, "Alice")), new RyaStatement(aliceSSN, new RyaURI("urn:age"), new RyaType(XMLSchema.INT, "30")), new RyaStatement(aliceSSN, new RyaURI("urn:eye"), new RyaType(XMLSchema.STRING, "blue")), new RyaStatement(bobSSN, new RyaURI("urn:name"), new RyaType(XMLSchema.STRING, "Bob")), new RyaStatement(bobSSN, new RyaURI("urn:hoursPerWeek"), new RyaType(XMLSchema.INT, "40")), new RyaStatement(bobSSN, new RyaURI(RDF.TYPE.toString()), new RyaType(XMLSchema.ANYURI, "urn:employee"))));
// Fetch the Entity from storage and ensure it looks correct.
final EntityStorage entities = new MongoEntityStorage(getMongoClient(), conf.getRyaInstanceName());
final Entity alice = entities.get(aliceSSN).get();
final Entity bob = entities.get(bobSSN).get();
final Set<Entity> storedEntities = Sets.newHashSet(alice, bob);
final Entity expectedAlice = Entity.builder().setSubject(aliceSSN).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"))).setProperty(new RyaURI("urn:employee"), new Property(new RyaURI("urn:name"), new RyaType(XMLSchema.STRING, "Alice"))).setVersion(alice.getVersion()).build();
final Entity expectedBob = Entity.builder().setSubject(bobSSN).setExplicitType(new RyaURI("urn:employee")).setProperty(new RyaURI("urn:employee"), new Property(new RyaURI("urn:name"), new RyaType(XMLSchema.STRING, "Bob"))).setProperty(new RyaURI("urn:employee"), new Property(new RyaURI("urn:hoursPerWeek"), new RyaType(XMLSchema.INT, "40"))).setProperty(new RyaURI("urn:person"), new Property(new RyaURI("urn:name"), new RyaType(XMLSchema.STRING, "Bob"))).setVersion(bob.getVersion()).build();
final Set<Entity> expected = Sets.newHashSet(expectedAlice, expectedBob);
assertEquals(expected, storedEntities);
}
}
use of org.apache.rya.indexing.entity.storage.mongo.MongoEntityStorage in project incubator-rya by apache.
the class MongoEntityIndexerIT method deleteStatement_deletesProperty.
@Test
public void deleteStatement_deletesProperty() throws Exception {
try (MongoEntityIndexer indexer = new MongoEntityIndexer()) {
indexer.setConf(conf);
indexer.init();
// Load the type into the TypeStorage.
final TypeStorage types = new MongoTypeStorage(getMongoClient(), conf.getRyaInstanceName());
types.create(PERSON_TYPE);
types.create(EMPLOYEE_TYPE);
// Index a bunch of RyaStatements.
final RyaURI aliceSSN = new RyaURI("urn:SSN/111-11-1111");
indexer.storeStatements(Sets.newHashSet(new RyaStatement(aliceSSN, new RyaURI(RDF.TYPE.toString()), new RyaType(XMLSchema.ANYURI, "urn:person")), new RyaStatement(aliceSSN, new RyaURI("urn:name"), new RyaType(XMLSchema.STRING, "Alice")), new RyaStatement(aliceSSN, new RyaURI("urn:age"), new RyaType(XMLSchema.INT, "30")), new RyaStatement(aliceSSN, new RyaURI("urn:eye"), new RyaType(XMLSchema.STRING, "blue"))));
// Remove the name property from Alice.
indexer.deleteStatement(new RyaStatement(aliceSSN, new RyaURI("urn:name"), new RyaType(XMLSchema.STRING, "Alice")));
// Fetch the Entity from storage and ensure it looks correct.
final EntityStorage entities = new MongoEntityStorage(getMongoClient(), conf.getRyaInstanceName());
final Entity entity = entities.get(new RyaURI("urn:SSN/111-11-1111")).get();
final Entity expected = Entity.builder().setSubject(aliceSSN).setExplicitType(new RyaURI("urn:person")).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"))).setVersion(entity.getVersion()).build();
assertEquals(expected, entity);
}
}
Aggregations