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: groupby path expression with overlapping identifier #992

Merged
merged 8 commits into from
Jan 27, 2025
2 changes: 1 addition & 1 deletion hana/lib/HANAService.js
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ class HANAService extends SQLService {
// if (col.ref?.length === 1) { col.ref.unshift(parent.as) }
if (col.ref?.length > 1) {
const colName = this.column_name(col)
if (!parent.SELECT.columns.some(c => this.column_name(c) === colName)) {
if (!parent.SELECT.columns.some(c => !c.elements && this.column_name(c) === colName)) {
const isSource = from => {
if (from.as === col.ref[0]) return true
return from.args?.some(a => {
Expand Down
14 changes: 14 additions & 0 deletions test/compliance/SELECT.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,20 @@ describe('SELECT', () => {
const res = await cds.run(cqn)
assert.strictEqual(res.length, 3, 'Ensure that all rows are coming back')
})

test('navigation with duplicate identifier in path', async () => {
const { Books } = cds.entities('complex.associations')
const cqn = CQL`SELECT name { name } FROM ${Books} GROUP BY name.name`
const res = await cds.run(cqn)
assert.strictEqual(res.length, 1, 'Ensure that all rows are coming back')
})
PDT42 marked this conversation as resolved.
Show resolved Hide resolved

test('navigation with duplicate identifier in path and aggregation', async () => {
const { Books } = cds.entities('complex.associations')
const cqn = CQL`SELECT name { name }, count(1) as total FROM ${Books} GROUP BY name.name`
const res = await cds.run(cqn)
assert.strictEqual(res.length, 1, 'Ensure that all rows are coming back')
})
})

describe('having', () => {
Expand Down
1 change: 1 addition & 0 deletions test/compliance/resources/db/complex/associations.cds
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ entity Books {
key ID : Integer;
title : String(111);
author : Association to Authors;
name : Association to Authors on $self.author.ID = ID;
PDT42 marked this conversation as resolved.
Show resolved Hide resolved
}

entity Authors {
Expand Down
Loading