Skip to content

Commit 09afe01

Browse files
committed
GH-1112 minor optimizations
1 parent 2652dcb commit 09afe01

2 files changed

Lines changed: 38 additions & 29 deletions

File tree

core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/ClassConstraintComponent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public PlanNode generateTransactionalValidationPlan(ConnectionsGroup connections
186186
stableRandomVariableProvider)
187187
.extend(deletedTypes, connectionsGroup, validationSettings.getDataGraph(), scope,
188188
EffectiveTarget.Extend.left, false, null);
189-
addedTargets = UnionNode.getInstance(addedTargets, new TrimToTarget(deletedTypes));
189+
addedTargets = UnionNode.getInstance(addedTargets, deletedTypes);
190190
}
191191
}
192192

core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/ClosedConstraintComponent.java

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.BufferedSplitter;
4040
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.BulkedExternalInnerJoin;
4141
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.ExternalFilterByQuery;
42-
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.NotValuesIn;
4342
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.PlanNode;
4443
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.PlanNodeProvider;
4544
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.ReduceTargets;
@@ -233,6 +232,7 @@ public PlanNode generateTransactionalValidationPlan(ConnectionsGroup connections
233232
return falseNode1;
234233

235234
} else {
235+
assert scope == Scope.nodeShape;
236236

237237
PlanNode targetNodePlanNode;
238238

@@ -248,18 +248,17 @@ public PlanNode generateTransactionalValidationPlan(ConnectionsGroup connections
248248
scope, false, null);
249249

250250
// get all subjects of all triples where the predicate is not in the allAllowedPredicates set
251-
UnorderedSelect unorderedSelect = new UnorderedSelect(connectionsGroup.getAddedStatements(), null, null,
251+
PlanNode unorderedSelect = new UnorderedSelect(connectionsGroup.getAddedStatements(), null, null,
252252
null, validationSettings.getDataGraph(),
253253
UnorderedSelect.Mapper.SubjectScopedMapper.getFunction(scope), (statement -> {
254254
return !allAllowedPredicates.contains(statement.getPredicate());
255255
}));
256256

257257
// then remove any that are in the addedTargets node
258-
NotValuesIn notValuesIn = new NotValuesIn(unorderedSelect, addedTargets);
258+
PlanNode notValuesIn = new ReduceTargets(unorderedSelect, addedTargets);
259259

260-
// trim to target and remove duplicates
261-
TrimToTarget trimToTarget = new TrimToTarget(notValuesIn);
262-
PlanNode unique = Unique.getInstance(trimToTarget, false);
260+
// remove duplicates
261+
PlanNode unique = Unique.getInstance(notValuesIn, false);
263262

264263
// then check that the rest are actually targets
265264
PlanNode targetFilter = effectiveTarget.getTargetFilter(connectionsGroup,
@@ -286,7 +285,7 @@ public PlanNode generateTransactionalValidationPlan(ConnectionsGroup connections
286285
SparqlFragment sparqlFragment = SparqlFragment.join(List.of(bgp, sparqlFragmentFilter));
287286

288287
BulkedExternalInnerJoin bulkedExternalInnerJoin = new BulkedExternalInnerJoin(
289-
Unique.getInstance(new TrimToTarget(targetNodePlanNode), false),
288+
Unique.getInstance(targetNodePlanNode, false),
290289
connectionsGroup.getBaseConnection(),
291290
validationSettings.getDataGraph(),
292291
sparqlFragment,
@@ -331,41 +330,51 @@ public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[]
331330
throw new IllegalStateException();
332331
case nodeShape:
333332

334-
PlanNode targets = effectiveTarget.getPlanNode(connectionsGroup, dataGraph,
335-
scope, true, null);
336-
337-
// get all subjects of all triples where the predicate is not in the allAllowedPredicates set
338-
PlanNode unorderedSelectAdded = new UnorderedSelect(connectionsGroup.getAddedStatements(), null, null,
339-
null, dataGraph,
340-
UnorderedSelect.Mapper.SubjectScopedMapper.getFunction(scope),
341-
(statement -> !allAllowedPredicates.contains(statement.getPredicate())));
342-
333+
BufferedSplitter targets = new BufferedSplitter(
334+
effectiveTarget.getPlanNode(connectionsGroup, dataGraph, scope, false,
335+
null));
343336
// get all subjects of all triples where the predicate is not in the allAllowedPredicates set
344-
PlanNode unorderedSelectRemoved = new UnorderedSelect(connectionsGroup.getRemovedStatements(), null, null,
337+
PlanNode statementsNotMatchingPredicateList = new UnorderedSelect(connectionsGroup.getAddedStatements(),
338+
null, null,
345339
null, dataGraph,
346340
UnorderedSelect.Mapper.SubjectScopedMapper.getFunction(scope),
347341
(statement -> !allAllowedPredicates.contains(statement.getPredicate())));
348342

349343
// then remove any that are in the targets node
350-
unorderedSelectAdded = new TrimToTarget(new NotValuesIn(unorderedSelectAdded, targets));
351-
unorderedSelectRemoved = new TrimToTarget(new NotValuesIn(unorderedSelectRemoved, targets));
352-
353-
// union and remove duplicates
354-
PlanNode unique = Unique.getInstance(UnionNode.getInstance(unorderedSelectAdded, unorderedSelectRemoved),
355-
false);
344+
statementsNotMatchingPredicateList = new ReduceTargets(statementsNotMatchingPredicateList,
345+
targets.getPlanNode());
356346

357347
// then check that the rest are actually targets
358-
PlanNode targetFilter = effectiveTarget.getTargetFilter(connectionsGroup,
348+
statementsNotMatchingPredicateList = effectiveTarget.getTargetFilter(connectionsGroup,
359349
dataGraph,
360-
unique);
350+
statementsNotMatchingPredicateList);
351+
352+
if (connectionsGroup.getStats().hasRemoved()) {
353+
354+
// get all subjects of all triples where the predicate is not in the allAllowedPredicates set
355+
PlanNode removed = new UnorderedSelect(connectionsGroup.getRemovedStatements(), null, null,
356+
null, dataGraph,
357+
UnorderedSelect.Mapper.SubjectScopedMapper.getFunction(scope),
358+
(statement -> !allAllowedPredicates.contains(statement.getPredicate())));
359+
360+
removed = new ReduceTargets(removed, targets.getPlanNode());
361+
362+
// then check that the rest are actually targets
363+
removed = effectiveTarget.getTargetFilter(connectionsGroup, dataGraph, removed);
364+
365+
statementsNotMatchingPredicateList = UnionNode.getInstance(statementsNotMatchingPredicateList, removed);
366+
367+
}
368+
369+
// union and remove duplicates
370+
PlanNode unique = Unique.getInstance(statementsNotMatchingPredicateList, false);
361371

362372
// this should now be targets that are not valid
363-
PlanNode extend = effectiveTarget.extend(targetFilter, connectionsGroup,
373+
PlanNode extend = effectiveTarget.extend(unique, connectionsGroup,
364374
dataGraph,
365375
scope, EffectiveTarget.Extend.left, false, null);
366376

367-
return UnionNode.getInstance(extend, effectiveTarget.getPlanNode(connectionsGroup,
368-
dataGraph, scope, true, null));
377+
return extend;
369378

370379
case propertyShape:
371380
Path path = getTargetChain().getPath().get();

0 commit comments

Comments
 (0)