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-2883: Fix for an NPE in OpAsQuery. #2884

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Aklakan
Copy link
Contributor

@Aklakan Aklakan commented Dec 7, 2024

GitHub issue resolved #2883

Pull request Description: Changed a line to pass on an ExprTransform rather than null.

Notes for possible further improvements outside the scope of this PR:

  • It may be the case that ElementTransformer needs to create an identity ExprTransform rather than passing null into the machinery.
  • QueryTransformOps.transformVarExprList in my IDE warns that the changed flag is not used. Perhaps this needlessly creates clones of queries w.r.t. identity transforms.

  • Tests are included.
  • Commits have been squashed to remove intermediate development commit messages.
  • Key commit messages start with the issue number (GH-xxxx)

By submitting this pull request, I acknowledge that I am making a contribution to the Apache Software Foundation under the terms and conditions of the Contributor's Agreement.


See the Apache Jena "Contributing" guide.

@@ -69,7 +69,7 @@ public static Query transform(Query query, ElementTransform transform, ExprTrans
Query q2 = QueryTransformOps.shallowCopy(query);
// Mutate the q2 structures which are already allocated and no other code can access yet.

mutateByQueryType(q2, transform, exprTransform);
mutateByQueryType(q2, exprTransform);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed unused argument.

@Aklakan Aklakan force-pushed the 2024-12-08_op-as-query-fix branch 2 times, most recently from 0a6a054 to 994ace2 Compare December 8, 2024 00:25
@@ -482,6 +482,21 @@ public void testMinus02() {
"SELECT * { GRAPH ?g { { ?x ?y ?z FILTER(EXISTS { ?s ?p ?o }) } ?x ?y ?z } }",
syntaxARQ); }

@Test
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These EXISTS tests are about the ARQ extensions.

IIRC It's not about EXISTS, it's about subquery select expressions.

If that's right please use this test (insert at around L463):

  @Test
  public void testSubQuery01() {
      test_roundTripQuery("SELECT ?z { SELECT ?x {  } }");
  }

The outer SELECT ?z stops the outer SELECT getting removed because SELECT * is a no-op.

Copy link
Contributor Author

@Aklakan Aklakan Dec 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your query does not fail for me. See my note on the PR discussion.

@Aklakan Aklakan force-pushed the 2024-12-08_op-as-query-fix branch from 994ace2 to e18ab07 Compare December 8, 2024 14:28
@@ -329,6 +329,11 @@ public void testSubQuery3() {
test_roundTripQuery(query) ;
}

@Test
public void testSubQuery4() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this test case for completeness - but it did not fail.

@Aklakan
Copy link
Contributor Author

Aklakan commented Dec 8, 2024

My change is in here:

public Expr transform(ExprFunctionOp funcOp, ExprList args, Op opArg)
{
    Element el2 = ElementTransformer.transform(funcOp.getElement(), transform, this);
}

ExprFunctionOp is the base class for (NOT) EXISTS - so the issue is related to (NOT) EXISTS when there is a subquery.
Also note that, the transform is an ElementTransform - so SELECT * { ?y a ?z } is treated differently than ?y a ?z - although the Op would be the same.

I reduced the query to this:

SELECT ?x {
  SELECT ?x { # <-- NPE disappears when removing this sub select.
    ?x a ?y
    FILTER EXISTS { SELECT * { ?y a ?z } }
  }
}

I silghtly updated the test cases.

@Aklakan Aklakan marked this pull request as draft December 9, 2024 20:52
@Aklakan
Copy link
Contributor Author

Aklakan commented Dec 9, 2024

I converted to draft for now because it seems there are some more issues related to how ExprFunctionOp are handled - I added another example query that breaks to #2883 (comment)

@Aklakan Aklakan force-pushed the 2024-12-08_op-as-query-fix branch 3 times, most recently from 109d372 to 3f660cd Compare December 11, 2024 00:02
@Aklakan
Copy link
Contributor Author

Aklakan commented Dec 11, 2024

I updated the code that handles ExprFunctionOp that when the Element is absent then it will be derived from the algebra. I also added additional test cases.
It's ready for another round of review.

@Aklakan Aklakan marked this pull request as ready for review December 11, 2024 00:04
@Aklakan Aklakan force-pushed the 2024-12-08_op-as-query-fix branch 2 times, most recently from 077c539 to 10a1360 Compare December 11, 2024 00:08
@Aklakan Aklakan force-pushed the 2024-12-08_op-as-query-fix branch from 10a1360 to 261af51 Compare December 11, 2024 12:41
Comment on lines +47 to +55
// If the element is null then an attempt is made to obtain it from the algebra.
// A given element takes precedence over the algebra.
Element el1 = funcOp.getElement();
if (el1 == null) {
Op op = funcOp.getGraphPattern();
el1 = op == null ? null : OpAsQuery.asElement(op);
}
// ElementTransformer will warn should it happen that null is passed to it.
Element el2 = ElementTransformer.transform(el1, transform, this);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now the updated actual fix - together with the introduction of OpAsQuery.asElement.

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

Successfully merging this pull request may close these issues.

NPE in OpAsQuery
3 participants