use of org.apache.rya.indexing.pcj.storage.accumulo.ShiftVarOrderFactory in project incubator-rya by apache.
the class AccumuloPcjStorageIT method purge.
@Test
public void purge() throws Exception {
// Setup the PCJ storage that will be tested against.
final Connector connector = super.getClusterInstance().getConnector();
final String ryaInstanceName = super.getRyaInstanceName();
try (final PrecomputedJoinStorage pcjStorage = new AccumuloPcjStorage(connector, ryaInstanceName)) {
// 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.indexing.pcj.storage.accumulo.ShiftVarOrderFactory in project incubator-rya by apache.
the class AccumuloPcjStorageIT method getPcjMetadata.
@Test
public void getPcjMetadata() throws AccumuloException, AccumuloSecurityException, PCJStorageException, MalformedQueryException {
// Setup the PCJ storage that will be tested against.
final Connector connector = super.getClusterInstance().getConnector();
final String ryaInstanceName = super.getRyaInstanceName();
try (final PrecomputedJoinStorage pcjStorage = new AccumuloPcjStorage(connector, ryaInstanceName)) {
// Create a PCJ.
final String sparql = "SELECT * WHERE { ?a <http://isA> ?b }";
final String pcjId = pcjStorage.createPcj(sparql);
// Fetch the PCJ's metadata.
final PcjMetadata metadata = pcjStorage.getPcjMetadata(pcjId);
// Ensure it has the expected values.
final Set<VariableOrder> varOrders = new ShiftVarOrderFactory().makeVarOrders(sparql);
final PcjMetadata expectedMetadata = new PcjMetadata(sparql, 0L, varOrders);
assertEquals(expectedMetadata, metadata);
}
}
use of org.apache.rya.indexing.pcj.storage.accumulo.ShiftVarOrderFactory in project incubator-rya by apache.
the class MongoPcjStorageIT method addResults.
@Test
public void addResults() 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> results = new HashSet<>();
final MapBindingSet aliceBS = new MapBindingSet();
aliceBS.addBinding("a", new URIImpl("http://Alice"));
aliceBS.addBinding("b", new URIImpl("http://Person"));
results.add(new VisibilityBindingSet(aliceBS, ""));
final MapBindingSet charlieBS = new MapBindingSet();
charlieBS.addBinding("a", new URIImpl("http://Charlie"));
charlieBS.addBinding("b", new URIImpl("http://Comedian"));
results.add(new VisibilityBindingSet(charlieBS, ""));
pcjStorage.addResults(pcjId, results);
// 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, 2L, varOrders);
assertEquals(expectedMetadata, metadata);
}
}
use of org.apache.rya.indexing.pcj.storage.accumulo.ShiftVarOrderFactory in project incubator-rya by apache.
the class PcjIntegrationTestingUtil method createAndPopulatePcj.
// ****************************Creation and Population of PcjTables Accumulo***************************
/**
* Creates a new PCJ Table in Accumulo and populates it by scanning an
* instance of Rya for historic matches.
* <p>
* If any portion of this operation fails along the way, the partially
* create PCJ table will be left in Accumulo.
*
* @param ryaConn - Connects to the Rya that will be scanned. (not null)
* @param accumuloConn - Connects to the accumulo that hosts the PCJ results. (not null)
* @param pcjTableName - The name of the PCJ table that will be created. (not null)
* @param sparql - The SPARQL query whose results will be loaded into the table. (not null)
* @param resultVariables - The variables that are included in the query's resulting binding sets. (not null)
* @param pcjVarOrderFactory - An optional factory that indicates the various variable orders
* the results will be stored in. If one is not provided, then {@link ShiftVarOrderFactory}
* is used by default. (not null)
* @throws PcjException The PCJ table could not be create or the values from
* Rya were not able to be loaded into it.
*/
public static void createAndPopulatePcj(final RepositoryConnection ryaConn, final Connector accumuloConn, final String pcjTableName, final String sparql, final String[] resultVariables, final Optional<PcjVarOrderFactory> pcjVarOrderFactory) throws PcjException {
checkNotNull(ryaConn);
checkNotNull(accumuloConn);
checkNotNull(pcjTableName);
checkNotNull(sparql);
checkNotNull(resultVariables);
checkNotNull(pcjVarOrderFactory);
final PcjTables pcj = new PcjTables();
// Create the PCJ's variable orders.
final PcjVarOrderFactory varOrderFactory = pcjVarOrderFactory.or(new ShiftVarOrderFactory());
final Set<VariableOrder> varOrders = varOrderFactory.makeVarOrders(new VariableOrder(resultVariables));
// Create the PCJ table in Accumulo.
pcj.createPcjTable(accumuloConn, pcjTableName, varOrders, sparql);
// Load historic matches from Rya into the PCJ table.
populatePcj(accumuloConn, pcjTableName, ryaConn);
}
use of org.apache.rya.indexing.pcj.storage.accumulo.ShiftVarOrderFactory in project incubator-rya by apache.
the class PcjTablesTest method shiftVarOrdersFactory.
@Test
public void shiftVarOrdersFactory() {
Set<VariableOrder> expected = Sets.newHashSet(new VariableOrder("a;b;c"), new VariableOrder("b;c;a"), new VariableOrder("c;a;b"));
Set<VariableOrder> varOrders = new ShiftVarOrderFactory().makeVarOrders(new VariableOrder("a;b;c"));
assertEquals(expected, varOrders);
}
Aggregations