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));
}
});
}
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);
}
});
}
Aggregations