From 356809a06a3d2558568b1323dd21c55decd61d19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ha=CC=8Avard=20Ottestad?= Date: Wed, 14 Aug 2024 10:50:09 +0200 Subject: [PATCH] GH-5108 add a java system property to modify the limit for when we can still use SPARQL validation approach with sh:maxCount --- .../MaxCountConstraintComponent.java | 21 ++++++++++++++++--- .../MaxLengthConstraintComponent.java | 2 +- .../MinCountConstraintComponent.java | 2 +- .../MinLengthConstraintComponent.java | 2 +- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/MaxCountConstraintComponent.java b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/MaxCountConstraintComponent.java index 6adefc57fee..d52be57f429 100644 --- a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/MaxCountConstraintComponent.java +++ b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/MaxCountConstraintComponent.java @@ -44,9 +44,20 @@ import org.eclipse.rdf4j.sail.shacl.ast.planNodes.ValidationTuple; import org.eclipse.rdf4j.sail.shacl.ast.targets.EffectiveTarget; import org.eclipse.rdf4j.sail.shacl.wrapper.data.ConnectionsGroup; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class MaxCountConstraintComponent extends AbstractConstraintComponent { + private static final Logger logger = LoggerFactory.getLogger(MaxCountConstraintComponent.class); + + // Performance degrades quickly as the maxCount increases when using a SPARQL Validation Approach. The default is 5, + // but it can be tuned using the system property below. + private static final String SPARQL_VALIDATION_APPROACH_LIMIT_PROPERTY = "org.eclipse.rdf4j.sail.shacl.ast.constraintcomponents.MaxCountConstraintComponent.sparqlValidationApproachLimit"; + private static final long SPARQL_VALIDATION_APPROACH_LIMIT = System + .getProperty(SPARQL_VALIDATION_APPROACH_LIMIT_PROPERTY) == null ? 5 + : Long.parseLong(System.getProperty(SPARQL_VALIDATION_APPROACH_LIMIT_PROPERTY)); + private final long maxCount; public MaxCountConstraintComponent(long maxCount) { @@ -216,8 +227,12 @@ public ValidationQuery generateSparqlValidationQuery(ConnectionsGroup connection @Override public ValidationApproach getOptimalBulkValidationApproach() { - // performance of large maxCount is terrible - if (maxCount > 5) { + if (maxCount > SPARQL_VALIDATION_APPROACH_LIMIT) { + if (logger.isDebugEnabled()) { + logger.debug( + "maxCount is {}, which is greater than the limit of {}, using ValidationApproach.Transactional instead of ValidationApproach.SPARQL for {}", + maxCount, SPARQL_VALIDATION_APPROACH_LIMIT, stringRepresentationOfValue(getId())); + } return ValidationApproach.Transactional; } return ValidationApproach.SPARQL; @@ -244,6 +259,6 @@ public boolean equals(Object o) { @Override public int hashCode() { - return (int) (maxCount ^ (maxCount >>> 32)) + "MaxCountConstraintComponent".hashCode(); + return Long.hashCode(maxCount) + "MaxCountConstraintComponent".hashCode(); } } diff --git a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/MaxLengthConstraintComponent.java b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/MaxLengthConstraintComponent.java index a24d9d312bc..25259b05206 100644 --- a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/MaxLengthConstraintComponent.java +++ b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/MaxLengthConstraintComponent.java @@ -89,6 +89,6 @@ public boolean equals(Object o) { @Override public int hashCode() { - return (int) (maxLength ^ (maxLength >>> 32)) + "MaxLengthConstraintComponent".hashCode(); + return Long.hashCode(maxLength) + "MaxLengthConstraintComponent".hashCode(); } } diff --git a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/MinCountConstraintComponent.java b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/MinCountConstraintComponent.java index 7d67d7fc855..090c4310ef2 100644 --- a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/MinCountConstraintComponent.java +++ b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/MinCountConstraintComponent.java @@ -227,6 +227,6 @@ public boolean equals(Object o) { @Override public int hashCode() { - return (int) (minCount ^ (minCount >>> 32)) + "MinCountConstraintComponent".hashCode(); + return Long.hashCode(minCount) + "MinCountConstraintComponent".hashCode(); } } diff --git a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/MinLengthConstraintComponent.java b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/MinLengthConstraintComponent.java index 47e9ec119a0..9b8ef2ce966 100644 --- a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/MinLengthConstraintComponent.java +++ b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/MinLengthConstraintComponent.java @@ -89,6 +89,6 @@ public boolean equals(Object o) { @Override public int hashCode() { - return (int) (minLength ^ (minLength >>> 32)) + "MinLengthConstraintComponent".hashCode(); + return Long.hashCode(minLength) + "MinLengthConstraintComponent".hashCode(); } }