Skip to content

Commit

Permalink
GH-5139 fix bug in sh:qualifiedMaxCount
Browse files Browse the repository at this point in the history
  • Loading branch information
hmottestad committed Nov 21, 2024
1 parent e1c3e4b commit de41bf7
Show file tree
Hide file tree
Showing 37 changed files with 300 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,12 @@ public SourceConstraintComponent getConstraintComponent() {

@Override
public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] dataGraph, Scope scope,
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider) {
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider,
ValidationSettings validationSettings) {

PlanNode planNode = constraintComponents.stream()
.map(c -> c.getAllTargetsPlan(connectionsGroup, dataGraph, Scope.nodeShape,
new StatementMatcher.StableRandomVariableProvider()))
new StatementMatcher.StableRandomVariableProvider(), validationSettings))
.distinct()
.reduce((nodes, nodes2) -> UnionNode.getInstanceDedupe(connectionsGroup, nodes, nodes2))
.orElse(EmptyNode.getInstance());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,11 @@ constraintComponent, getSeverity(), t.getScope(), t.getContexts(),

@Override
public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] dataGraph, Scope scope,
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider) {
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider,
ValidationSettings validationSettings) {
PlanNode planNode = constraintComponents.stream()
.map(c -> c.getAllTargetsPlan(connectionsGroup, dataGraph, Scope.propertyShape,
new StatementMatcher.StableRandomVariableProvider()))
new StatementMatcher.StableRandomVariableProvider(), validationSettings))
.distinct()
.reduce((nodes, nodes2) -> UnionNode.getInstanceDedupe(connectionsGroup, nodes, nodes2))
.orElse(EmptyNode.getInstance());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ public boolean requiresEvaluation(ConnectionsGroup connectionsGroup, Scope scope

@Override
public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] dataGraph, Scope scope,
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider) {
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider,
ValidationSettings validationSettings) {
throw new UnsupportedOperationException();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ private PlanNode getAllTargetsBasedOnPredicate(ConnectionsGroup connectionsGroup

@Override
public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] dataGraph, Scope scope,
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider) {
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider,
ValidationSettings validationSettings) {
if (scope == Scope.propertyShape) {
PlanNode allTargetsPlan = getTargetChain()
.getEffectiveTarget(Scope.nodeShape, connectionsGroup.getRdfsSubClassOfReasoner(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,8 @@ String literalToString(Literal literal) {

@Override
public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] dataGraph, Scope scope,
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider) {
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider,
ValidationSettings validationSettings) {

if (scope == Scope.propertyShape) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,11 @@ public PlanNode generateTransactionalValidationPlan(ConnectionsGroup connections

@Override
public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] dataGraph, Scope scope,
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider) {
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider,
ValidationSettings validationSettings) {
PlanNode planNode = and.stream()
.map(c -> c.getAllTargetsPlan(connectionsGroup, dataGraph, scope,
new StatementMatcher.StableRandomVariableProvider()))
new StatementMatcher.StableRandomVariableProvider(), validationSettings))
.distinct()
.reduce((nodes, nodes2) -> UnionNode.getInstanceDedupe(connectionsGroup, nodes, nodes2))
.orElse(EmptyNode.getInstance());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ public PlanNode generateTransactionalValidationPlan(ConnectionsGroup connections

@Override
public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] dataGraph, Scope scope,
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider) {
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider,
ValidationSettings validationSettings) {
if (scope == Scope.propertyShape) {
PlanNode allTargetsPlan = getTargetChain()
.getEffectiveTarget(Scope.nodeShape, connectionsGroup.getRdfsSubClassOfReasoner(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,8 @@ public PlanNode generateTransactionalValidationPlan(ConnectionsGroup connections

@Override
public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] dataGraph, Scope scope,
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider) {
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider,
ValidationSettings validationSettings) {

EffectiveTarget effectiveTarget = getTargetChain().getEffectiveTarget(scope,
connectionsGroup.getRdfsSubClassOfReasoner(), stableRandomVariableProvider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ boolean requiresEvaluation(ConnectionsGroup connectionsGroup, Scope scope, Resou
SourceConstraintComponent getConstraintComponent();

PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] dataGraph, Scope scope,
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider);
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider,
ValidationSettings validationSettings);

SparqlFragment buildSparqlValidNodes_rsx_targetShape(Variable<Value> subject,
Variable<Value> object, RdfsSubClassOfReasoner rdfsSubClassOfReasoner, Scope scope,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ public PlanNode generateTransactionalValidationPlan(ConnectionsGroup connections

@Override
public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] dataGraph, Scope scope,
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider) {
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider,
ValidationSettings validationSettings) {
if (scope == Scope.propertyShape) {
PlanNode allTargetsPlan = getTargetChain()
.getEffectiveTarget(Scope.nodeShape, connectionsGroup.getRdfsSubClassOfReasoner(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ public PlanNode generateTransactionalValidationPlan(ConnectionsGroup connections

@Override
public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] dataGraph, Scope scope,
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider) {
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider,
ValidationSettings validationSettings) {
if (scope == Scope.propertyShape) {
PlanNode allTargetsPlan = getTargetChain()
.getEffectiveTarget(Scope.nodeShape, connectionsGroup.getRdfsSubClassOfReasoner(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ public PlanNode generateTransactionalValidationPlan(ConnectionsGroup connections

@Override
public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] dataGraph, Scope scope,
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider) {
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider,
ValidationSettings validationSettings) {
if (scope == Scope.propertyShape) {
PlanNode allTargetsPlan = getTargetChain()
.getEffectiveTarget(Scope.nodeShape, connectionsGroup.getRdfsSubClassOfReasoner(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ public PlanNode generateTransactionalValidationPlan(ConnectionsGroup connections

@Override
public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] dataGraph, Scope scope,
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider) {
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider,
ValidationSettings validationSettings) {
return EmptyNode.getInstance();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public PlanNode generateTransactionalValidationPlan(ConnectionsGroup connections
planNodeProvider = overrideTargetNode;
} else {
planNodeProvider = () -> getAllTargetsPlan(connectionsGroup, validationSettings.getDataGraph(), scope,
stableRandomVariableProvider);
stableRandomVariableProvider, validationSettings);
}

PlanNode planNode = not.generateTransactionalValidationPlan(
Expand Down Expand Up @@ -166,7 +166,8 @@ public PlanNode generateTransactionalValidationPlan(ConnectionsGroup connections

@Override
public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] dataGraph, Scope scope,
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider) {
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider,
ValidationSettings validationSettings) {
PlanNode allTargets;

if (scope == Scope.propertyShape) {
Expand All @@ -186,7 +187,7 @@ public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[]
}

PlanNode notTargets = not.getAllTargetsPlan(connectionsGroup, dataGraph, scope,
new StatementMatcher.StableRandomVariableProvider());
new StatementMatcher.StableRandomVariableProvider(), validationSettings);

return Unique.getInstance(UnionNode.getInstanceDedupe(connectionsGroup, allTargets, notTargets), false,
connectionsGroup);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public PlanNode generateTransactionalValidationPlan(ConnectionsGroup connections
} else {
planNodeProvider = BufferedSplitter.getInstance(
getAllTargetsPlan(connectionsGroup, validationSettings.getDataGraph(), scope,
stableRandomVariableProvider),
stableRandomVariableProvider, validationSettings),
false);
}

Expand All @@ -141,7 +141,8 @@ public PlanNode generateTransactionalValidationPlan(ConnectionsGroup connections

@Override
public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] dataGraph, Scope scope,
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider) {
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider,
ValidationSettings validationSettings) {
PlanNode allTargets;

if (scope == Scope.propertyShape) {
Expand All @@ -162,7 +163,7 @@ public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[]

PlanNode planNode = or.stream()
.map(or -> or.getAllTargetsPlan(connectionsGroup, dataGraph, scope,
new StatementMatcher.StableRandomVariableProvider()))
new StatementMatcher.StableRandomVariableProvider(), validationSettings))
.distinct()
.reduce((nodes, nodes2) -> UnionNode.getInstanceDedupe(connectionsGroup, nodes, nodes2))
.orElse(EmptyNode.getInstance());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@
import org.eclipse.rdf4j.sail.shacl.ast.Cache;
import org.eclipse.rdf4j.sail.shacl.ast.NodeShape;
import org.eclipse.rdf4j.sail.shacl.ast.PropertyShape;
import org.eclipse.rdf4j.sail.shacl.ast.ShaclParsingException;
import org.eclipse.rdf4j.sail.shacl.ast.ShaclProperties;
import org.eclipse.rdf4j.sail.shacl.ast.ShaclUnsupportedException;
import org.eclipse.rdf4j.sail.shacl.ast.Shape;
import org.eclipse.rdf4j.sail.shacl.ast.StatementMatcher;
import org.eclipse.rdf4j.sail.shacl.ast.ValidationQuery;
import org.eclipse.rdf4j.sail.shacl.ast.paths.Path;
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.AbstractBulkJoinPlanNode;
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.BulkedExternalLeftOuterJoin;
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.GroupByCountFilter;
Expand Down Expand Up @@ -121,22 +123,27 @@ public ValidationQuery generateSparqlValidationQuery(ConnectionsGroup connection
public PlanNode generateTransactionalValidationPlan(ConnectionsGroup connectionsGroup,
ValidationSettings validationSettings,
PlanNodeProvider overrideTargetNode, Scope scope) {
assert scope == Scope.propertyShape;

if (scope != Scope.propertyShape) {
throw new ShaclParsingException(
"QualifiedMaxCountConstraintComponent can only be used on property shapes!");
}

StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider = new StatementMatcher.StableRandomVariableProvider();

PlanNode target;

EffectiveTarget effectiveTarget = getTargetChain().getEffectiveTarget(scope,
connectionsGroup.getRdfsSubClassOfReasoner(), stableRandomVariableProvider);

if (overrideTargetNode != null) {
target = getTargetChain()
.getEffectiveTarget(scope, connectionsGroup.getRdfsSubClassOfReasoner(),
stableRandomVariableProvider)
target = effectiveTarget
.extend(overrideTargetNode.getPlanNode(), connectionsGroup, validationSettings.getDataGraph(),
scope, EffectiveTarget.Extend.right,
false, null);
} else {
target = getAllTargetsPlan(connectionsGroup, validationSettings.getDataGraph(), scope,
stableRandomVariableProvider);
stableRandomVariableProvider, validationSettings);
}

PlanNode planNode = negated(connectionsGroup, validationSettings, overrideTargetNode, scope);
Expand All @@ -160,7 +167,7 @@ public PlanNode negated(ConnectionsGroup connectionsGroup, ValidationSettings va

if (overrideTargetNode == null) {
target = getAllTargetsPlan(connectionsGroup, validationSettings.getDataGraph(), scope,
stableRandomVariableProvider);
stableRandomVariableProvider, validationSettings);
} else {
target = getTargetChain()
.getEffectiveTarget(scope, connectionsGroup.getRdfsSubClassOfReasoner(),
Expand Down Expand Up @@ -205,7 +212,7 @@ public PlanNode negated(ConnectionsGroup connectionsGroup, ValidationSettings va

if (overrideTargetNode == null) {
allTargetsPlan = getAllTargetsPlan(connectionsGroup, validationSettings.getDataGraph(), scope,
stableRandomVariableProvider);
stableRandomVariableProvider, validationSettings);
} else {
allTargetsPlan = getTargetChain()
.getEffectiveTarget(scope, connectionsGroup.getRdfsSubClassOfReasoner(),
Expand Down Expand Up @@ -237,20 +244,29 @@ public PlanNode negated(ConnectionsGroup connectionsGroup, ValidationSettings va

@Override
public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] dataGraph, Scope scope,
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider) {
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider,
ValidationSettings validationSettings) {
assert scope == Scope.propertyShape;

PlanNode allTargets = getTargetChain()
EffectiveTarget effectiveTarget = getTargetChain()
.getEffectiveTarget(Scope.propertyShape, connectionsGroup.getRdfsSubClassOfReasoner(),
stableRandomVariableProvider)
.getPlanNode(connectionsGroup, dataGraph, Scope.propertyShape, true, null);
stableRandomVariableProvider);

PlanNode subTargets = qualifiedValueShape.getAllTargetsPlan(connectionsGroup, dataGraph, scope,
new StatementMatcher.StableRandomVariableProvider());
Path path = getTargetChain().getPath().orElseThrow();

return Unique
.getInstance(new TrimToTarget(UnionNode.getInstanceDedupe(connectionsGroup, allTargets, subTargets),
connectionsGroup), false, connectionsGroup);
PlanNode allTargets = getAllTargetsIncludingThoseAddedByPath(connectionsGroup, validationSettings, scope,
effectiveTarget, path, false);

PlanNode subTargets = qualifiedValueShape.getAllTargetsPlan(connectionsGroup, dataGraph, scope,
new StatementMatcher.StableRandomVariableProvider(), validationSettings);

return Unique.getInstance(
new TrimToTarget(
UnionNode.getInstanceDedupe(connectionsGroup, allTargets, subTargets),
connectionsGroup
),
false, connectionsGroup
);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public PlanNode generateTransactionalValidationPlan(ConnectionsGroup connections
false, null);
} else {
target = getAllTargetsPlan(connectionsGroup, validationSettings.getDataGraph(), scope,
stableRandomVariableProvider);
stableRandomVariableProvider, validationSettings);
}

PlanNode planNode = negated(connectionsGroup, validationSettings, overrideTargetNode, scope);
Expand All @@ -163,7 +163,7 @@ public PlanNode negated(ConnectionsGroup connectionsGroup, ValidationSettings va

if (overrideTargetNode == null) {
target = getAllTargetsPlan(connectionsGroup, validationSettings.getDataGraph(), scope,
stableRandomVariableProvider);
stableRandomVariableProvider, validationSettings);
} else {
PlanNode planNode = overrideTargetNode.getPlanNode();
if (planNode instanceof AllTargetsPlanNode) {
Expand Down Expand Up @@ -211,7 +211,7 @@ public PlanNode negated(ConnectionsGroup connectionsGroup, ValidationSettings va
PlanNode allTargetsPlan;
if (overrideTargetNode == null) {
allTargetsPlan = getAllTargetsPlan(connectionsGroup, validationSettings.getDataGraph(), scope,
stableRandomVariableProvider);
stableRandomVariableProvider, validationSettings);
} else {
allTargetsPlan = getTargetChain()
.getEffectiveTarget(scope, connectionsGroup.getRdfsSubClassOfReasoner(),
Expand Down Expand Up @@ -252,7 +252,8 @@ public PlanNode negated(ConnectionsGroup connectionsGroup, ValidationSettings va

@Override
public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] dataGraph, Scope scope,
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider) {
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider,
ValidationSettings validationSettings) {
assert scope == Scope.propertyShape;

PlanNode allTargets = getTargetChain()
Expand All @@ -261,7 +262,7 @@ public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[]
.getPlanNode(connectionsGroup, dataGraph, Scope.propertyShape, true, null);

PlanNode subTargets = qualifiedValueShape.getAllTargetsPlan(connectionsGroup, dataGraph, scope,
new StatementMatcher.StableRandomVariableProvider());
new StatementMatcher.StableRandomVariableProvider(), validationSettings);

return Unique
.getInstance(new TrimToTarget(UnionNode.getInstanceDedupe(connectionsGroup, allTargets, subTargets),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ private PlanNode getPlanNodeForOverrideTargetNode(ConnectionsGroup connectionsGr

@Override
public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] dataGraph, Scope scope,
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider) {
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider,
ValidationSettings validationSettings) {
return getTargetChain()
.getEffectiveTarget(scope, connectionsGroup.getRdfsSubClassOfReasoner(), stableRandomVariableProvider)
.getAllTargets(connectionsGroup, dataGraph, scope);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ public PlanNode generateTransactionalValidationPlan(ConnectionsGroup connections

@Override
public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] dataGraph, Scope scope,
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider) {
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider,
ValidationSettings validationSettings) {
if (scope == Scope.propertyShape) {
PlanNode allTargetsPlan = getTargetChain()
.getEffectiveTarget(Scope.nodeShape, connectionsGroup.getRdfsSubClassOfReasoner(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ public PlanNode generateTransactionalValidationPlan(ConnectionsGroup connections

@Override
public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] dataGraph, Scope scope,
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider) {
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider,
ValidationSettings validationSettings) {
return EmptyNode.getInstance();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ public SparqlFragment getTargetQueryFragment(StatementMatcher.Variable subject,
new SingletonBindingSet(subjectName, statement.getSubject()), true)) {
while (evaluate.hasNext()) {
BindingSet next = evaluate.next();
System.out.println(next);
statements.add(new EffectiveTarget.SubjectObjectAndMatcher.SubjectObject(
((Resource) next.getValue(subject.getName())), null));
}
Expand Down
Loading

0 comments on commit de41bf7

Please sign in to comment.