Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-5153 max count cut off for sparql based validation #5154

Merged
merged 3 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.eclipse.rdf4j.model.Value;
import org.eclipse.rdf4j.model.base.CoreDatatype;
import org.eclipse.rdf4j.model.datatypes.XMLDatatypeUtil;
import org.eclipse.rdf4j.model.impl.BooleanLiteral;
import org.eclipse.rdf4j.model.util.Literals;
import org.eclipse.rdf4j.query.algebra.Compare.CompareOp;
import org.eclipse.rdf4j.query.algebra.evaluation.ValueExprEvaluationException;
Expand Down Expand Up @@ -62,6 +63,13 @@ public class QueryEvaluationUtil {
* @throws ValueExprEvaluationException In case the application of the EBV algorithm results in a type error.
*/
public static boolean getEffectiveBooleanValue(Value value) throws ValueExprEvaluationException {

if (value == BooleanLiteral.TRUE) {
return true;
} else if (value == BooleanLiteral.FALSE) {
return false;
}

if (value.isLiteral()) {
Literal literal = (Literal) value;
String label = literal.getLabel();
Expand Down Expand Up @@ -107,6 +115,15 @@ public static boolean compare(Value leftVal, Value rightVal, CompareOp operator)

public static boolean compare(Value leftVal, Value rightVal, CompareOp operator, boolean strict)
throws ValueExprEvaluationException {
if (leftVal == rightVal) {
switch (operator) {
case EQ:
return true;
case NE:
return false;
}
}

if (leftVal != null && leftVal.isLiteral() && rightVal != null && rightVal.isLiteral()) {
// Both left and right argument is a Literal
return compareLiterals((Literal) leftVal, (Literal) rightVal, operator, strict);
Expand Down Expand Up @@ -162,6 +179,15 @@ public static boolean compareLiterals(Literal leftLit, Literal rightLit, Compare
// - CoreDatatype.XSD:string
// - RDF term (equal and unequal only)

if (leftLit == rightLit) {
switch (operator) {
case EQ:
return true;
case NE:
return false;
}
}

CoreDatatype.XSD leftCoreDatatype = leftLit.getCoreDatatype().asXSDDatatypeOrNull();
CoreDatatype.XSD rightCoreDatatype = rightLit.getCoreDatatype().asXSDDatatypeOrNull();

Expand Down Expand Up @@ -329,7 +355,7 @@ && isSupportedDatatype(rightCoreDatatype)) {
* <a href="http://www.w3.org/TR/rdf-concepts/#section-blank-nodes">6.6 Blank Nodes of [CONCEPTS]</a>.
* </ul>
* </blockquote>
*
* <p>
* (emphasis ours)
* <p>
* When applying the SPARQL specification in a minimally-conforming manner, RDFterm-equal is supposed to return a
Expand All @@ -349,7 +375,6 @@ && isSupportedDatatype(rightCoreDatatype)) {
* @param rightCoreDatatype the right datatype to compare
* @throws ValueExprEvaluationException if query evaluation is operating in strict mode, and the two supplied
* datatypes are both supported datatypes but not comparable.
*
* @see <a href="https://github.com/eclipse/rdf4j/issues/3947">Github issue #3947</a>
*/
private static void validateDatatypeCompatibility(boolean strict, CoreDatatype.XSD leftCoreDatatype,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public class MaxCountConstraintComponent extends AbstractConstraintComponent {
// 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
public static long SPARQL_VALIDATION_APPROACH_LIMIT = System
.getProperty(SPARQL_VALIDATION_APPROACH_LIMIT_PROPERTY) == null ? 1
: Long.parseLong(System.getProperty(SPARQL_VALIDATION_APPROACH_LIMIT_PROPERTY));

private final long maxCount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,25 @@ public class BenchmarkConfigs {

public static List<List<Statement>> generateStatements(StatementCreator statementCreator) {

return generateStatements(NUMBER_OF_TRANSACTIONS, STATEMENTS_PER_TRANSACTION, NUMBER_OF_EMPTY_TRANSACTIONS,
statementCreator);
}

public static List<List<Statement>> generateStatements(int numberOfTransactions, int statementsPerTransaction,
int numberOfEmptyTransactions, StatementCreator statementCreator) {

List<List<Statement>> allStatements = new ArrayList<>();

for (int j = 0; j < BenchmarkConfigs.NUMBER_OF_TRANSACTIONS; j++) {
for (int j = 0; j < numberOfTransactions; j++) {
List<Statement> statements = new ArrayList<>();
allStatements.add(statements);
for (int i = 0; i < BenchmarkConfigs.STATEMENTS_PER_TRANSACTION; i++) {
for (int i = 0; i < statementsPerTransaction; i++) {

statementCreator.createStatement(statements, i, j);
}
}

for (int j = 0; j < BenchmarkConfigs.NUMBER_OF_EMPTY_TRANSACTIONS; j++) {
for (int j = 0; j < numberOfEmptyTransactions; j++) {
List<Statement> statements = new ArrayList<>();
allStatements.add(statements);
}
Expand Down
Loading
Loading