use of org.apache.rya.api.domain.RyaStatement in project incubator-rya by apache.
the class MongoDBRyaDAOIT method testDeleteWildcardSubjectWithContext.
@Test
public void testDeleteWildcardSubjectWithContext() throws RyaDAOException, MongoException, IOException {
final MongoDBRyaDAO dao = new MongoDBRyaDAO();
try {
dao.setConf(conf);
dao.init();
final RyaStatementBuilder builder = new RyaStatementBuilder();
builder.setPredicate(new RyaURI("http://temp.com"));
builder.setSubject(new RyaURI("http://subject.com"));
builder.setObject(new RyaURI("http://object.com"));
builder.setContext(new RyaURI("http://context.com"));
builder.setColumnVisibility(new DocumentVisibility("A&B&C").flatten());
final RyaStatement statement = builder.build();
final MongoDatabase db = conf.getMongoClient().getDatabase(conf.get(MongoDBRdfConfiguration.MONGO_DB_NAME));
final MongoCollection<Document> coll = db.getCollection(conf.getTriplesCollectionName());
dao.add(statement);
assertEquals(1, coll.count());
final RyaStatementBuilder builder2 = new RyaStatementBuilder();
builder2.setPredicate(new RyaURI("http://temp.com"));
builder2.setObject(new RyaURI("http://object.com"));
builder2.setContext(new RyaURI("http://context3.com"));
final RyaStatement query = builder2.build();
dao.delete(query, conf);
assertEquals(1, coll.count());
} finally {
dao.destroy();
}
}
use of org.apache.rya.api.domain.RyaStatement in project incubator-rya by apache.
the class RyaStatementBindingSetCursorIterator method submitBatchQuery.
private void submitBatchQuery() {
int count = 0;
executedRangeMap.clear();
final List<Document> pipeline = new ArrayList<>();
final List<DBObject> match = new ArrayList<>();
while (queryIterator.hasNext() && count < QUERY_BATCH_SIZE) {
count++;
final RyaStatement query = queryIterator.next();
executedRangeMap.putAll(query, rangeMap.get(query));
final DBObject currentQuery = strategy.getQuery(query);
match.add(currentQuery);
}
if (match.size() > 1) {
pipeline.add(new Document("$match", new Document("$or", match)));
} else if (match.size() == 1) {
pipeline.add(new Document("$match", match.get(0)));
} else {
batchQueryResultsIterator = Iterators.emptyIterator();
return;
}
// Executing redact aggregation to only return documents the user has access to.
pipeline.addAll(AggregationUtil.createRedactPipeline(auths));
log.trace(pipeline);
final AggregateIterable<Document> aggIter = coll.aggregate(pipeline);
aggIter.batchSize(1000);
batchQueryResultsIterator = aggIter.iterator();
}
use of org.apache.rya.api.domain.RyaStatement in project incubator-rya by apache.
the class MongoDBRyaDAO2IT method testDelete.
@Test
public void testDelete() throws RyaDAOException, MongoException, IOException {
MongoDBRyaDAO dao = new MongoDBRyaDAO();
try {
dao.setConf(conf);
dao.init();
final RyaStatementBuilder builder = new RyaStatementBuilder();
builder.setPredicate(new RyaURI("http://temp.com"));
builder.setSubject(new RyaURI("http://subject.com"));
builder.setObject(new RyaURI("http://object.com"));
final RyaStatement statement = builder.build();
final MongoDatabase db = conf.getMongoClient().getDatabase(conf.get(MongoDBRdfConfiguration.MONGO_DB_NAME));
final MongoCollection<Document> coll = db.getCollection(conf.getTriplesCollectionName());
dao.add(statement);
assertEquals(coll.count(), 1);
dao.delete(statement, conf);
assertEquals(coll.count(), 0);
} finally {
dao.destroy();
}
}
use of org.apache.rya.api.domain.RyaStatement in project incubator-rya by apache.
the class GeoMesaGeoIndexer method deleteStatements.
private void deleteStatements(final Collection<RyaStatement> ryaStatements) throws IOException {
// create a feature collection
final DefaultFeatureCollection featureCollection = new DefaultFeatureCollection();
for (final RyaStatement ryaStatement : ryaStatements) {
final Statement statement = RyaToRdfConversions.convertStatement(ryaStatement);
// if the predicate list is empty, accept all predicates.
// Otherwise, make sure the predicate is on the "valid" list
final boolean isValidPredicate = validPredicates.isEmpty() || validPredicates.contains(statement.getPredicate());
if (isValidPredicate && (statement.getObject() instanceof Literal)) {
try {
final SimpleFeature feature = createFeature(featureType, statement);
featureCollection.add(feature);
} catch (final ParseException e) {
logger.warn("Error getting geo from statement: " + statement.toString(), e);
}
}
}
// remove this feature collection from the store
if (!featureCollection.isEmpty()) {
final Set<Identifier> featureIds = new HashSet<Identifier>();
final FilterFactory filterFactory = CommonFactoryFinder.getFilterFactory(null);
final Set<String> stringIds = DataUtilities.fidSet(featureCollection);
for (final String id : stringIds) {
featureIds.add(filterFactory.featureId(id));
}
final Filter filter = filterFactory.id(featureIds);
featureStore.removeFeatures(filter);
}
}
use of org.apache.rya.api.domain.RyaStatement in project incubator-rya by apache.
the class InputIT method historicThenStreamedResults.
/**
* Simulates the case where a Triple is added to Rya, a new query that includes
* that triple as a historic match is inserted into Fluo, and then some new
* triple that matches the query is streamed into Fluo. The query's results
* must include both the historic result and the newly streamed result.
*/
@Test
public void historicThenStreamedResults() throws Exception {
// A query that finds people who talk to Eve and work at Chipotle.
final String sparql = "SELECT ?x WHERE { " + "?x <http://talksTo> <http://Eve>. " + "?x <http://worksAt> <http://Chipotle>." + "}";
// Triples that are loaded into Rya before the PCJ is created.
final ValueFactory vf = new ValueFactoryImpl();
final Set<Statement> historicTriples = Sets.newHashSet(vf.createStatement(vf.createURI("http://Alice"), vf.createURI("http://talksTo"), vf.createURI("http://Eve")), vf.createStatement(vf.createURI("http://Alice"), vf.createURI("http://worksAt"), vf.createURI("http://Chipotle")));
// Triples that will be streamed into Fluo after the PCJ has been created.
final Set<RyaStatement> streamedTriples = Sets.newHashSet(new RyaStatement(new RyaURI("http://Frank"), new RyaURI("http://talksTo"), new RyaURI("http://Eve")), new RyaStatement(new RyaURI("http://Frank"), new RyaURI("http://worksAt"), new RyaURI("http://Chipotle")));
// Load the historic data into Rya.
final SailRepositoryConnection ryaConn = super.getRyaSailRepository().getConnection();
for (final Statement triple : historicTriples) {
ryaConn.add(triple);
}
ryaConn.close();
// Create the PCJ table.
final Connector accumuloConn = super.getAccumuloConnector();
final PrecomputedJoinStorage pcjStorage = new AccumuloPcjStorage(accumuloConn, getRyaInstanceName());
final String pcjId = pcjStorage.createPcj(sparql);
try (FluoClient fluoClient = FluoFactory.newClient(super.getFluoConfiguration())) {
// Tell the Fluo app to maintain the PCJ.
new CreateFluoPcj().withRyaIntegration(pcjId, pcjStorage, fluoClient, accumuloConn, getRyaInstanceName());
// Ensure Alice is a match.
super.getMiniFluo().waitForObservers();
final Set<BindingSet> expected = new HashSet<>();
MapBindingSet bs = new MapBindingSet();
bs.addBinding("x", vf.createURI("http://Alice"));
expected.add(bs);
Set<BindingSet> results = new HashSet<>();
try (CloseableIterator<BindingSet> resultsIt = pcjStorage.listResults(pcjId)) {
while (resultsIt.hasNext()) {
results.add(resultsIt.next());
}
}
assertEquals(expected, results);
// Stream the data into Fluo.
new InsertTriples().insert(fluoClient, streamedTriples, Optional.<String>absent());
// Verify the end results of the query also include Frank.
super.getMiniFluo().waitForObservers();
bs = new MapBindingSet();
bs.addBinding("x", vf.createURI("http://Frank"));
expected.add(bs);
results = new HashSet<>();
try (CloseableIterator<BindingSet> resultsIt = pcjStorage.listResults(pcjId)) {
while (resultsIt.hasNext()) {
results.add(resultsIt.next());
}
}
assertEquals(expected, results);
}
}
Aggregations