Skip to content

Commit

Permalink
fix: expand + group may return null, dont try to attach .element to…
Browse files Browse the repository at this point in the history
… the column

this is a workaround for an issue reported in cap/issues#17907

--> we need to put all this logic in the OData protocol adapter, this coding should
not be necessary for the DB. This initiative has already started in #990
  • Loading branch information
patricebender committed Feb 24, 2025
1 parent 93047e0 commit b61556f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
16 changes: 11 additions & 5 deletions db-service/lib/cqn4sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -877,8 +877,8 @@ function cqn4sql(originalQuery, model) {

// to be attached to dummy query
const elements = {}
const wildcardIndex = column.expand.findIndex(e => e === '*')
if (wildcardIndex !== -1) {
const wildcardIndex = column.expand.includes('*')
if (wildcardIndex) {
// expand with wildcard vanishes as expand is part of the group by (OData $apply + $expand)
return null
}
Expand All @@ -888,8 +888,10 @@ function cqn4sql(originalQuery, model) {

if (expand.expand) {
const nested = _subqueryForGroupBy(expand, fullRef, expand.as || expand.ref.map(idOnly).join('_'))
setElementOnColumns(nested, expand.element)
elements[expand.as || expand.ref.map(idOnly).join('_')] = nested
if(nested) {
setElementOnColumns(nested, expand.element)
elements[expand.as || expand.ref.map(idOnly).join('_')] = nested
}
return nested
}

Expand All @@ -910,7 +912,11 @@ function cqn4sql(originalQuery, model) {
elements[c.as || c.ref.at(-1)] = c.element
})
return res
})
}).filter(c => c !== null)

if (expandedColumns.length === 0) {
return null
}

const SELECT = {
from: null,
Expand Down
3 changes: 2 additions & 1 deletion db-service/test/cqn4sql/expand.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,8 @@ describe('Expands with aggregations are special', () => {

it('wildcard expand vanishes for aggregations', () => {
const q = CQL`SELECT from bookshop.TestPublisher {
ID
ID,
texts { publisher {*} }
} group by ID, publisher.structuredKey_ID, publisher.title`

const qx = CQL`SELECT from bookshop.TestPublisher as TestPublisher
Expand Down

0 comments on commit b61556f

Please sign in to comment.