Hi Tom,
attached you find a new version of the subquery fix:
https://glassfish.dev.java.net/issues/show_bug.cgi?id=444
https://glassfish.dev.java.net/issues/show_bug.cgi?id=449
This version includes the following changes:
- Generate a SQL join for a JOIN variable that is declared in the outer
query, but only used in the subquery, e.g. the 'o' in the example:
SELECT c FROM Customer c JOIN c.orders o
WHERE EXISTS (SELECT o FROM o.items i ...)
- Handle joins for outer variables in OR-operands.
- For an EXISTS subquery we replace SELECT clause by SELECT 1. THis is
now done directly on the ReportQuery instead of changing the EJBQL parse
tree. This makes sure we generate SQL joins for any relationship
navigations in the original SELECT clause.
Please have a look and please have another test run on your side.
Thanks!
Regards Michael
> Hi Tom,
>
> I'm sorry, I include a wrong version of one of the files. Please find a
> new jar attached.
>
> Regards Michael
>
>> Hi Michael,
>>
>> I am getting a compile failure in VariableNode.
>>
>> originalNode doesn't exist in my code.
>>
>> public void validate(ParseTreeContext context) {
>> if (left != null) {
>> // change SELECT clause of subquery
>> SubqueryNode subqueryNode = (SubqueryNode)getLeft();
>> EJBQLParseTree parseTree = subqueryNode.getParseTree();
>> SelectNode selectNode = (SelectNode)parseTree.getQueryNode();
>> originalNode = (Node)selectNode.getSelectExpressions().get(0);
>> if (originalNode.isVariableNode()) {
>>
>> -Tom
>>
>> Michael Bouschen wrote:
>>
>>> Hi Tom,
>>>
>>> attached you find new changes fixing two subquery issues:
>>> https://glassfish.dev.java.net/issues/show_bug.cgi?id=444
>>> https://glassfish.dev.java.net/issues/show_bug.cgi?id=449
>>>
>>> I changed the validation in the ExistsNode to validate the subquery
>>> after I changed the SELECT clause of the subquery to return 1. This
>>> causes a joined attributed to be added using
>>> addNonFetchJoinedAttribute. This fixes the issue 449. The other
>>> change is in SubqueryNode when adding the equal expression connecting
>>> variables from the inner and the outer query. I call
>>> VariableNode.generateExpression to create the expression instead of
>>> just looking it up in the expression cache. There was a case where
>>> the cache did not include an expression, so the cache lookup returned
>>> null causing the construction of an invalid Expression.
>>>
>>> Please have a look and please have another test run on your side.
>>> Thanks!
>>>
>>> Regards Michael
>>>
>>>
>>>
>>>
>>>> Hi Michael,
>>>>
>>>> These changes look good to me.
>>>>
>>>> We will definitely have to ensure CTS passes with these changes. Let
>>>> me know if you want me to include these changes in our next CTS run.
>>>>
>>>> -Tom
>>>>
>>>> Michael Bouschen wrote:
>>>>
>>>>
>>>>
>>>>> Hi Tom,
>>>>>
>>>>> attached are my changes for better subquery support. With these
>>>>> changes the SelectGenerationContext created for a subquery does not
>>>>> share its expression cache with the one for the outer query.
>>>>> Instead it generates an Expression.equal call for all variables
>>>>> used in the subquery that are declared in the outer query, e.g. the
>>>>> variable c in the following examples:
>>>>> SELECT c FROM Customer c WHERE EXISTS (SELECT o FROM c.orders o)
>>>>> SELECT c FROM Customer c WHERE EXISTS
>>>>> (SELECT o FROM Order o WHERE o.customer.name = c.name)
>>>>>
>>>>> Please have a look, thanks!
>>>>>
>>>>> Regards Michael
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>>
>>