diff --git a/db-service/lib/cqn4sql.js b/db-service/lib/cqn4sql.js index 60569c547..6a88363e1 100644 --- a/db-service/lib/cqn4sql.js +++ b/db-service/lib/cqn4sql.js @@ -1276,7 +1276,10 @@ function cqn4sql(originalQuery, model = cds.context?.model || cds.model) { transformedTokenStream.push({ list: [] }) } } else { - transformedTokenStream.push({ list: getTransformedTokenStream(token.list, $baseLink) }) + const { list } = token + if (list.every(e => e.val)) // no need for transformation + transformedTokenStream.push({ list }) + else transformedTokenStream.push({ list: getTransformedTokenStream(list, $baseLink) }) } } else if (tokenStream.length === 1 && token.val && $baseLink) { // infix filter - OData variant w/o mentioning key --> flatten out and compare each leaf to token.val diff --git a/db-service/test/cqn4sql/DELETE.test.js b/db-service/test/cqn4sql/DELETE.test.js index 99fa99199..509da0c46 100644 --- a/db-service/test/cqn4sql/DELETE.test.js +++ b/db-service/test/cqn4sql/DELETE.test.js @@ -107,6 +107,82 @@ describe('DELETE', () => { expect(query.DELETE).to.deep.equal(expected.DELETE) }) + it('in a list with exactly one val, dont transform to key comparison', () => { + const query = { + DELETE: { + from: { + ref: [ + { + id: 'bookshop.Books', + where: [ + { + ref: ['ID'], + }, + 'in', + { + list: [ + { + val: 'b6248f67-6f8b-4816-a096-0b65c2349143', + }, + ], + }, + ], + }, + 'author', + ], + }, + }, + } + + const expected = { + DELETE: { + from: { + ref: ['bookshop.Authors'], + as: 'author', + }, + where: [ + 'exists', + { + SELECT: { + from: { + ref: ['bookshop.Books'], + as: 'Books', + }, + columns: [ + { + val: 1, + }, + ], + where: [ + { + ref: ['Books', 'author_ID'], + }, + '=', + { + ref: ['author', 'ID'], + }, + 'and', + { + ref: ['Books', 'ID'], + }, + 'in', + { + list: [ + { + val: 'b6248f67-6f8b-4816-a096-0b65c2349143', + }, + ], + }, + ], + }, + }, + ], + }, + } + const res = cqn4sql(query) + expect(res).to.deep.equal(expected) + }) + it('DELETE with assoc filter and where exists expansion', () => { const { DELETE } = cds.ql let d = DELETE.from('bookshop.Reproduce[author = null and ID = 99]:accessGroup')