Search in sources :

Example 61 with RyaStatement

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();
    }
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) RyaStatementBuilder(org.apache.rya.api.domain.RyaStatement.RyaStatementBuilder) RyaStatement(org.apache.rya.api.domain.RyaStatement) DocumentVisibility(org.apache.rya.mongodb.document.visibility.DocumentVisibility) Document(org.bson.Document) MongoDatabase(com.mongodb.client.MongoDatabase) Test(org.junit.Test)

Example 62 with RyaStatement

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();
}
Also used : ArrayList(java.util.ArrayList) RyaStatement(org.apache.rya.api.domain.RyaStatement) Document(org.bson.Document) DBObject(com.mongodb.DBObject)

Example 63 with RyaStatement

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();
    }
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) RyaStatementBuilder(org.apache.rya.api.domain.RyaStatement.RyaStatementBuilder) RyaStatement(org.apache.rya.api.domain.RyaStatement) Document(org.bson.Document) MongoDatabase(com.mongodb.client.MongoDatabase) Test(org.junit.Test)

Example 64 with RyaStatement

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);
    }
}
Also used : RyaStatement(org.apache.rya.api.domain.RyaStatement) Statement(org.openrdf.model.Statement) RyaStatement(org.apache.rya.api.domain.RyaStatement) SimpleFeature(org.opengis.feature.simple.SimpleFeature) FilterFactory(org.opengis.filter.FilterFactory) Identifier(org.opengis.filter.identity.Identifier) Filter(org.opengis.filter.Filter) Literal(org.openrdf.model.Literal) ParseException(com.vividsolutions.jts.io.ParseException) DefaultFeatureCollection(org.geotools.feature.DefaultFeatureCollection) HashSet(java.util.HashSet)

Example 65 with RyaStatement

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);
    }
}
Also used : Connector(org.apache.accumulo.core.client.Connector) MapBindingSet(org.openrdf.query.impl.MapBindingSet) BindingSet(org.openrdf.query.BindingSet) FluoClient(org.apache.fluo.api.client.FluoClient) AccumuloPcjStorage(org.apache.rya.indexing.pcj.storage.accumulo.AccumuloPcjStorage) InsertTriples(org.apache.rya.indexing.pcj.fluo.api.InsertTriples) Statement(org.openrdf.model.Statement) RyaStatement(org.apache.rya.api.domain.RyaStatement) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) RyaStatement(org.apache.rya.api.domain.RyaStatement) CreateFluoPcj(org.apache.rya.indexing.pcj.fluo.api.CreateFluoPcj) ValueFactory(org.openrdf.model.ValueFactory) SailRepositoryConnection(org.openrdf.repository.sail.SailRepositoryConnection) RyaURI(org.apache.rya.api.domain.RyaURI) PrecomputedJoinStorage(org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage) MapBindingSet(org.openrdf.query.impl.MapBindingSet) HashSet(java.util.HashSet) 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