JDOQL Subquery failing
I'm trying to get a complex query working with a subquery in the filter which is failing in the JDOQL Parser. I have diluted it to a very simple use case with a subselect which is failing as well. Please see the test-case on github.
I am fairly sure there is something which does not match expected syntax, but I am trying to follow the examples in the DN Docs, but the parser is still failing.
My query is:
Query q = pm.newQuery(Person.class);
and the exception I get is the following:
2021-07-23 15:31:44 INFO JDO:92 - Exception thrown
expected ')' at character 15 in "id == (select id from Person p)"
org.datanucleus.store.query.QueryCompilerSyntaxException: expected ')' at character 15 in "id == (select id from Person p)"
Ample examples of JDO subqueries in these tests. Note that none of the DN docs or these examples codes a subquery text into a "filter" clause of the parent query; they either single-string the whole query, or they use a variable for the subquery. They also always package-qualify all class names.
Thanks for the link. I'll take a closer look at them.
I did notice that none of the examples I had found added a subquery filter to a parent query. I wasn't sure if that was for clarity or by design.
It would seem that appending subquery text into a filter clause of a parent query is not supported. Would that be accurate? Is that be a limitation or by design?
Like I said, I tried to step through the parser to identify where it was failing to provide a patch for it, but I was having to trouble grasping the sequence of the Lexer parser well enough.
JDO Query programmatic "API" with separated items for "from", "filter", "result" etc never had subqueries in JDO1, and when subqueries were added in JDO2 they were specifiable using that programmatic "API" using addSubquery() and variables.
Single string JDOQL also came in at JDO2, with subqueries directly in the single string.
Clearly you could contribute handling, which would involve going to Query class where setFrom is called and parse it for a user including subqueries directly, and store those into the "subqueries" field. Then the primary query and each subquery are each compiled using their own individual JDOQLCompiler like now. No interest here. The other option in setFrom would be to search for the start of a subquery (e.g "SELECT ") and throw an exception informing the user of the error of their ways