Issue Details (XML | Word | Printable)

Key: NUCCORE-505
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Andy Jefferson
Reporter: Andy Jefferson
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
DataNucleus Core

JDOQL2 : Support for parameters in subqueries linking back to main query

Created: 31/Mar/10 08:45 AM   Updated: 26/Apr/10 03:37 PM   Resolved: 12/Apr/10 04:22 PM
Component/s: Queries
Affects Version/s: None
Fix Version/s: 2.1.0.m2


 Description  « Hide
If we have
Query subquery = pm.newQuery(Employee.class);
subquery.setResult("avg(this.salary)");
subquery.setFilter("this.lastName == :lastNameParam");

Query q = pm.newQuery(Employee.class, "salary > averageSalaryForFamily");
q.addSubquery(subquery, "double averageSalaryForFamily", null, "this.lastName");

this ought to translate into a subquery with a where clause like

SUB.LAST_NAME = A0.LAST_NAME

where "SUB" is the candidate of the subquery, and "A0" is the candidate of the main query.

It may need an update to the generic compilation, which currently gives
QueryCompilation:
  [filter:DyadicExpression{PrimaryExpression{salary} > VariableExpression{averageSalaryForFamily}}]
  [symbols: averageSalaryForFamily type=unknown, this type=org.jpox.samples.models.company.Employee]
  [subquery: averageSalaryForFamily
    [result:InvokeExpression{STATIC.avg(PrimaryExpression{this.salary})}]
    [filter:DyadicExpression{PrimaryExpression{this.lastName} = ParameterExpression{lastNameParam}}]
    [symbols: this type=org.jpox.samples.models.company.Employee, lastNameParam type=java.lang.String]]

[see test.jdo.datastore "JDOQLSubqueryTest"].



Andy Jefferson made changes - 01/Apr/10 10:40 AM
Field Original Value New Value
Fix Version/s 2.1.0.m2 [ 10912 ]
Component/s Queries [ 10142 ]
Andy Jefferson made changes - 12/Apr/10 04:17 PM
Project DataNucleus RDBMS [ 10144 ] DataNucleus Core [ 10143 ]
Key NUCRDBMS-353 NUCCORE-505
Fix Version/s 2.1.0.m2 [ 10901 ]
Fix Version/s 2.1.0.m2 [ 10912 ]
Component/s Queries [ 10154 ]
Component/s Queries [ 10142 ]
Andy Jefferson added a comment - 12/Apr/10 04:18 PM
The main problem is when a JDOQL query is set using the API the alias for the subquery is "this" hence causing clashing with the outer query, and also that parameters are not being substituted in the generic compilation.

Andy Jefferson added a comment - 12/Apr/10 04:20 PM
When we fix those two generic query compilation issues the compilation becomes

QueryCompilation:
  [filter:DyadicExpression{PrimaryExpression{salary} > VariableExpression{averageSalaryForFamily}}]
  [symbols: averageSalaryForFamily type=unknown, this type=org.jpox.samples.models.company.Employee]
  [subquery: averageSalaryForFamily
    [result:InvokeExpression{STATIC.avg(PrimaryExpression{sub_this.salary})}]
    [filter:DyadicExpression{PrimaryExpression{sub_this.lastName} = PrimaryExpression{this.lastName}}]
    [symbols: sub_this type=org.jpox.samples.models.company.Employee]]

Andy Jefferson added a comment - 12/Apr/10 04:22 PM
SVN trunk has this fixed.
SVN branches/2.0 doesn't have this.

Andy Jefferson made changes - 12/Apr/10 04:22 PM
Status Open [ 1 ] Resolved [ 5 ]
Resolution Fixed [ 1 ]
Andy Jefferson made changes - 26/Apr/10 03:37 PM
Status Resolved [ 5 ] Closed [ 6 ]