Search in sources :

Example 1 with BatchRyaQuery

use of org.apache.rya.api.persist.query.BatchRyaQuery in project incubator-rya by apache.

the class AccumuloRyaQueryEngine method batchQuery.

@Override
public CloseableIteration<RyaStatement, RyaDAOException> batchQuery(Collection<RyaStatement> stmts, AccumuloRdfConfiguration conf) throws RyaDAOException {
    if (conf == null) {
        conf = configuration;
    }
    BatchRyaQuery batchRyaQuery = BatchRyaQuery.builder(stmts).load(conf).build();
    CloseableIterable<RyaStatement> results = query(batchRyaQuery);
    return new CloseableIterableIteration<RyaStatement, RyaDAOException>(results);
}
Also used : BatchRyaQuery(org.apache.rya.api.persist.query.BatchRyaQuery) CloseableIterableIteration(org.apache.rya.api.utils.CloseableIterableIteration) RyaStatement(org.apache.rya.api.domain.RyaStatement)

Example 2 with BatchRyaQuery

use of org.apache.rya.api.persist.query.BatchRyaQuery in project incubator-rya by apache.

the class CreateFluoPcj method importHistoricResultsIntoFluo.

private void importHistoricResultsIntoFluo(FluoClient fluo, FluoQuery fluoQuery, Connector accumulo, String ryaInstance) throws RyaDAOException {
    // Reuse the same set object while performing batch inserts.
    final Set<RyaStatement> queryBatch = new HashSet<>();
    // historic matches into Fluo.
    for (final StatementPatternMetadata patternMetadata : fluoQuery.getStatementPatternMetadata()) {
        // Get an iterator over all of the binding sets that match the
        // statement pattern.
        final StatementPattern pattern = FluoStringConverter.toStatementPattern(patternMetadata.getStatementPattern());
        queryBatch.add(spToRyaStatement(pattern));
    }
    // Create AccumuloRyaQueryEngine to query for historic results
    final AccumuloRdfConfiguration conf = new AccumuloRdfConfiguration();
    conf.setTablePrefix(ryaInstance);
    conf.setAuths(getAuths(accumulo));
    try (final AccumuloRyaQueryEngine queryEngine = new AccumuloRyaQueryEngine(accumulo, conf);
        CloseableIterable<RyaStatement> queryIterable = queryEngine.query(new BatchRyaQuery(queryBatch))) {
        final Set<RyaStatement> triplesBatch = new HashSet<>();
        // Insert batches of the binding sets into Fluo.
        for (final RyaStatement ryaStatement : queryIterable) {
            if (triplesBatch.size() == spInsertBatchSize) {
                writeBatch(fluo, triplesBatch);
                triplesBatch.clear();
            }
            triplesBatch.add(ryaStatement);
        }
        if (!triplesBatch.isEmpty()) {
            writeBatch(fluo, triplesBatch);
            triplesBatch.clear();
        }
    } catch (final IOException e) {
        log.warn("Ignoring IOException thrown while closing the AccumuloRyaQueryEngine used by CreatePCJ.", e);
    }
}
Also used : StatementPattern(org.openrdf.query.algebra.StatementPattern) StatementPatternMetadata(org.apache.rya.indexing.pcj.fluo.app.query.StatementPatternMetadata) BatchRyaQuery(org.apache.rya.api.persist.query.BatchRyaQuery) RyaStatement(org.apache.rya.api.domain.RyaStatement) AccumuloRyaQueryEngine(org.apache.rya.accumulo.query.AccumuloRyaQueryEngine) IOException(java.io.IOException) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) HashSet(java.util.HashSet)

Aggregations

RyaStatement (org.apache.rya.api.domain.RyaStatement)2 BatchRyaQuery (org.apache.rya.api.persist.query.BatchRyaQuery)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 AccumuloRdfConfiguration (org.apache.rya.accumulo.AccumuloRdfConfiguration)1 AccumuloRyaQueryEngine (org.apache.rya.accumulo.query.AccumuloRyaQueryEngine)1 CloseableIterableIteration (org.apache.rya.api.utils.CloseableIterableIteration)1 StatementPatternMetadata (org.apache.rya.indexing.pcj.fluo.app.query.StatementPatternMetadata)1 StatementPattern (org.openrdf.query.algebra.StatementPattern)1