Search in sources :

Example 1 with BOp

use of com.bigdata.bop.BOp 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 BOp

use of com.bigdata.bop.BOp in project wikidata-query-rdf by wikimedia.

the class WikidataServicePlacementOptimizer method checkArbitraryLengthPathNode.

private boolean checkArbitraryLengthPathNode(StaticAnalysis sa, ArbitraryLengthPathNode node, Set<IVariable<?>> projectedVars) {
    BOp left = node.left();
    BOp right = node.right();
    return checkIfNodeProducesVars(sa, left, projectedVars) || checkIfNodeProducesVars(sa, right, projectedVars);
}
Also used : BOp(com.bigdata.bop.BOp)

Example 3 with BOp

use of com.bigdata.bop.BOp in project wikidata-query-rdf by wikimedia.

the class WikidataServicePlacementOptimizer method findLatestPossiblePositionForTheServiceNode.

private int findLatestPossiblePositionForTheServiceNode(StaticAnalysis sa, BOp serviceNode, final JoinGroupNode joinGroup) {
    int lastJoinIndex = -1;
    // Retrieve inVars from annotations. If no WIKIDATA_SERVICE_IN_VARS annotation provided
    // (which occurs on first run of LabelServicePlacementOptimizer), we still need to
    // traverse the tree, as there might be NamedSubqueryInclude, which might
    // be producing variables for ServiceNode.
    Object inVarsObject = serviceNode.annotations().get(WIKIDATA_SERVICE_IN_VARS);
    @SuppressWarnings("unchecked") Set<IVariable<?>> inVars = inVarsObject instanceof Set ? (Set<IVariable<?>>) inVarsObject : Collections.emptySet();
    for (int i = joinGroup.size() - 1; i >= 0; i--) {
        BOp child = joinGroup.get(i);
        if (child != serviceNode && child instanceof IBindingProducerNode) {
            // will touch any inbound var for the service
            if (checkIfNodeProducesVars(sa, child, inVars)) {
                lastJoinIndex = i;
                break;
            }
        }
    }
    return lastJoinIndex;
}
Also used : BOp(com.bigdata.bop.BOp) Set(java.util.Set) IBindingSet(com.bigdata.bop.IBindingSet) IVariable(com.bigdata.bop.IVariable) IBindingProducerNode(com.bigdata.rdf.sparql.ast.IBindingProducerNode)

Example 4 with BOp

use of com.bigdata.bop.BOp in project wikidata-query-rdf by wikimedia.

the class LabelService method findResolutions.

/**
 * Create the resolutions list from the service call parameters.
 */
static List<Resolution> findResolutions(final ServiceNode params) {
    JoinGroupNode g = (JoinGroupNode) params.getGraphPattern();
    List<Resolution> resolutions = new ArrayList<>(g.args().size());
    for (BOp st : g.args()) {
        StatementPatternNode sn = (StatementPatternNode) st;
        if (sn.s().isConstant() && BD.SERVICE_PARAM.equals(sn.s().getValue())) {
            // skip service params
            continue;
        }
        resolutions.add(new Resolution(sn));
    }
    return resolutions;
}
Also used : BOp(com.bigdata.bop.BOp) ArrayList(java.util.ArrayList) JoinGroupNode(com.bigdata.rdf.sparql.ast.JoinGroupNode) StatementPatternNode(com.bigdata.rdf.sparql.ast.StatementPatternNode)

Example 5 with BOp

use of com.bigdata.bop.BOp 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)5 JoinGroupNode (com.bigdata.rdf.sparql.ast.JoinGroupNode)3 StatementPatternNode (com.bigdata.rdf.sparql.ast.StatementPatternNode)3 IVariable (com.bigdata.bop.IVariable)2 QueryRoot (com.bigdata.rdf.sparql.ast.QueryRoot)2 ArrayList (java.util.ArrayList)2 IBindingSet (com.bigdata.bop.IBindingSet)1 IBindingProducerNode (com.bigdata.rdf.sparql.ast.IBindingProducerNode)1 SubqueryBase (com.bigdata.rdf.sparql.ast.SubqueryBase)1 Set (java.util.Set)1