Thanks Andrus :).

It works for the most part but I’m still running into some problems. I think 
I’ll switch to SQL for now for the methods where this matters. I’m filing JIRAs 
for the issues I’ve encountered but FYI, this is where it fails:

Failure 1:
Wrong SQL generated for a DISTINCT count using a DB path. Example:

Running EJBQL query:
select count(distinct db:e.receipt_id) from Entry e

Generates SQL:
SELECT COUNT(DISTINCT *) AS sc0 FROM `strimillinn`.`fd_entry` t0

Should generate SQL:
SELECT COUNT(DISTINCT receipt_id) AS sc0 FROM `strimillinn`.`fd_entry` t0

———————————————

Failure 2:
EJBQL fails to find joins for relationships when DB-paths are used in the 
where-clause.

Running EJBQL query:
select r.entries from Receipt r where db:r.shop.name='Holtagarðar'

Results in a EJBQLException with the message:
"No join configured for id r.shop"

Running the same query using a regular path (not a DB path) works fine:
select r.entries from Receipt r where r.shop.name='Holtagarðar'

Cheers,
- hugi


> On 16. ágú. 2016, at 07:26, Andrus Adamchik <[email protected]> wrote:
> 
> Looks like DB path prefix was ignored everywhere except in conditions. E.g. 
> here it would work, but nowhere else:
> 
> select p.estimatedPrice from Painting p WHERE  db:p.ESTIMATED_PRICE > 2
> 
> Since expanding it to SELECT clause didn't require a parser change, the fix 
> was actually pretty easy. I just committed it. See 
> 5869e40f61e547cb33285803eede286a780cb0f3 and CAY-2102.
> 
> Andrus
> 
>> On Aug 15, 2016, at 9:53 PM, Hugi Thordarson <[email protected]> wrote:
>> 
>> I’m not quite getting this to work… In this case I have a list of Receipts 
>> linked to Shops, and I want to select the shop IDs (simplified example). If 
>> I try:
>> 
>> select db:r.shop_id from Receipt r
>> 
>> I’ll receive an error that “shop_id” is an invalid path component.
>> 
>> 
>> 
>> 
>>> On 15. ágú. 2016, at 17:18, Andrus Adamchik <[email protected]> wrote:
>>> 
>>>> One last question: Can I use db:-paths in EJBQL queries?
>>> 
>>> Yes, db path should be supported everywhere. 
>>> 
>>>> Particularly, I’m attempting to use FK-columns (that aren’t exposed in the 
>>>> ObjEntity) in my queries, perhaps there’s another way?
>>> 
>>> 
>>> If possible, use a relationship name instead of FK. E.g. 
>>> 
>>> "SELECT p FROM Painting p WHERE p.artist = 1"
>>> 
>>> but if not, db path is an option.
>>> 
>>> Andrus
>>> 
>>> 
>>>> On Aug 15, 2016, at 7:02 PM, Hugi Thordarson <[email protected]> wrote:
>>>> 
>>>> Thanks for this Andrus. One last question: Can I use db:-paths in EJBQL 
>>>> queries? Particularly, I’m attempting to use FK-columns (that aren’t 
>>>> exposed in the ObjEntity) in my queries, perhaps there’s another way?
>>>> 
>>>> Cheers,
>>>> - hugi
>>>> 
>>>> 
>>>> 
>>>>> On 15. ágú. 2016, at 15:31, Andrus Adamchik <[email protected]> 
>>>>> wrote:
>>>>> 
>>>>> Ah yeah, now checking the code I am starting to remember. Arithmetic 
>>>>> expressions are not allowed in SELECT clause, only in WHERE. There's no 
>>>>> real reason for it other then us initially basing EJBQL parser on some 
>>>>> early JPA spec that probably didn't support it. We need to add it to the 
>>>>> parser. For now it won't work.
>>>>> 
>>>>> Andrus
>>>>> 
>>>>> 
>>>>>> On Aug 15, 2016, at 5:49 PM, Hugi Thordarson <[email protected]> wrote:
>>>>>> 
>>>>>> Hi Andrus,
>>>>>> 
>>>>>>> On 15. ágú. 2016, at 06:30, Andrus Adamchik <[email protected]> 
>>>>>>> wrote:
>>>>>>> 
>>>>>>> Hi Hugi,
>>>>>>> 
>>>>>>> Sorry for delayed reply. I swear we had the BNF for EJBQL in the docs, 
>>>>>>> but apparently we don't. Here is the closest thing to it - a JavaCC 
>>>>>>> grammar:
>>>>>>> 
>>>>>>> https://github.com/apache/cayenne/blob/master/cayenne-server/src/main/jjtree/org/apache/cayenne/ejbql/EJBQLParser.jjt
>>>>>>> 
>>>>>>> We do support simple arithmetic operations. Search for 'arithmetic_' 
>>>>>>> clauses in the .jjt.
>>>>>> 
>>>>>> I’m not as smart as you think—I haven’t touched JavaCC grammar before, 
>>>>>> though I could figure it out but I don’t see how to do this :). Can you 
>>>>>> tell me how I can do something equivalent to “select e.price*e.quantity 
>>>>>> from Entry e”?
>>>>>> 
>>>>>> Cheers,
>>>>>> - hugi
>>>>> 
>>>> 
>>> 
>> 
> 

Reply via email to