Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sending a cqn targeting non-model entities, fails for subquery selects #1013

Open
patricebender opened this issue Feb 4, 2025 · 0 comments
Labels
bug Something isn't working cqn2sql cqn-to-sql transformation

Comments

@patricebender
Copy link
Member

Go into the bookshop and start a repl session:

> sql = `
... SELECT author_name, total_books
... FROM (
...     SELECT 
...         a.name AS author_name, 
...         COUNT(b.ID) AS total_books
...     FROM sap_capire_bookshop_Authors a
...     LEFT JOIN sap_capire_bookshop_Books b ON a.ID = b.author_ID
...     GROUP BY a.name
... ) AS author_summary
... ORDER BY total_books DESC;
> await cds.run(sql)
[
  { author_name: 'Edgar Allen Poe', total_books: 2 },
  { author_name: 'Charlotte Brontë', total_books: 1 },
  { author_name: 'Emily Brontë', total_books: 1 },
  { author_name: 'Richard Carpenter', total_books: 1 }
]

so far so good. We had a customer doing (weird) stuff like this:

> await cds.run( cds.parse.cql(sql) )
Uncaught Error: "sap_capire_bookshop_Authors" not found in the definitions of your model
    at inferTarget (/Users/patricebender/SAPDevelop/dev/cds-dbs/db-service/lib/infer/index.js:105:53)

what usually doesn't bother us, because here:

cqn4sql(q) {
if (
!cds.env.features.db_strict &&
!q.SELECT?.from?.join &&
!q.SELECT?.from?.SELECT &&
!this.model?.definitions[_target_name4(q)]
) return q
else return cqn4sql(q, this.model)
}

we check for non-modeled entities and if that is the case, we just send the query to the database. However, that mechanism does not work, because the unresolvable entity lives within the subquery.

@BobdenOs @johannes-vogel FYI

@patricebender patricebender added bug Something isn't working cqn2sql cqn-to-sql transformation labels Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cqn2sql cqn-to-sql transformation
Projects
None yet
Development

No branches or pull requests

1 participant