Skip to content

fix(expand): proper subquery from construction #1126

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

Merged
merged 3 commits into from
Apr 9, 2025

Conversation

patricebender
Copy link
Member

@patricebender patricebender commented Apr 8, 2025

if a query selects from another query, we need to consider the case where the subquery has path expressions (and therefore joins).

The best solution is then to drill down into the innermost query of the from clause, because we do not know the depth.

It is also not a good idea to check for the ref of the innermost untransformed query, as it is potentially a scoped query (as shown in one of the tests).

Moreover, it is not possible to use the ref of the transformed query because it might be replaced by join args.

replaces #1114

fix #1112

if a query selects from another query, we need to consider the case
where the subquery has path expressions (and therefore joins).

The best solution is then to drill down into the innermost query of the from clause,
because we do not know the depth.

It is also not a good idea to check for the `ref` of the innermost _untransformed_ query,
as it is potentially a scoped query (as shown in one of the tests).

fix #1112
expect(JSON.parse(JSON.stringify(res))).to.deep.equal(expected)
})
it('expand via subquery with path expressions nested', () => {
const q = cds.ql`SELECT from (SELECT from (SELECT from bookshop.Books as inner { author, ID } where author.name = 'King') as Mid { * }) as Outer {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw this revealed another issue, which is not subject to this PR. So I will ship a dedicated fix for #1127 once this is in main

Copy link
Contributor

@danjoa danjoa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed: might get obsolete with cds9 but would work with that as well
Thanks @patricebender 👍

@patricebender patricebender enabled auto-merge (squash) April 9, 2025 09:28
@patricebender patricebender merged commit e343e79 into main Apr 9, 2025
6 of 7 checks passed
@patricebender patricebender deleted the patrice/subq-expand branch April 9, 2025 09:34
@cap-bots cap-bots mentioned this pull request Apr 9, 2025
johannes-vogel added a commit that referenced this pull request Apr 17, 2025
🤖 I have created a release *beep* *boop*
---


<details><summary>db-service: 1.20.0</summary>

##
[1.20.0](db-service-v1.19.1...db-service-v1.20.0)
(2025-04-17)


### Added

* Result set streaming
([#702](#702))
([2fe02ea](2fe02ea))


### Fixed

* **`expand`:** proper subquery `from` construction
([#1126](#1126))
([e343e79](e343e79)),
closes [#1114](#1114)
[#1112](#1112)
* Improved support for special characters in column names
([#1141](#1141))
([ba04697](ba04697))
* **infer:** for localized queries, use `localized.<entity>` as
`_target` ([#1140](#1140))
([b08707b](b08707b))
</details>

<details><summary>sqlite: 1.11.0</summary>

##
[1.11.0](sqlite-v1.10.0...sqlite-v1.11.0)
(2025-04-17)


### Added

* Result set streaming
([#702](#702))
([2fe02ea](2fe02ea))
</details>

<details><summary>postgres: 1.14.0</summary>

##
[1.14.0](postgres-v1.13.0...postgres-v1.14.0)
(2025-04-17)


### Added

* Result set streaming
([#702](#702))
([2fe02ea](2fe02ea))
</details>

<details><summary>hana: 1.9.0</summary>

##
[1.9.0](hana-v1.8.1...hana-v1.9.0)
(2025-04-17)


### Added

* enable skip hana wrapping
([#1137](#1137))
([5e6d61f](5e6d61f))
* Result set streaming
([#702](#702))
([2fe02ea](2fe02ea))


### Fixed

* Improved support for special characters in column names
([#1141](#1141))
([ba04697](ba04697))
</details>

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: D045778 <[email protected]>
johannes-vogel added a commit that referenced this pull request May 19, 2025
)

`q._target` will resolve recursively to the innermost entity, with our
streamlined `cds.infer` --> no need to do this manually anymore


this is a follow up of #1126

@danjoa fyi

---------

Co-authored-by: Johannes Vogel <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[REGRESSION] db-service aggregation query throws error
3 participants