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

Unexpected parent for node after query parsing with aggregation #4992

Open
frensjan opened this issue May 29, 2024 · 1 comment
Open

Unexpected parent for node after query parsing with aggregation #4992

frensjan opened this issue May 29, 2024 · 1 comment
Labels
🐞 bug issue is a bug

Comments

@frensjan
Copy link
Contributor

frensjan commented May 29, 2024

It seems that there is a bug in constructing the tuple expression for queries with aggregations. E.g., this code throws an exception:

String query =
        """
        SELECT (COUNT(?s) AS ?count)
        WHERE { ?s ?p ?o  }
        """;

TupleExpr expr = new SPARQLParser().parseQuery(query, null).getTupleExpr();
new ParentReferenceChecker(null).optimize(expr, new SimpleDataset(), new EmptyBindingSet());

The exception message:

java.lang.AssertionError: After query parsing there was an unexpected parent for node Count
   Var (name=s)
: ExtensionElem (count)
   Count
      Var (name=s)
 (expected GroupElem (count)
   Count
      Var (name=s)
)

There aren't any issues with the query execution. But it does cause issues with optimisers that e.g. replace nodes. The exact 'location' the parent reference is mixed up seems to depend on the query 'shape' a bit. E.g., with a more complex expression in the projection like SELECT (COUNT(?s)/30 AS ?count) it's the ?s ?p ?o StatementPattern that gets the wrong parent reference.

Version

4.3.8

Are you interested in contributing a solution yourself?

Perhaps?

@frensjan frensjan added the 🐞 bug issue is a bug label May 29, 2024
frensjan added a commit to frensjan/rdf4j that referenced this issue May 29, 2024
frensjan added a commit to frensjan/rdf4j that referenced this issue May 29, 2024
@frensjan
Copy link
Contributor Author

I've added parent reference checking in SPARQLParserTest in this branch:

These tests then fail:

  • testGroupByProjectionHandling_Aggregate_Alias
  • testGroupByProjectionHandling_Aggregate_Constant
  • testGroupByProjectionHandling_Aggregate_SimpleExpr2
  • testGroupByProjectionHandling_function
  • testGroupByProjectionHandling_renameVariableWithAggregation
  • testGroupByProjectionHandling_variableEffectivelyAggregationResult
  • testProjectionHandling_CustomAggregateFunction
  • testProjectionHandling_HavingCustomAggregateFunction
  • testProjectionHandling_MultipleAggregateFunction

testParseWildcardSubselectInUpdate also fails, but not for the same reason.

I think I've been able to track down the issue to this line in TupleExprBuilder.java. At least that's where for a particular case I've seen the wrong link being made.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug issue is a bug
Projects
None yet
Development

No branches or pull requests

1 participant