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