Skip to content

Commit eab7272

Browse files
authored
GH-5108 add a java system property to modify the limit for when we can still use SPARQL validation approach with sh:maxCount (#5109)
2 parents 20fb23f + 356809a commit eab7272

4 files changed

Lines changed: 21 additions & 6 deletions

File tree

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,20 @@
4444
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.ValidationTuple;
4545
import org.eclipse.rdf4j.sail.shacl.ast.targets.EffectiveTarget;
4646
import org.eclipse.rdf4j.sail.shacl.wrapper.data.ConnectionsGroup;
47+
import org.slf4j.Logger;
48+
import org.slf4j.LoggerFactory;
4749

4850
public class MaxCountConstraintComponent extends AbstractConstraintComponent {
4951

52+
private static final Logger logger = LoggerFactory.getLogger(MaxCountConstraintComponent.class);
53+
54+
// Performance degrades quickly as the maxCount increases when using a SPARQL Validation Approach. The default is 5,
55+
// but it can be tuned using the system property below.
56+
private static final String SPARQL_VALIDATION_APPROACH_LIMIT_PROPERTY = "org.eclipse.rdf4j.sail.shacl.ast.constraintcomponents.MaxCountConstraintComponent.sparqlValidationApproachLimit";
57+
private static final long SPARQL_VALIDATION_APPROACH_LIMIT = System
58+
.getProperty(SPARQL_VALIDATION_APPROACH_LIMIT_PROPERTY) == null ? 5
59+
: Long.parseLong(System.getProperty(SPARQL_VALIDATION_APPROACH_LIMIT_PROPERTY));
60+
5061
private final long maxCount;
5162

5263
public MaxCountConstraintComponent(long maxCount) {
@@ -216,8 +227,12 @@ public ValidationQuery generateSparqlValidationQuery(ConnectionsGroup connection
216227

217228
@Override
218229
public ValidationApproach getOptimalBulkValidationApproach() {
219-
// performance of large maxCount is terrible
220-
if (maxCount > 5) {
230+
if (maxCount > SPARQL_VALIDATION_APPROACH_LIMIT) {
231+
if (logger.isDebugEnabled()) {
232+
logger.debug(
233+
"maxCount is {}, which is greater than the limit of {}, using ValidationApproach.Transactional instead of ValidationApproach.SPARQL for {}",
234+
maxCount, SPARQL_VALIDATION_APPROACH_LIMIT, stringRepresentationOfValue(getId()));
235+
}
221236
return ValidationApproach.Transactional;
222237
}
223238
return ValidationApproach.SPARQL;
@@ -244,6 +259,6 @@ public boolean equals(Object o) {
244259

245260
@Override
246261
public int hashCode() {
247-
return (int) (maxCount ^ (maxCount >>> 32)) + "MaxCountConstraintComponent".hashCode();
262+
return Long.hashCode(maxCount) + "MaxCountConstraintComponent".hashCode();
248263
}
249264
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,6 @@ public boolean equals(Object o) {
8989

9090
@Override
9191
public int hashCode() {
92-
return (int) (maxLength ^ (maxLength >>> 32)) + "MaxLengthConstraintComponent".hashCode();
92+
return Long.hashCode(maxLength) + "MaxLengthConstraintComponent".hashCode();
9393
}
9494
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,6 @@ public boolean equals(Object o) {
227227

228228
@Override
229229
public int hashCode() {
230-
return (int) (minCount ^ (minCount >>> 32)) + "MinCountConstraintComponent".hashCode();
230+
return Long.hashCode(minCount) + "MinCountConstraintComponent".hashCode();
231231
}
232232
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,6 @@ public boolean equals(Object o) {
8989

9090
@Override
9191
public int hashCode() {
92-
return (int) (minLength ^ (minLength >>> 32)) + "MinLengthConstraintComponent".hashCode();
92+
return Long.hashCode(minLength) + "MinLengthConstraintComponent".hashCode();
9393
}
9494
}

0 commit comments

Comments
 (0)