Feature/381 sparql 11 variable visibility#454
Conversation
|
Test Results 414 files 414 suites 19s ⏱️ Results for commit 9ad9945. ♻️ This comment has been updated with latest results. |
|
|
MaillPierre
left a comment
There was a problem hiding this comment.
I have some comments before approving because I'm lost by some changes.
| QueryAst ast = parser.parse(""" | ||
| SELECT * WHERE { | ||
| ?s ?p ?o . | ||
| BIND(IF(BOUND(?s), COUNT(?o), ?p) AS ?result) |
There was a problem hiding this comment.
Can you explain this test please ? I don't understand where the aggregate is.
There was a problem hiding this comment.
Here the aggregate is COUNT(?o) inside the IF(...) expression.
This test is here to check collectReferencedVariablesOutsideAggregates(...)
The query itself does not really make sense as a full example.
It is only used to build a AST with some variables outside an aggregate and one variable inside an aggregate
The only part really used by the test is:
BIND(IF(BOUND(?s), COUNT(?o), ?p) AS ?result)
In this expression:
?sis outside the aggregate?pis outside the aggregate?ois insideCOUNT(?o)
So the helper should keep ?s and ?p, and ignore ?o
|
|
||
| QueryAst ast = parser.parse(""" | ||
| SELECT ?s WHERE { | ||
| SELECT (AVG(?val) AS ?avg) WHERE { |
There was a problem hiding this comment.
Why change that ? AVG(?val) appears twice in the query now.
There was a problem hiding this comment.
I changed it because the old query was not valid
In the old version SELECT ?s ... ORDER BY AVG(?val)
AVG(?val) makes the query an aggregate query, but ?s is not grouped and not aggregated.
The new version keeps the same thing we want to test (ORDER BY AVG(?val)), but also makes the full query valid: SELECT (AVG(?val) AS ?avg) ... ORDER BY AVG(?val)
So yes, AVG(?val) appears twice, once to make the query valid and once because this is the ORDER BY expression we want to parse
| WHERE { | ||
| ?s ?p ?o . | ||
| } | ||
| ORDER BY ?s |
There was a problem hiding this comment.
This is grammatically correct ... It does not make any sense, though. Only HAVING and LIMIT would impact the query execution.
This is just a comment.
There was a problem hiding this comment.
Yes, I agree.
This test is mainly here for parser/AST consistency.
It is not here because ORDER BY is especially useful for ASK.
I first had this kind of check for SELECT, and in this PR I extended it to the other query forms too, to keep the behavior consistent.
So here the goal is only to check that ORDER BY is parsed and stored correctly in the AST for ASK.
|
|
||
| private void validateProjectionExpression( | ||
| String projectionVariableName, | ||
| ProjectionAst projection, |
There was a problem hiding this comment.
add GROUP BY.
Set<String> groupedVariables,
| return; | ||
| } | ||
| for (String referencedVariable : collectReferencedVariablesOutsideAggregates(expression)) { | ||
| diagnostics.add(buildGroupedProjectionDiagnostic(referencedVariable)); |
There was a problem hiding this comment.
if (!groupedVariables.contains(referencedVariable)) {
diagnostics.add(buildGroupedProjectionDiagnostic(referencedVariable));
}
There was a problem hiding this comment.
we can add the following test :
@Test
@DisplayName("Should accept grouped SELECT expression using a variable from GROUP BY ?var")
void shouldAcceptGroupedSelectExpressionUsingGroupedVariable() {
SparqlParser parser = newParserDefault();
QueryAst ast = parser.parse("""
SELECT ?groupedVar (STR(?groupedVar) AS ?alias) WHERE {
?groupedVar ?p ?o
}
GROUP BY ?groupedVar
""");
SelectQueryAst selectQueryAst = assertInstanceOf(SelectQueryAst.class, ast);
ProjectionAst projection = selectQueryAst.projection();
assertFalse(projection.selectAll());
assertEquals(2, projection.variables().size());
assertEquals("groupedVar", projection.variables().get(0).name());
assertEquals("alias", projection.variables().get(1).name());
assertTrue(projection.expressionBoundVariables().contains("alias"));
}
Implemented for issue #381.
GROUP BYHAVINGSELECT (expr AS ?var)SELECTclauseORDER BYscope validation forASKqueriesSELECTORDER BYscope validation to includeVALUESSELECTprojection validation:GROUP BYSELECT *whenGROUP BYis presentGROUP BY (expr AS ?alias)GROUP BYexpression aliases in:SELECTHAVINGORDER BYHAVINGvalidation:ORDER BYvalidation:ORDER BY