Search in sources :

Example 1 with QueryMetadata

use of org.apache.rya.indexing.pcj.fluo.app.query.QueryMetadata 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 QueryMetadata

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

the class ListFluoQueriesIT method queryMetadataTest.

@Test
public void queryMetadataTest() throws Exception {
    final FluoQueryMetadataDAO dao = new FluoQueryMetadataDAO();
    String sparql1 = "select ?x ?y ?z where {?x <uri:p1> ?y; <uri:p2> 'literal1'. ?y <uri:p3> ?z }";
    String sparql2 = "select ?x ?y ?z where {{select ?x ?y ?z {?x <uri:p1> ?y; <uri:p2> ?z. ?y <uri:p3> ?z }}}";
    // Create the object that will be serialized.
    String queryId1 = NodeType.generateNewFluoIdForType(NodeType.QUERY);
    final QueryMetadata.Builder builder = QueryMetadata.builder(queryId1);
    builder.setQueryType(QueryType.PROJECTION);
    builder.setVarOrder(new VariableOrder("y;s;d"));
    builder.setSparql(sparql1);
    builder.setChildNodeId("childNodeId");
    builder.setExportStrategies(new HashSet<>(Arrays.asList(ExportStrategy.KAFKA)));
    final QueryMetadata meta1 = builder.build();
    String queryId2 = NodeType.generateNewFluoIdForType(NodeType.QUERY);
    final QueryMetadata.Builder builder2 = QueryMetadata.builder(queryId2);
    builder2.setQueryType(QueryType.PROJECTION);
    builder2.setVarOrder(new VariableOrder("y;s;d"));
    builder2.setSparql(sparql2);
    builder2.setChildNodeId("childNodeId");
    builder2.setExportStrategies(new HashSet<>(Arrays.asList(ExportStrategy.RYA)));
    final QueryMetadata meta2 = builder2.build();
    try (FluoClient fluoClient = FluoFactory.newClient(super.getFluoConfiguration())) {
        // Write it to the Fluo table.
        try (Transaction tx = fluoClient.newTransaction()) {
            dao.write(tx, meta1);
            dao.write(tx, meta2);
            tx.commit();
        }
        ListFluoQueries listFluoQueries = new ListFluoQueries();
        List<String> queries = listFluoQueries.listFluoQueries(fluoClient);
        FluoQueryStringBuilder queryBuilder1 = new FluoQueryStringBuilder();
        String expected1 = queryBuilder1.setQueryId(queryId1).setQueryType(QueryType.PROJECTION).setQuery(sparql1).setExportStrategies(Sets.newHashSet(ExportStrategy.KAFKA)).build();
        FluoQueryStringBuilder queryBuilder2 = new FluoQueryStringBuilder();
        String expected2 = queryBuilder2.setQueryId(queryId2).setQueryType(QueryType.PROJECTION).setQuery(sparql2).setExportStrategies(Sets.newHashSet(ExportStrategy.RYA)).build();
        Set<String> expected = new HashSet<>();
        expected.add(expected1);
        expected.add(expected2);
        Assert.assertEquals(expected, Sets.newHashSet(queries));
    }
}
Also used : QueryMetadata(org.apache.rya.indexing.pcj.fluo.app.query.QueryMetadata) FluoClient(org.apache.fluo.api.client.FluoClient) VariableOrder(org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder) FluoQueryMetadataDAO(org.apache.rya.indexing.pcj.fluo.app.query.FluoQueryMetadataDAO) Transaction(org.apache.fluo.api.client.Transaction) FluoQueryStringBuilder(org.apache.rya.indexing.pcj.fluo.api.ListFluoQueries.FluoQueryStringBuilder) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with QueryMetadata

use of org.apache.rya.indexing.pcj.fluo.app.query.QueryMetadata 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)

Example 4 with QueryMetadata

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

the class QueryResultObserver method process.

@Override
public void process(final TransactionBase tx, final Bytes brow, final Column col) throws Exception {
    // Read the queryId from the row and get the QueryMetadata.
    final String queryId = BindingSetRow.makeFromShardedRow(Bytes.of(QUERY_PREFIX), brow).getNodeId();
    final QueryMetadata metadata = queryDao.readQueryMetadata(tx, queryId);
    // Read the Child Binding Set that will be exported.
    final Bytes valueBytes = tx.get(brow, col);
    exporterManager.export(metadata.getQueryType(), metadata.getExportStrategies(), queryId, valueBytes);
}
Also used : Bytes(org.apache.fluo.api.data.Bytes) QueryMetadata(org.apache.rya.indexing.pcj.fluo.app.query.QueryMetadata)

Aggregations

QueryMetadata (org.apache.rya.indexing.pcj.fluo.app.query.QueryMetadata)4 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 HashSet (java.util.HashSet)1 FluoClient (org.apache.fluo.api.client.FluoClient)1 Transaction (org.apache.fluo.api.client.Transaction)1 Bytes (org.apache.fluo.api.data.Bytes)1 VisibilityBindingSet (org.apache.rya.api.model.VisibilityBindingSet)1 QueryReport (org.apache.rya.indexing.pcj.fluo.api.GetQueryReport.QueryReport)1 FluoQueryStringBuilder (org.apache.rya.indexing.pcj.fluo.api.ListFluoQueries.FluoQueryStringBuilder)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 FluoQueryMetadataDAO (org.apache.rya.indexing.pcj.fluo.app.query.FluoQueryMetadataDAO)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 VariableOrder (org.apache.rya.indexing.pcj.storage.accumulo.VariableOrder)1