Skip to content

Commit

Permalink
GH-5108 add a java system property to modify the limit for when we ca…
Browse files Browse the repository at this point in the history
…n still use SPARQL validation approach with sh:maxCount
  • Loading branch information
hmottestad committed Aug 14, 2024
1 parent 59eba18 commit 356809a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

0 comments on commit 356809a

Please sign in to comment.