use of org.apache.rya.indexing.pcj.fluo.app.query.StatementPatternMetadata in project incubator-rya by apache.
the class StatementPatternIdCacheIT method statementPatternIdCacheTest.
/**
* Ensure streamed matches are included in the result.
*/
@Test
public void statementPatternIdCacheTest() throws Exception {
// A query that finds people who talk to Eve and work at Chipotle.
final String sparql1 = "SELECT ?x WHERE { " + "?x <urn:pred1> <urn:obj1>. " + "?x <urn:pred2> <urn:obj2>." + "}";
final String sparql2 = "SELECT ?x WHERE { " + "?x <urn:pred3> <urn:obj3>. " + "?x <urn:pred4> <urn:obj4>." + "}";
try (FluoClient fluoClient = FluoFactory.newClient(super.getFluoConfiguration())) {
String pcjId = FluoQueryUtils.createNewPcjId();
// Tell the Fluo app to maintain the PCJ.
FluoQuery query1 = new CreateFluoPcj().createPcj(pcjId, sparql1, new HashSet<>(), fluoClient);
Set<String> spIds1 = new HashSet<>();
for (StatementPatternMetadata metadata : query1.getStatementPatternMetadata()) {
spIds1.add(metadata.getNodeId());
}
StatementPatternIdCache cache = new StatementPatternIdCache();
assertEquals(spIds1, cache.getStatementPatternIds(fluoClient.newTransaction()));
FluoQuery query2 = new CreateFluoPcj().createPcj(pcjId, sparql2, new HashSet<>(), fluoClient);
Set<String> spIds2 = new HashSet<>();
for (StatementPatternMetadata metadata : query2.getStatementPatternMetadata()) {
spIds2.add(metadata.getNodeId());
}
assertEquals(Sets.union(spIds1, spIds2), cache.getStatementPatternIds(fluoClient.newTransaction()));
}
}
use of org.apache.rya.indexing.pcj.fluo.app.query.StatementPatternMetadata 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);
}
}
Aggregations