From 8318014c6b0fedbdb45ca8e98195402cf10f94c0 Mon Sep 17 00:00:00 2001 From: Patrice Bender Date: Wed, 22 Jan 2025 14:13:34 +0100 Subject: [PATCH] fix: wildcard expand + group by doesnt skip expand --- db-service/lib/cqn4sql.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/db-service/lib/cqn4sql.js b/db-service/lib/cqn4sql.js index e75da05e1..1d0cc2933 100644 --- a/db-service/lib/cqn4sql.js +++ b/db-service/lib/cqn4sql.js @@ -796,8 +796,10 @@ function cqn4sql(originalQuery, model) { // columns of the expand must be in the groupBy if (transformedQuery.SELECT.groupBy) { const baseRef = column.$refLinks[0].definition.SELECT || ref - - return _subqueryForGroupBy(column, baseRef, columnAlias) + const wildcardIndex = column.expand.findIndex(e => e === '*') + if (wildcardIndex === -1) { + return _subqueryForGroupBy(column, baseRef, columnAlias) + } } // we need to respect the aliases of the outer query, so the columnAlias might not be suitable @@ -877,11 +879,6 @@ function cqn4sql(originalQuery, model) { // to be attached to dummy query const elements = {} - const wildcardIndex = column.expand.findIndex(e => e === '*') - if (wildcardIndex !== -1) { - // expand with wildcard vanishes as expand is part of the group by (OData $apply + $expand) - return null - } const expandedColumns = column.expand.flatMap(expand => { if (!expand.ref) return expand const fullRef = [...baseRef, ...expand.ref]