use of org.apache.rya.api.model.VisibilityBindingSet in project incubator-rya by apache.
the class MongoPcjStorageIT method listResults.
@Test
public void listResults() throws Exception {
try (final PrecomputedJoinStorage pcjStorage = new MongoPcjStorage(getMongoClient(), conf.getRyaInstanceName())) {
final MongoRyaInstanceDetailsRepository detailsRepo = new MongoRyaInstanceDetailsRepository(getMongoClient(), conf.getRyaInstanceName());
detailsRepo.initialize(RyaDetails.builder().setRyaInstanceName(conf.getRyaInstanceName()).setRyaVersion("test").setEntityCentricIndexDetails(new EntityCentricIndexDetails(false)).setTemporalIndexDetails(new TemporalIndexDetails(false)).setFreeTextDetails(new FreeTextIndexDetails(false)).setProspectorDetails(new ProspectorDetails(Optional.absent())).setJoinSelectivityDetails(new JoinSelectivityDetails(Optional.absent())).setPCJIndexDetails(PCJIndexDetails.builder().setEnabled(true)).build());
// Create a PCJ.
final String sparql = "SELECT * WHERE { ?a <http://isA> ?b }";
final String pcjId = pcjStorage.createPcj(sparql);
// Add some binding sets to it.
final Set<VisibilityBindingSet> visiSets = new HashSet<>();
final Set<BindingSet> expectedResults = new HashSet<>();
final MapBindingSet aliceBS = new MapBindingSet();
aliceBS.addBinding("a", new URIImpl("http://Alice"));
aliceBS.addBinding("b", new URIImpl("http://Person"));
visiSets.add(new VisibilityBindingSet(aliceBS, ""));
expectedResults.add(aliceBS);
final MapBindingSet charlieBS = new MapBindingSet();
charlieBS.addBinding("a", new URIImpl("http://Charlie"));
charlieBS.addBinding("b", new URIImpl("http://Comedian"));
visiSets.add(new VisibilityBindingSet(charlieBS, ""));
expectedResults.add(charlieBS);
pcjStorage.addResults(pcjId, visiSets);
// List the results that were stored.
final Set<BindingSet> results = new HashSet<>();
try (CloseableIterator<BindingSet> resultsIt = pcjStorage.listResults(pcjId)) {
while (resultsIt.hasNext()) {
results.add(resultsIt.next());
}
}
assertEquals(expectedResults, results);
}
}
use of org.apache.rya.api.model.VisibilityBindingSet in project incubator-rya by apache.
the class MongoPcjStorageIT method purge.
@Test
public void purge() throws Exception {
try (final PrecomputedJoinStorage pcjStorage = new MongoPcjStorage(getMongoClient(), conf.getRyaInstanceName())) {
final MongoRyaInstanceDetailsRepository detailsRepo = new MongoRyaInstanceDetailsRepository(getMongoClient(), conf.getRyaInstanceName());
detailsRepo.initialize(RyaDetails.builder().setRyaInstanceName(conf.getRyaInstanceName()).setRyaVersion("test").setEntityCentricIndexDetails(new EntityCentricIndexDetails(false)).setTemporalIndexDetails(new TemporalIndexDetails(false)).setFreeTextDetails(new FreeTextIndexDetails(false)).setProspectorDetails(new ProspectorDetails(Optional.absent())).setJoinSelectivityDetails(new JoinSelectivityDetails(Optional.absent())).setPCJIndexDetails(PCJIndexDetails.builder().setEnabled(true)).build());
// Create a PCJ.
final String sparql = "SELECT * WHERE { ?a <http://isA> ?b }";
final String pcjId = pcjStorage.createPcj(sparql);
// Add some binding sets to it.
final Set<VisibilityBindingSet> expectedResults = new HashSet<>();
final MapBindingSet aliceBS = new MapBindingSet();
aliceBS.addBinding("a", new URIImpl("http://Alice"));
aliceBS.addBinding("b", new URIImpl("http://Person"));
expectedResults.add(new VisibilityBindingSet(aliceBS, ""));
final MapBindingSet charlieBS = new MapBindingSet();
charlieBS.addBinding("a", new URIImpl("http://Charlie"));
charlieBS.addBinding("b", new URIImpl("http://Comedian"));
expectedResults.add(new VisibilityBindingSet(charlieBS, ""));
pcjStorage.addResults(pcjId, expectedResults);
// Purge the PCJ.
pcjStorage.purge(pcjId);
// List the results that were stored.
final Set<BindingSet> results = new HashSet<>();
try (CloseableIterator<BindingSet> resultsIt = pcjStorage.listResults(pcjId)) {
while (resultsIt.hasNext()) {
results.add(resultsIt.next());
}
}
assertTrue(results.isEmpty());
// Make sure the PCJ metadata was updated.
final PcjMetadata metadata = pcjStorage.getPcjMetadata(pcjId);
final Set<VariableOrder> varOrders = new ShiftVarOrderFactory().makeVarOrders(sparql);
final PcjMetadata expectedMetadata = new PcjMetadata(sparql, 0L, varOrders);
assertEquals(expectedMetadata, metadata);
}
}
use of org.apache.rya.api.model.VisibilityBindingSet in project incubator-rya by apache.
the class PcjIntegrationTestingUtil method writeResults.
/**
* Add a collection of results to a specific PCJ table.
*
* @param accumuloConn - A connection to the Accumulo that hosts the PCJ table. (not null)
* @param pcjTableName - The name of the PCJ table that will receive the results. (not null)
* @param results - Binding sets that will be written to the PCJ table. (not null)
* @throws PcjException The provided PCJ table doesn't exist, is missing the
* PCJ metadata, or the result could not be written to it.
*/
private static void writeResults(final MongoPcjDocuments pcj, final String pcjTableName, final Collection<BindingSet> results) throws PcjException {
checkNotNull(pcj);
checkNotNull(pcjTableName);
checkNotNull(results);
final Collection<VisibilityBindingSet> visRes = new ArrayList<>();
results.forEach(bindingSet -> {
visRes.add(new VisibilityBindingSet(bindingSet));
});
pcj.addResults(pcjTableName, visRes);
}
use of org.apache.rya.api.model.VisibilityBindingSet in project incubator-rya by apache.
the class KafkaBindingSetExporterFactory method build.
@Override
public Optional<IncrementalResultExporter> build(final Context context) throws IncrementalExporterFactoryException, ConfigurationException {
final KafkaBindingSetExporterParameters exportParams = new KafkaBindingSetExporterParameters(context.getObserverConfiguration().toMap());
if (exportParams.getUseKafkaBindingSetExporter()) {
log.info("Exporter is enabled.");
// Setup Kafka connection
final KafkaProducer<String, VisibilityBindingSet> producer = new KafkaProducer<>(exportParams.listAllConfig());
// Create the exporter
final IncrementalBindingSetExporter exporter = new KafkaBindingSetExporter(producer);
return Optional.of(exporter);
} else {
return Optional.absent();
}
}
use of org.apache.rya.api.model.VisibilityBindingSet in project incubator-rya by apache.
the class JoinBatchBindingSetUpdater method processBatch.
/**
* Processes {@link JoinBatchInformation}. Updates the BindingSets
* associated with the specified nodeId. The BindingSets are processed in
* batch fashion, where the number of results is indicated by
* {@link JoinBatchInformation#getBatchSize()}. BindingSets are either
* Added, Deleted, or Updated according to
* {@link JoinBatchInformation#getTask()}. In the event that the number of
* entries that need to be updated exceeds the batch size, the row of the
* first unprocessed BindingSets is used to create a new JoinBatch job to
* process the remaining BindingSets.
* @throws Exception
*/
@Override
public void processBatch(final TransactionBase tx, final Bytes row, final BatchInformation batch) throws Exception {
super.processBatch(tx, row, batch);
final String nodeId = BatchRowKeyUtil.getNodeId(row);
Preconditions.checkArgument(batch instanceof JoinBatchInformation);
final JoinBatchInformation joinBatch = (JoinBatchInformation) batch;
final Task task = joinBatch.getTask();
// Figure out which join algorithm we are going to use.
final IterativeJoin joinAlgorithm;
switch(joinBatch.getJoinType()) {
case NATURAL_JOIN:
joinAlgorithm = new NaturalJoin();
break;
case LEFT_OUTER_JOIN:
joinAlgorithm = new LeftOuterJoin();
break;
default:
throw new RuntimeException("Unsupported JoinType: " + joinBatch.getJoinType());
}
final Set<VisibilityBindingSet> bsSet = new HashSet<>();
final Optional<RowColumn> rowCol = fillSiblingBatch(tx, joinBatch, bsSet);
// Iterates over the resulting BindingSets from the join.
final Iterator<VisibilityBindingSet> newJoinResults;
final VisibilityBindingSet bs = joinBatch.getBs();
if (joinBatch.getSide() == Side.LEFT) {
newJoinResults = joinAlgorithm.newLeftResult(bs, bsSet.iterator());
} else {
newJoinResults = joinAlgorithm.newRightResult(bsSet.iterator(), bs);
}
// Read join metadata, create new join BindingSets and insert them into the Fluo table.
final JoinMetadata joinMetadata = CACHE.readJoinMetadata(tx, nodeId);
final VariableOrder joinVarOrder = joinMetadata.getVariableOrder();
while (newJoinResults.hasNext()) {
final VisibilityBindingSet newJoinResult = newJoinResults.next();
// create BindingSet value
final Bytes bsBytes = BS_SERDE.serialize(newJoinResult);
// make rowId
Bytes rowKey = BindingHashShardingFunction.addShard(nodeId, joinVarOrder, newJoinResult);
final Column col = FluoQueryColumns.JOIN_BINDING_SET;
processTask(tx, task, rowKey, col, bsBytes);
}
// update the span and register updated batch job
if (rowCol.isPresent()) {
final Span newSpan = getNewSpan(rowCol.get(), joinBatch.getSpan());
joinBatch.setSpan(newSpan);
BatchInformationDAO.addBatch(tx, nodeId, joinBatch);
}
}
Aggregations