371 [SPARQL 1.1 Update] - Parser and AST : LOAD and CLEAR Query#452
371 [SPARQL 1.1 Update] - Parser and AST : LOAD and CLEAR Query#452MaillPierre wants to merge 7 commits into
Conversation
|
162c4a8 to
12a9589
Compare
|
| default -> throw new QueryEvaluationException("Could not determine the type of query during parsing"); | ||
| }; | ||
| } else { // Update query | ||
| return switch (this.queryType) { |
There was a problem hiding this comment.
The grammar allows chained updates, but the builder returns only one update operation.
Example:
LOAD <a> INTO GRAPH <g> ;
LOAD <b>A fix would be to build an update request AST with a list of update operations, and create one AST node per update.
There was a problem hiding this comment.
@Test
void chainedLoadShouldCreateTwoUpdateOperations() {
QueryParser parser = newParserDefault();
String query = """
LOAD <http://example.org/a> INTO GRAPH <http://example.org/g> ;
LOAD <http://example.org/b>
""";
QueryAst queryAst = parser.parse(query);
UpdateRequestAst update = assertInstanceOf(UpdateRequestAst.class, queryAst);
assertEquals(2, update.operations().size());
LoadQueryAst first = assertInstanceOf(LoadQueryAst.class, update.operations().get(0));
assertEquals("<http://example.org/a>", first.fromClause().graph().raw());
assertNotNull(first.toClause());
assertEquals("<http://example.org/g>", first.toClause().graph().raw());
LoadQueryAst second = assertInstanceOf(LoadQueryAst.class, update.operations().get(1));
assertEquals("<http://example.org/b>", second.fromClause().graph().raw());
assertNull(second.toClause());
}| /** | ||
| * Root interface for all queries related to the SPARQL Update queries listed in <a href="https://www.w3.org/TR/sparql11-update/">SPARQL 1.1 Update</>. | ||
| */ | ||
| public sealed interface UpdateQueryAst extends QueryAst permits LoadQueryAst, ClearQueryAst { |
There was a problem hiding this comment.
Updates can start with BASE and PREFIX, but the update AST does not keep the prologue.
Example:
PREFIX ex: <http://example.org/>
LOAD ex:dataThere was a problem hiding this comment.
@Test
void updateShouldKeepPrologue() {
QueryParser parser = newParserDefault();
String query = """
PREFIX ex: <http://example.org/>
LOAD ex:data
""";
QueryAst queryAst = parser.parse(query);
UpdateRequestAst update = assertInstanceOf(UpdateRequestAst.class, queryAst);
assertEquals(1, update.operations().size());
assertTrue(update.prologue().prefixDeclarations().stream()
.anyMatch(prefixDecl ->
prefixDecl.prefix().equals("ex")
&& prefixDecl.namespace().raw().equals("http://example.org/")));
assertInstanceOf(LoadQueryAst.class, update.operations().get(0));
}| super(builder); | ||
| } | ||
|
|
||
| public void exitLoad(SparqlParser.LoadContext ctx) { |
There was a problem hiding this comment.
Add the "@OverRide" annotation above this method signature
| @@ -5,10 +5,7 @@ | |||
| import org.slf4j.Logger; | |||
There was a problem hiding this comment.
The import org.slf4j.Logger is never used
| @@ -5,10 +5,7 @@ | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
There was a problem hiding this comment.
Remove this unused import 'org.slf4j.LoggerFactory'.
| @@ -20,7 +20,7 @@ public void inlineSyntaxTest() { | |||
| VALUES ?var { "test" <http://ns.inria.fr/test> } | |||
There was a problem hiding this comment.
Remove this unused import 'fr.inria.corese.core.next.query.api.exception.QueryEvaluationException'.
| } | ||
| """; |
There was a problem hiding this comment.
Remove this unused "logger" private field.
| @@ -20,7 +20,7 @@ public void inlineSyntaxTest() { | |||
| VALUES ?var { "test" <http://ns.inria.fr/test> } | |||
| } | |||
There was a problem hiding this comment.
Remove this unused import 'fr.inria.corese.core.next.query.api.exception.QuerySyntaxException'.
| @@ -385,7 +385,7 @@ void whereClauseAccessor() { | |||
| GroupGraphPatternAst where = new GroupGraphPatternAst(List.of( | |||
There was a problem hiding this comment.
The import fr.inria.corese.core.next.query.impl.sparql.ast is never used
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public record GraphRefAst(IriAst graph, boolean named, boolean all, boolean defaultGraph) { |
There was a problem hiding this comment.
This constructor allows invalid mixed states such as an explicit graph together with named, all, or defaultGraph.
It may be safer to reject these combinations here as well.
This aims to add the update queries LOAD and CLEAR.
Breaking change: A new sub-interface SPARQLQueryAst is inserted between QueryAst and the SELECT, CONSTRUCT, etc queries. A new sub-interface for update queries is also added at the same level.
Furthermore, the declaration of a prologue or of a where clause is delegated to interfaces that can be used both in updates and regular queries.
Explanation:
Update queries can be graph management queries (such as LOAD) or graph update queries (INSERT,DELETE). Graph management have no prologue and no WHERE clause.