Search in sources :

Example 1 with QueryRoot

use of com.bigdata.rdf.sparql.ast.QueryRoot in project wikidata-query-rdf by wikimedia.

the class EmptyLabelServiceOptimizer method optimizeJoinGroup.

@Override
protected void optimizeJoinGroup(AST2BOpContext ctx, StaticAnalysis sa, IBindingSet[] bSets, JoinGroupNode op) {
    final QueryRoot root = sa.getQueryRoot();
    if (root.getQueryType() == QueryType.ASK) {
        return;
    }
    if (root.getWhereClause() == op) {
        op.setProperty(LABEL_SERVICE_PROJECTION, root.getProjection());
    }
    op.getChildren(SubqueryBase.class).forEach(node -> {
        if (node.getWhereClause() != null) {
            BOp whereClause = node.getWhereClause();
            whereClause.setProperty(LABEL_SERVICE_PROJECTION, node.getProjection());
        }
    });
    // Prepare a set of vars, which might be bound both outside of the service and by LabelService
    // Fix for the issue: https://phabricator.wikimedia.org/T159723
    // See also patch for the com.bigdata.rdf.sparql.ast.eval.AST2BOpUtility.addServiceCall()
    Set<IVariable<?>> uncertainVars = collectUncertainVars(sa, bSets, op);
    getLabelServiceNodes(op).forEach(service -> {
        service.setUncertainVars(uncertainVars);
        JoinGroupNode g = (JoinGroupNode) service.getGraphPattern();
        boolean foundArg = false;
        for (BOp st : g.args()) {
            StatementPatternNode sn = (StatementPatternNode) st;
            if (sn.s().isConstant() && BD.SERVICE_PARAM.equals(sn.s().getValue())) {
                continue;
            }
            foundArg = true;
            break;
        }
        if (restoreExtracted(service)) {
            foundArg = true;
        }
        if (!foundArg) {
            addResolutions(ctx, g, getProjectionNode(service));
        }
    });
}
Also used : BOp(com.bigdata.bop.BOp) QueryRoot(com.bigdata.rdf.sparql.ast.QueryRoot) IVariable(com.bigdata.bop.IVariable) SubqueryBase(com.bigdata.rdf.sparql.ast.SubqueryBase) JoinGroupNode(com.bigdata.rdf.sparql.ast.JoinGroupNode) StatementPatternNode(com.bigdata.rdf.sparql.ast.StatementPatternNode)

Example 2 with QueryRoot

use of com.bigdata.rdf.sparql.ast.QueryRoot in project wikidata-query-rdf by wikimedia.

the class LabelServiceExtractOptimizer method optimizeJoinGroup.

@Override
protected void optimizeJoinGroup(AST2BOpContext ctx, StaticAnalysis sa, IBindingSet[] bSets, JoinGroupNode op) {
    final QueryRoot root = sa.getQueryRoot();
    if (root.getQueryType() == QueryType.ASK) {
        return;
    }
    LabelServiceUtils.getLabelServiceNodes(op).forEach(service -> {
        JoinGroupNode g = (JoinGroupNode) service.getGraphPattern();
        final List<StatementPatternNode> extractedNodes = new ArrayList<>();
        for (BOp st : g.args()) {
            StatementPatternNode sn = (StatementPatternNode) st;
            if (sn.s().isConstant() && BD.SERVICE_PARAM.equals(sn.s().getValue())) {
                if (WikidataServicePlacementOptimizer.DISABLE_REORDERING.equals(sn.p().getValue())) {
                    String flag = sn.o().getValue().stringValue();
                    service.annotations().put(WikidataServicePlacementOptimizer.DISABLE_REORDERING_ANNOTATION, Boolean.valueOf(flag));
                }
                // skip parameters
                continue;
            }
            extractedNodes.add(sn);
        }
        for (BOp node : extractedNodes) {
            g.removeArg(node);
        }
        if (!extractedNodes.isEmpty()) {
            service.annotations().put(EXTRACTOR_ANNOTATION, extractedNodes);
        }
    });
}
Also used : BOp(com.bigdata.bop.BOp) QueryRoot(com.bigdata.rdf.sparql.ast.QueryRoot) ArrayList(java.util.ArrayList) JoinGroupNode(com.bigdata.rdf.sparql.ast.JoinGroupNode) StatementPatternNode(com.bigdata.rdf.sparql.ast.StatementPatternNode)

Aggregations

BOp (com.bigdata.bop.BOp)2 JoinGroupNode (com.bigdata.rdf.sparql.ast.JoinGroupNode)2 QueryRoot (com.bigdata.rdf.sparql.ast.QueryRoot)2 StatementPatternNode (com.bigdata.rdf.sparql.ast.StatementPatternNode)2 IVariable (com.bigdata.bop.IVariable)1 SubqueryBase (com.bigdata.rdf.sparql.ast.SubqueryBase)1 ArrayList (java.util.ArrayList)1