use of org.apache.rya.indexing.pcj.fluo.api.GetQueryReport.QueryReport in project incubator-rya by apache.
the class QueryReportCommand method execute.
@Override
public void execute(final Connector accumulo, final String ryaTablePrefix, final RyaSailRepository rya, final FluoClient fluo, final String[] args) throws ArgumentsException, ExecutionException, UnsupportedQueryException {
checkNotNull(accumulo);
checkNotNull(ryaTablePrefix);
checkNotNull(rya);
checkNotNull(fluo);
checkNotNull(args);
log.trace("Executing the Get Query Report Command...");
// Parse the command line arguments.
final Parameters params = new Parameters();
try {
new JCommander(params, args);
} catch (final ParameterException e) {
throw new ArgumentsException("Could not create a new query because of invalid command line parameters.", e);
}
// Build the report using what is stored in Fluo.
log.trace("Building the report for Query ID: " + params.queryId);
final QueryReport queryReport = new GetQueryReport().getReport(fluo, params.queryId);
log.trace("Report built.");
// Format and print the report.
try {
final String reportString = new QueryReportRenderer().render(queryReport);
System.out.println(reportString);
} catch (final Exception e) {
throw new ExecutionException("Unable to render the query metadata report for output.", e);
}
log.trace("Finished executing the Get Query Report Command.");
}
use of org.apache.rya.indexing.pcj.fluo.api.GetQueryReport.QueryReport in project incubator-rya by apache.
the class QueryReportRenderer method render.
/**
* Pretty render a {@link QueryReport}.
*
* @param queryReport - The report that will be rendered. (not null)
* @return A pretty render of the report.
* @throws Exception Indicates the SPARQL could not be rendered for some reason.
*/
public String render(final QueryReport queryReport) throws Exception {
checkNotNull(queryReport);
final Report.Builder builder = Report.builder();
final FluoQuery metadata = queryReport.getFluoQuery();
QueryMetadata queryMetadata = metadata.getQueryMetadata();
builder.appendItem(new ReportItem(""));
builder.appendItem(new ReportItem("QUERY NODE"));
builder.appendItem(new ReportItem("Node ID", queryMetadata.getNodeId()));
builder.appendItem(new ReportItem("Variable Order", queryMetadata.getVariableOrder().toString()));
builder.appendItem(new ReportItem("SPARQL", queryMetadata.getSparql()));
builder.appendItem(new ReportItem("Child Node ID", queryMetadata.getChildNodeId()));
builder.appendItem(new ReportItem("Count", "" + queryReport.getCount(queryMetadata.getNodeId())));
if (metadata.getQueryType() == QueryType.CONSTRUCT) {
builder.appendItem(new ReportItem(""));
final ConstructQueryMetadata constructMetadata = metadata.getConstructQueryMetadata().get();
builder.appendItem(new ReportItem("CONSTRUCT QUERY NODE"));
builder.appendItem(new ReportItem("Node ID", constructMetadata.getNodeId()));
builder.appendItem(new ReportItem("Variable Order", constructMetadata.getVariableOrder().toString()));
builder.appendItem(new ReportItem("Parent Node ID", constructMetadata.getParentNodeId()));
builder.appendItem(new ReportItem("Child Node ID", constructMetadata.getChildNodeId()));
builder.appendItem(new ReportItem("Construct Graph", constructMetadata.getConstructGraph().toString()));
builder.appendItem(new ReportItem("Count", "" + queryReport.getCount(constructMetadata.getNodeId())));
}
for (ProjectionMetadata projectionMetadata : metadata.getProjectionMetadata()) {
builder.appendItem(new ReportItem(""));
builder.appendItem(new ReportItem("PROJECTION NODE"));
builder.appendItem(new ReportItem("Node ID", projectionMetadata.getNodeId()));
builder.appendItem(new ReportItem("Variable Order", projectionMetadata.getVariableOrder().toString()));
builder.appendItem(new ReportItem("Parent Node ID", projectionMetadata.getParentNodeId()));
builder.appendItem(new ReportItem("Child Node ID", projectionMetadata.getChildNodeId()));
builder.appendItem(new ReportItem("Count", "" + queryReport.getCount(projectionMetadata.getNodeId())));
}
for (final FilterMetadata filterMetadata : metadata.getFilterMetadata()) {
builder.appendItem(new ReportItem(""));
builder.appendItem(new ReportItem("FILTER NODE"));
builder.appendItem(new ReportItem("Node ID", filterMetadata.getNodeId()));
builder.appendItem(new ReportItem("Variable Order", filterMetadata.getVariableOrder().toString()));
builder.appendItem(new ReportItem("Filter SPARQL", prettyFormatSparql(filterMetadata.getFilterSparql())));
builder.appendItem(new ReportItem("Parent Node ID", filterMetadata.getParentNodeId()));
builder.appendItem(new ReportItem("Child Node ID", filterMetadata.getChildNodeId()));
builder.appendItem(new ReportItem("Count", "" + queryReport.getCount(filterMetadata.getNodeId())));
}
for (final JoinMetadata joinMetadata : metadata.getJoinMetadata()) {
builder.appendItem(new ReportItem(""));
builder.appendItem(new ReportItem("JOIN NODE"));
builder.appendItem(new ReportItem("Node ID", joinMetadata.getNodeId()));
builder.appendItem(new ReportItem("Variable Order", joinMetadata.getVariableOrder().toString()));
builder.appendItem(new ReportItem("Parent Node ID", joinMetadata.getParentNodeId()));
builder.appendItem(new ReportItem("Left Child Node ID", joinMetadata.getLeftChildNodeId()));
builder.appendItem(new ReportItem("Right Child Node ID", joinMetadata.getRightChildNodeId()));
builder.appendItem(new ReportItem("Count", "" + queryReport.getCount(joinMetadata.getNodeId())));
}
for (final StatementPatternMetadata spMetadata : metadata.getStatementPatternMetadata()) {
builder.appendItem(new ReportItem(""));
builder.appendItem(new ReportItem("STATEMENT PATTERN NODE"));
builder.appendItem(new ReportItem("Node ID", spMetadata.getNodeId()));
builder.appendItem(new ReportItem("Variable Order", spMetadata.getVariableOrder().toString()));
builder.appendItem(new ReportItem("Statement Pattern", spMetadata.getStatementPattern()));
builder.appendItem(new ReportItem("Parent Node ID", spMetadata.getParentNodeId()));
builder.appendItem(new ReportItem("Count", "" + queryReport.getCount(spMetadata.getNodeId())));
}
return builder.build().toString();
}
use of org.apache.rya.indexing.pcj.fluo.api.GetQueryReport.QueryReport 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