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

fix: Remove orderBy ref check for sql_simple_queries #964

Merged
merged 4 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion hana/lib/HANAService.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ class HANAService extends SQLService {
throw new Error('CQN query using joins must specify the selected columns.')
}

let { limit, one, from, orderBy, having, expand, columns = ['*'], localized, count, parent } = q.SELECT
let { limit, one, distinct, from, orderBy, having, expand, columns = ['*'], localized, count, parent } = q.SELECT

// When one of these is defined wrap the query in a sub query
if (expand || (parent && (limit || one || orderBy))) {
Expand Down Expand Up @@ -373,6 +373,7 @@ class HANAService extends SQLService {

let orderByHasOutputColumnRef = false
if (orderBy) {
if (distinct) orderByHasOutputColumnRef = true
// Ensure that all columns used in the orderBy clause are exposed
orderBy = orderBy.map((c, i) => {
if (!c.ref) {
Expand Down
11 changes: 11 additions & 0 deletions test/scenarios/bookshop/read.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,17 @@ describe('Bookshop - Read', () => {
expect(res[0].price).to.be.eq('150')
})

test('select distinct order by selected result column with alias', async () => {
const { Authors } = cds.entities('sap.capire.bookshop')
const res = await SELECT.distinct
.columns`ID`
.from`${Authors} as a`
.orderBy`a.ID`

expect(res.length).to.be.eq(4)
expect(res[0].ID).to.be.eq('101')
johannes-vogel marked this conversation as resolved.
Show resolved Hide resolved
})

test('reuse already executed select as subselect', async () => {
let s = SELECT.columns('ID').from('sap.capire.bookshop.Books')
let res = await s
Expand Down
Loading