-
Notifications
You must be signed in to change notification settings - Fork 169
GH-5314: add validation check for construct query template #5321
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
base: develop
Are you sure you want to change the base?
GH-5314: add validation check for construct query template #5321
Conversation
c38d1ab
to
2ae8560
Compare
2ae8560
to
e2bf139
Compare
@@ -1,5 +1,5 @@ | |||
/******************************************************************************* | |||
* Copyright (c) 2015 Eclipse RDF4J contributors, Aduna, and others. | |||
* Copyright (c) 2025 Eclipse RDF4J contributors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you revert the copyright headers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
|
||
// recursively check child nodes | ||
for (int i = 0; i < node.jjtGetNumChildren(); i++) { | ||
if (isInvalidConstructQueryTemplate(node.jjtGetChild(i), isInConstructTemplate)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have an example query that recurses several levels deep?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, it's provided as an invalid test case.
@Test
public void testInvalidConstructQueryWithZeroOrMorePathInPredicate() {
String invalidSparqlQuery = "PREFIX foaf: <http://xmlns.com/foaf/0.1/> " +
"CONSTRUCT {\n" +
" ?s foaf:knows* ?o . " +
"}\n" +
"WHERE {\n" +
" ?s foaf:knows* ?o .\n" +
"} ";
assertThrows(MalformedQueryException.class, () -> {
parser.parseQuery(invalidSparqlQuery, null);
});
}
@Test
public void testInvalidConstructQueryWithZeroOrMorePathInPredicates() {
String invalidSparqlQuery = "PREFIX foaf: <http://xmlns.com/foaf/0.1/> " +
"CONSTRUCT {\n" +
" ?s foaf:knows ?o . " +
" ?s foaf:name+ ?o . " +
"}\n" +
"WHERE {\n" +
" ?s foaf:knows* ?o .\n" +
" ?s foaf:name ?o .\n" +
"} ";
assertThrows(MalformedQueryException.class, () -> {
parser.parseQuery(invalidSparqlQuery, null);
});
}
@hmottestad is this a piece of code where you are familiar with to do a review? A bit of background on why we propose the change: as many others we are currently integrating capabilities of LLMs. And the LLM sometimes produces property path expressions in the CONSTRUCT block. We now ideally want to detect such syntactical errors using static validation and with RDF4J library support |
GitHub issue resolved: #5314
Briefly describe the changes proposed in this PR:
add validation check for construct query template
PR Author Checklist (see the contributor guidelines for more details):
mvn process-resources
to format from the command line)