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(cqn4sql): only transform list if necessary #438

Merged
merged 2 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 4 additions & 1 deletion db-service/lib/cqn4sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
76 changes: 76 additions & 0 deletions db-service/test/cqn4sql/DELETE.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down