use of org.apache.rya.indexing.pcj.storage.PcjMetadata in project incubator-rya by apache.
the class PcjMetadataRendererTest method formatSingleMetadata.
@Test
public void formatSingleMetadata() throws Exception {
// Create the PcjMetadata that will be formatted as a report.
final PcjMetadata metadata = new PcjMetadata("SELECT ?x ?y " + "WHERE { " + "?x <http://talksTo> <http://Eve>. " + "?y <http://worksAt> <http://Chipotle>." + "}", 12233423L, Sets.<VariableOrder>newHashSet(new VariableOrder("x", "y"), new VariableOrder("y", "x")));
// Run the test.
final String expected = "---------------------------------------------------------------------\n" + "| Query ID | query1 |\n" + "| Cardinality | 12,233,423 |\n" + "| Export Variable Orders | y;x |\n" + "| | x;y |\n" + "| SPARQL | select ?x ?y |\n" + "| | where { |\n" + "| | ?x <http://talksTo> <http://Eve>. |\n" + "| | ?y <http://worksAt> <http://Chipotle>. |\n" + "| | } |\n" + "---------------------------------------------------------------------\n";
final PcjMetadataRenderer formatter = new PcjMetadataRenderer();
assertEquals(expected, formatter.render("query1", metadata));
}
use of org.apache.rya.indexing.pcj.storage.PcjMetadata 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.PcjMetadata 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.PcjMetadata in project incubator-rya by apache.
the class PcjMetadataRendererTest method formatManyMetdata.
@Test
public void formatManyMetdata() throws Exception {
// Create the PcjMetadata that will be formatted as a report.
final PcjMetadata metadata1 = new PcjMetadata("SELECT ?x ?y " + "WHERE { " + "?x <http://talksTo> <http://Eve>. " + "?y <http://worksAt> <http://Chipotle>." + "}", 12233423L, Sets.<VariableOrder>newHashSet(new VariableOrder("x", "y"), new VariableOrder("y", "x")));
final PcjMetadata metadata2 = new PcjMetadata("SELECT ?x " + "WHERE { " + "?x <http://likes> <http://cookies>" + "}", 2342L, Sets.<VariableOrder>newHashSet(new VariableOrder("x")));
final Map<String, PcjMetadata> metadata = new LinkedHashMap<>();
metadata.put("query1", metadata1);
metadata.put("query2", metadata2);
// Run the test.
final String expected = "---------------------------------------------------------------------\n" + "| Query ID | query1 |\n" + "| Cardinality | 12,233,423 |\n" + "| Export Variable Orders | y;x |\n" + "| | x;y |\n" + "| SPARQL | select ?x ?y |\n" + "| | where { |\n" + "| | ?x <http://talksTo> <http://Eve>. |\n" + "| | ?y <http://worksAt> <http://Chipotle>. |\n" + "| | } |\n" + "---------------------------------------------------------------------\n" + "\n" + "------------------------------------------------------------------\n" + "| Query ID | query2 |\n" + "| Cardinality | 2,342 |\n" + "| Export Variable Orders | x |\n" + "| SPARQL | select ?x |\n" + "| | where { |\n" + "| | ?x <http://likes> <http://cookies>. |\n" + "| | } |\n" + "------------------------------------------------------------------\n" + "\n";
final PcjMetadataRenderer formatter = new PcjMetadataRenderer();
assertEquals(expected, formatter.render(metadata));
}
use of org.apache.rya.indexing.pcj.storage.PcjMetadata in project incubator-rya by apache.
the class GetQueryReportIT method getReport.
@Test
public void getReport() throws Exception {
final String sparql = "SELECT ?worker ?company ?city" + "{ " + "FILTER(?worker = <http://Alice>) " + "?worker <http://worksAt> ?company . " + "?worker <http://livesIn> ?city ." + "}";
// Triples that will be streamed into Fluo after the PCJ has been created.
final Set<RyaStatement> streamedTriples = Sets.newHashSet(new RyaStatement(new RyaURI("http://Alice"), new RyaURI("http://worksAt"), new RyaURI("http://Taco Shop")), new RyaStatement(new RyaURI("http://Alice"), new RyaURI("http://worksAt"), new RyaURI("http://Burger Join")), new RyaStatement(new RyaURI("http://Alice"), new RyaURI("http://worksAt"), new RyaURI("http://Pastery Shop")), new RyaStatement(new RyaURI("http://Alice"), new RyaURI("http://worksAt"), new RyaURI("http://Burrito Place")), new RyaStatement(new RyaURI("http://Alice"), new RyaURI("http://livesIn"), new RyaURI("http://Lost County")), new RyaStatement(new RyaURI("http://Alice"), new RyaURI("http://livesIn"), new RyaURI("http://Big City")), new RyaStatement(new RyaURI("http://Bob"), new RyaURI("http://worksAt"), new RyaURI("http://Burrito Place")), new RyaStatement(new RyaURI("http://Bob"), new RyaURI("http://livesIn"), new RyaURI("http://Big City")), new RyaStatement(new RyaURI("http://Charlie"), new RyaURI("http://worksAt"), new RyaURI("http://Burrito Place")), new RyaStatement(new RyaURI("http://Charlie"), new RyaURI("http://livesIn"), new RyaURI("http://Big City")), new RyaStatement(new RyaURI("http://David"), new RyaURI("http://worksAt"), new RyaURI("http://Burrito Place")), new RyaStatement(new RyaURI("http://David"), new RyaURI("http://livesIn"), new RyaURI("http://Lost County")), new RyaStatement(new RyaURI("http://Eve"), new RyaURI("http://worksAt"), new RyaURI("http://Burrito Place")), new RyaStatement(new RyaURI("http://Eve"), new RyaURI("http://livesIn"), new RyaURI("http://Big City")), new RyaStatement(new RyaURI("http://Frank"), new RyaURI("http://worksAt"), new RyaURI("http://Burrito Place")), new RyaStatement(new RyaURI("http://Frank"), new RyaURI("http://livesIn"), new RyaURI("http://Lost County")));
// 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());
// Stream the data into Fluo.
new InsertTriples().insert(fluoClient, streamedTriples, Optional.<String>absent());
// Wait for the results to finish processing.
super.getMiniFluo().waitForObservers();
// Fetch the report.
final Map<String, PcjMetadata> metadata = new GetPcjMetadata().getMetadata(pcjStorage, fluoClient);
final Set<String> queryIds = metadata.keySet();
assertEquals(1, queryIds.size());
final String queryId = queryIds.iterator().next();
final QueryReport report = new GetQueryReport().getReport(fluoClient, queryId);
// Build the expected counts map.
final Map<String, BigInteger> expectedCounts = new HashMap<>();
final FluoQuery fluoQuery = report.getFluoQuery();
final String queryNodeId = fluoQuery.getQueryMetadata().getNodeId();
expectedCounts.put(queryNodeId, BigInteger.valueOf(8));
final String filterNodeId = fluoQuery.getFilterMetadata().iterator().next().getNodeId();
expectedCounts.put(filterNodeId, BigInteger.valueOf(8));
final String joinNodeId = fluoQuery.getJoinMetadata().iterator().next().getNodeId();
expectedCounts.put(joinNodeId, BigInteger.valueOf(13));
final Iterator<StatementPatternMetadata> patterns = fluoQuery.getStatementPatternMetadata().iterator();
final StatementPatternMetadata sp1 = patterns.next();
final StatementPatternMetadata sp2 = patterns.next();
if (sp1.getStatementPattern().contains("http://worksAt")) {
expectedCounts.put(sp1.getNodeId(), BigInteger.valueOf(9));
expectedCounts.put(sp2.getNodeId(), BigInteger.valueOf(7));
} else {
expectedCounts.put(sp2.getNodeId(), BigInteger.valueOf(9));
expectedCounts.put(sp1.getNodeId(), BigInteger.valueOf(7));
}
assertEquals(expectedCounts, report.getCounts());
}
}
Aggregations