use of org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder in project incubator-rya by apache.
the class ParsedQueryRequestTest method parseNoVarOrders.
@Test
public void parseNoVarOrders() throws IOException {
final String requestText = "SELECT * \n" + "WHERE { \n" + " ?a <http://talksTo> ?b. \n" + " ?b <http://talksTo> ?c. \n" + "}";
final ParsedQueryRequest expected = new ParsedQueryRequest("SELECT * \n" + "WHERE { \n" + " ?a <http://talksTo> ?b. \n" + " ?b <http://talksTo> ?c. \n" + "}", new HashSet<VariableOrder>());
final ParsedQueryRequest request = ParsedQueryRequest.parse(requestText);
assertEquals(expected, request);
}
use of org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder in project incubator-rya by apache.
the class GetPcjMetadataIT method getMetadataByQueryId.
@Test
public void getMetadataByQueryId() throws RepositoryException, MalformedQueryException, SailException, QueryEvaluationException, PcjException, NotInFluoException, NotInAccumuloException, RyaDAOException, UnsupportedQueryException {
final String sparql = "SELECT ?x " + "WHERE { " + "?x <http://talksTo> <http://Eve>. " + "?x <http://worksAt> <http://Chipotle>." + "}";
// 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());
// Fetch the PCJ's Metadata through the GetPcjMetadata interactor.
final String queryId = new ListQueryIds().listQueryIds(fluoClient).get(0);
final PcjMetadata metadata = new GetPcjMetadata().getMetadata(pcjStorage, fluoClient, queryId);
// Ensure the command returns the correct metadata.
final Set<VariableOrder> varOrders = new ShiftVarOrderFactory().makeVarOrders(sparql);
final PcjMetadata expected = new PcjMetadata(sparql, 0L, varOrders);
assertEquals(expected, metadata);
}
}
use of org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder in project incubator-rya by apache.
the class GetPcjMetadataIT method getAllMetadata.
@Test
public void getAllMetadata() throws MalformedQueryException, SailException, QueryEvaluationException, PcjException, NotInFluoException, NotInAccumuloException, AccumuloException, AccumuloSecurityException, RyaDAOException, UnsupportedQueryException {
final Connector accumuloConn = super.getAccumuloConnector();
final PrecomputedJoinStorage pcjStorage = new AccumuloPcjStorage(accumuloConn, getRyaInstanceName());
try (FluoClient fluoClient = FluoFactory.newClient(super.getFluoConfiguration())) {
// Add a couple of queries to Accumulo.
final String q1Sparql = "SELECT ?x " + "WHERE { " + "?x <http://talksTo> <http://Eve>. " + "?x <http://worksAt> <http://Chipotle>." + "}";
final String q1PcjId = pcjStorage.createPcj(q1Sparql);
final CreateFluoPcj createPcj = new CreateFluoPcj();
createPcj.withRyaIntegration(q1PcjId, pcjStorage, fluoClient, accumuloConn, getRyaInstanceName());
final String q2Sparql = "SELECT ?x ?y " + "WHERE { " + "?x <http://talksTo> ?y. " + "?y <http://worksAt> <http://Chipotle>." + "}";
final String q2PcjId = pcjStorage.createPcj(q2Sparql);
createPcj.withRyaIntegration(q2PcjId, pcjStorage, fluoClient, accumuloConn, getRyaInstanceName());
// Ensure the command returns the correct metadata.
final Set<PcjMetadata> expected = new HashSet<>();
final Set<VariableOrder> q1VarOrders = new ShiftVarOrderFactory().makeVarOrders(q1Sparql);
final Set<VariableOrder> q2VarOrders = new ShiftVarOrderFactory().makeVarOrders(q2Sparql);
expected.add(new PcjMetadata(q1Sparql, 0L, q1VarOrders));
expected.add(new PcjMetadata(q2Sparql, 0L, q2VarOrders));
final Map<String, PcjMetadata> metadata = new GetPcjMetadata().getMetadata(pcjStorage, fluoClient);
assertEquals(expected, Sets.newHashSet(metadata.values()));
}
}
use of org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder in project incubator-rya by apache.
the class PeriodicNotificationBinPrunerIT method compareFluoCounts.
private void compareFluoCounts(FluoClient client, String pcjId, long bin) {
QueryBindingSet bs = new QueryBindingSet();
bs.addBinding(IncrementalUpdateConstants.PERIODIC_BIN_ID, new LiteralImpl(Long.toString(bin), XMLSchema.LONG));
VariableOrder varOrder = new VariableOrder(IncrementalUpdateConstants.PERIODIC_BIN_ID);
try (Snapshot sx = client.newSnapshot()) {
String fluoQueryId = NodeType.generateNewIdForType(NodeType.QUERY, pcjId);
Set<String> ids = new HashSet<>();
PeriodicQueryUtil.getPeriodicQueryNodeAncestorIds(sx, fluoQueryId, ids);
for (String id : ids) {
NodeType optNode = NodeType.fromNodeId(id).orNull();
if (optNode == null)
throw new RuntimeException("Invalid NodeType.");
Bytes prefix = RowKeyUtil.makeRowKey(id, varOrder, bs);
RowScanner scanner = sx.scanner().fetch(optNode.getResultColumn()).over(Span.prefix(prefix)).byRow().build();
int count = 0;
Iterator<ColumnScanner> colScannerIter = scanner.iterator();
while (colScannerIter.hasNext()) {
ColumnScanner colScanner = colScannerIter.next();
String row = colScanner.getRow().toString();
Iterator<ColumnValue> values = colScanner.iterator();
while (values.hasNext()) {
values.next();
count++;
}
}
Assert.assertEquals(0, count);
}
}
}
use of org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder in project incubator-rya by apache.
the class BindingHashShardingFunctionTest method shardAddAndRemoveTest.
@Test
public void shardAddAndRemoveTest() {
String nodeId = NodeType.generateNewFluoIdForType(NodeType.STATEMENT_PATTERN);
QueryBindingSet bs = new QueryBindingSet();
bs.addBinding("entity", vf.createURI("urn:entity"));
bs.addBinding("location", vf.createLiteral("location_1"));
VisibilityBindingSet vBs = new VisibilityBindingSet(bs);
VariableOrder varOrder = new VariableOrder("entity", "location");
Bytes row = RowKeyUtil.makeRowKey(nodeId, varOrder, vBs);
Bytes shardedRow = BindingHashShardingFunction.addShard(nodeId, varOrder, vBs);
Bytes shardlessRow = BindingHashShardingFunction.removeHash(Bytes.of(SP_PREFIX), shardedRow);
Assert.assertEquals(row, shardlessRow);
}
Aggregations