Search in sources :

Example 1 with ConstructQueryMetadata

use of org.apache.rya.indexing.pcj.fluo.app.query.ConstructQueryMetadata 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();
}
Also used : QueryMetadata(org.apache.rya.indexing.pcj.fluo.app.query.QueryMetadata) ConstructQueryMetadata(org.apache.rya.indexing.pcj.fluo.app.query.ConstructQueryMetadata) QueryReport(org.apache.rya.indexing.pcj.fluo.api.GetQueryReport.QueryReport) StatementPatternMetadata(org.apache.rya.indexing.pcj.fluo.app.query.StatementPatternMetadata) FilterMetadata(org.apache.rya.indexing.pcj.fluo.app.query.FilterMetadata) ProjectionMetadata(org.apache.rya.indexing.pcj.fluo.app.query.ProjectionMetadata) JoinMetadata(org.apache.rya.indexing.pcj.fluo.app.query.JoinMetadata) FluoQuery(org.apache.rya.indexing.pcj.fluo.app.query.FluoQuery) ReportItem(org.apache.rya.indexing.pcj.fluo.client.util.Report.ReportItem) ConstructQueryMetadata(org.apache.rya.indexing.pcj.fluo.app.query.ConstructQueryMetadata)

Example 2 with ConstructQueryMetadata

use of org.apache.rya.indexing.pcj.fluo.app.query.ConstructQueryMetadata in project incubator-rya by apache.

the class BindingSetUpdater method process.

@Override
public final void process(final TransactionBase tx, final Bytes row, final Column col) {
    checkNotNull(tx);
    checkNotNull(row);
    checkNotNull(col);
    final Observation observation;
    try {
        observation = parseObservation(tx, row);
    } catch (final Exception e) {
        log.error("Unable to parse an Observation from a Row and Column pair, so this notification will be skipped. " + "Row: " + row + " Column: " + col, e);
        return;
    }
    final String observedNodeId = observation.getObservedNodeId();
    final VisibilityBindingSet observedBindingSet = observation.getObservedBindingSet();
    final String parentNodeId = observation.getParentId();
    // Figure out which node needs to handle the new metadata.
    final NodeType parentNodeType = NodeType.fromNodeId(parentNodeId).get();
    switch(parentNodeType) {
        case QUERY:
            final QueryMetadata parentQuery = queryDao.readQueryMetadata(tx, parentNodeId);
            try {
                queryUpdater.updateQueryResults(tx, observedBindingSet, parentQuery);
            } catch (final Exception e) {
                throw new RuntimeException("Could not process a Query node.", e);
            }
            break;
        case PROJECTION:
            final ProjectionMetadata projectionQuery = queryDao.readProjectionMetadata(tx, parentNodeId);
            try {
                projectionUpdater.updateProjectionResults(tx, observedBindingSet, projectionQuery);
            } catch (final Exception e) {
                throw new RuntimeException("Could not process a Query node.", e);
            }
            break;
        case CONSTRUCT:
            final ConstructQueryMetadata constructQuery = queryDao.readConstructQueryMetadata(tx, parentNodeId);
            try {
                constructUpdater.updateConstructQueryResults(tx, observedBindingSet, constructQuery);
            } catch (final Exception e) {
                throw new RuntimeException("Could not process a Query node.", e);
            }
            break;
        case FILTER:
            final FilterMetadata parentFilter = queryDao.readFilterMetadata(tx, parentNodeId);
            try {
                filterUpdater.updateFilterResults(tx, observedBindingSet, parentFilter);
            } catch (final Exception e) {
                throw new RuntimeException("Could not process a Filter node.", e);
            }
            break;
        case JOIN:
            final JoinMetadata parentJoin = queryDao.readJoinMetadata(tx, parentNodeId);
            try {
                joinUpdater.updateJoinResults(tx, observedNodeId, observedBindingSet, parentJoin);
            } catch (final Exception e) {
                throw new RuntimeException("Could not process a Join node.", e);
            }
            break;
        case PERIODIC_QUERY:
            final PeriodicQueryMetadata parentPeriodicQuery = queryDao.readPeriodicQueryMetadata(tx, parentNodeId);
            try {
                periodicQueryUpdater.updatePeriodicBinResults(tx, observedBindingSet, parentPeriodicQuery);
            } catch (Exception e) {
                throw new RuntimeException("Could not process PeriodicBin node.", e);
            }
            break;
        case AGGREGATION:
            final AggregationMetadata parentAggregation = queryDao.readAggregationMetadata(tx, parentNodeId);
            try {
                aggregationUpdater.updateAggregateResults(tx, observedBindingSet, parentAggregation);
            } catch (final Exception e) {
                throw new RuntimeException("Could not process an Aggregation node.", e);
            }
            break;
        default:
            throw new IllegalArgumentException("The parent node's NodeType must be of type Aggregation, Projection, ConstructQuery, Filter, Join, PeriodicBin or Query, but was " + parentNodeType);
    }
}
Also used : VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) ConstructQueryMetadata(org.apache.rya.indexing.pcj.fluo.app.query.ConstructQueryMetadata) QueryMetadata(org.apache.rya.indexing.pcj.fluo.app.query.QueryMetadata) PeriodicQueryMetadata(org.apache.rya.indexing.pcj.fluo.app.query.PeriodicQueryMetadata) PeriodicQueryMetadata(org.apache.rya.indexing.pcj.fluo.app.query.PeriodicQueryMetadata) ProjectionMetadata(org.apache.rya.indexing.pcj.fluo.app.query.ProjectionMetadata) JoinMetadata(org.apache.rya.indexing.pcj.fluo.app.query.JoinMetadata) NodeType(org.apache.rya.indexing.pcj.fluo.app.NodeType) FilterMetadata(org.apache.rya.indexing.pcj.fluo.app.query.FilterMetadata) AggregationMetadata(org.apache.rya.indexing.pcj.fluo.app.query.AggregationMetadata) ConstructQueryMetadata(org.apache.rya.indexing.pcj.fluo.app.query.ConstructQueryMetadata)

Aggregations

ConstructQueryMetadata (org.apache.rya.indexing.pcj.fluo.app.query.ConstructQueryMetadata)2 FilterMetadata (org.apache.rya.indexing.pcj.fluo.app.query.FilterMetadata)2 JoinMetadata (org.apache.rya.indexing.pcj.fluo.app.query.JoinMetadata)2 ProjectionMetadata (org.apache.rya.indexing.pcj.fluo.app.query.ProjectionMetadata)2 QueryMetadata (org.apache.rya.indexing.pcj.fluo.app.query.QueryMetadata)2 VisibilityBindingSet (org.apache.rya.api.model.VisibilityBindingSet)1 QueryReport (org.apache.rya.indexing.pcj.fluo.api.GetQueryReport.QueryReport)1 NodeType (org.apache.rya.indexing.pcj.fluo.app.NodeType)1 AggregationMetadata (org.apache.rya.indexing.pcj.fluo.app.query.AggregationMetadata)1 FluoQuery (org.apache.rya.indexing.pcj.fluo.app.query.FluoQuery)1 PeriodicQueryMetadata (org.apache.rya.indexing.pcj.fluo.app.query.PeriodicQueryMetadata)1 StatementPatternMetadata (org.apache.rya.indexing.pcj.fluo.app.query.StatementPatternMetadata)1 ReportItem (org.apache.rya.indexing.pcj.fluo.client.util.Report.ReportItem)1