use of org.apache.rya.indexing.pcj.fluo.client.util.Report.ReportItem in project incubator-rya by apache.
the class ReportTests method singleLineValues.
@Test
public void singleLineValues() {
final Report.Builder builder = Report.builder();
builder.appendItem(new ReportItem("Title 1", new String[] { "Short value." }));
builder.appendItem(new ReportItem("Title 2", new String[] { "This is the longest values that appears in the report." }));
builder.appendItem(new ReportItem("This is a long title", new String[] { "Short value." }));
final Report report = builder.build();
final String expected = "---------------------------------------------------------------------------------\n" + "| Title 1 | Short value. |\n" + "| Title 2 | This is the longest values that appears in the report. |\n" + "| This is a long title | Short value. |\n" + "---------------------------------------------------------------------------------\n";
assertEquals(expected, report.toString());
}
use of org.apache.rya.indexing.pcj.fluo.client.util.Report.ReportItem in project incubator-rya by apache.
the class ReportTests method emptyValues.
@Test
public void emptyValues() {
final Report.Builder builder = Report.builder();
builder.appendItem(new ReportItem("No Value Here", new String[] {}));
builder.appendItem(new ReportItem("Value Here", new String[] { "This one has a value." }));
final Report report = builder.build();
final String expected = "-----------------------------------------\n" + "| No Value Here | |\n" + "| Value Here | This one has a value. |\n" + "-----------------------------------------\n";
assertEquals(expected, report.toString());
}
use of org.apache.rya.indexing.pcj.fluo.client.util.Report.ReportItem in project incubator-rya by apache.
the class ReportTests method multiLineValues.
@Test
public void multiLineValues() {
final Report.Builder builder = Report.builder();
builder.appendItem(new ReportItem("Title 1", new String[] { "Value 1" }));
builder.appendItem(new ReportItem("Multiple Lines", new String[] { "This is the first line.", "This is the second line." }));
builder.appendItem(new ReportItem("Title 2", new String[] { "Value 2" }));
final Report report = builder.build();
final String expected = "---------------------------------------------\n" + "| Title 1 | Value 1 |\n" + "| Multiple Lines | This is the first line. |\n" + "| | This is the second line. |\n" + "| Title 2 | Value 2 |\n" + "---------------------------------------------\n";
assertEquals(expected, report.toString());
}
use of org.apache.rya.indexing.pcj.fluo.client.util.Report.ReportItem 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.client.util.Report.ReportItem in project incubator-rya by apache.
the class PcjMetadataRenderer method render.
/**
* Pretty render the state of a PCJ.
*
* @param queryId - The ID of the query the metadata is from. (not null)
* @param metadata - Metadata about one of the PCJs. (not null)
* @return A pretty render of a PCJ's state.
* @throws Exception The SPARQL within the metadata could not be parsed or
* it could not be rendered.
*/
public String render(final String queryId, final PcjMetadata metadata) throws Exception {
checkNotNull(metadata);
// Pretty format the cardinality.
final String cardinality = NumberFormat.getInstance().format(metadata.getCardinality());
// Pretty format and split the SPARQL query into lines.
final SPARQLParser parser = new SPARQLParser();
final SPARQLQueryRenderer renderer = new SPARQLQueryRenderer();
final ParsedQuery pq = parser.parseQuery(metadata.getSparql(), null);
final String prettySparql = renderer.render(pq);
final String[] sparqlLines = StringUtils.split(prettySparql, '\n');
// Split the variable orders into lines.
final String[] varOrderLines = new String[metadata.getVarOrders().size()];
int i = 0;
for (final VariableOrder varOrder : metadata.getVarOrders()) {
varOrderLines[i++] = varOrder.toString();
}
// Create the report.
final Report.Builder builder = Report.builder();
builder.appendItem(new ReportItem("Query ID", queryId));
builder.appendItem(new ReportItem("Cardinality", cardinality));
builder.appendItem(new ReportItem("Export Variable Orders", varOrderLines));
builder.appendItem(new ReportItem("SPARQL", sparqlLines));
return builder.build().toString();
}
Aggregations