on 05-29-2020 10:21 PM
Hi all,
I have a use case where I create a view on top of a table to calculate a field. In the same table I will create an association to the view on top of this table so I can navigate to this calculated field. This works fine except when I try to expand and filter on this association.
I simulated a simplified version of the problem, the datamodel:
Authors is the entity and AuthorStatus is a view on top of this table. AuthorStatus in Authors table is the association between the table and the view:
namespace sap.capire.bookshop;
entity Authors {
key ID : Integer;
name : String(111);
AuthorStatus : Association to AuthorStatus on AuthorStatus.ID = ID;
};
entity AuthorStatus as select from Authors as offer {
ID,
'test' as status : String(20)
};
Both are exposed in the service layer:
using { sap.capire.bookshop as my } from '../db/schema';
service AdminService @(_requires:'authenticated-user') {
entity Authors as projection on my.Authors;
entity AuthorStatus as projection on my.AuthorStatus;
}
When I try to test by expanding the data and filtering on the name of an author, it all works fine:
http://localhost:4004/admin/Authors?$expand=AuthorStatus&$filter=name eq 'Wouter'
When I try to filter on the field "status" in the association, I get the following error:
Url: http://localhost:4004/admin/Authors?$expand=AuthorStatus&$filter=AuthorStatus/status eq 'test'
Error:
When I enable debugging and look at the generated query, I notice it generates wrong SQL:
SELECT a.ID AS "a_ID", a.name AS "a_name", b.ID AS "b_ID", b.status AS "b_status" FROM AdminService_Authors a LEFT JOIN AdminService_AuthorStatus b ON ( b.ID = a.ID ) WHERE a.AuthorStatus.status =
? LIMIT 1000 [ 'test' ]
I guess it should use the "status" in the where from table "b"?
Could this be a bug or am I doing something that's not allowed?
Thank you in advance!
Kr, Wouter
Hi,
I don't have the answer but I remember I saw exactly this issue during workshop with SAP on CAP. We tried to deploy to HANA and it worked there OK. So it looked like a bug in CAP. Maybe you can try to deploy to HANA to see if you can replicate it there.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
My point was that if it works on HANA, it should work on SQLite as well. Hence it looks like a bug to me and CAP developers should address it.
Hi,
Path expressions, in this case `AuthorStatus/status`, only work on SAP HANA, not on SQLite.
Best regards,
David
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Wouter,
I can only support Gregor's proposal. I have also been working with a HANA database for 7 months now and I am also happy with it.
Unlike Gregor, my HANA does not run locally on my laptop, but I use a HDI container running on a CF space.
Best regards
Simon
Hi Wouter,
We have switched to use an HDI Container on the Cloud as well and connect to that if we need these sorts of queries.
I tried debugging through the entire sql resolving a while back, but couldn't really find an easy fix for it. (Yeah manually changing the a part of the setup in debug, but that's no solution).
david.kunz2 is it perhaps possible to note this somewhere in the documentation or do you have any plans like Wouter asked to resolve this? It's a recurring question so far. 🙂
https://answers.sap.com/questions/13016370/cloud-application-programming-model-sqlit-order-an.html
https://github.com/sapmentors/cap-community/issues/22
What I ran into for trying to manually fix this, was the following:
In the buildJoinQueries in expandCQNToJoin.js (@sap/cds-runtime/lib/cds-sql/expand) first the where was constructed and after that the join, which caused the where to not be properly mapped to what's joined.
I didn't have much time to delve deeper into this though.
Kind regards,
Vincent
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.