-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(
order by
): for localized sorting, prepend table alias (#546)
Usually, column references in _simple_ names in order by clauses are left as is. That means **no table alias** is prepended. In expressions however, **only source elements** can be reffered to. That is why in case of localized sorting, we must prepend the table alias nevertheless, as in the DB specific drivers, a `COLLATE` expression is wrapped around the string reference. Hence we must replace the column reference with the underlying source reference. as reported in #543, postgres is not able to resolve a reference to a column unambigously if the reference is part of a `COLLATE` expression.
- Loading branch information
1 parent
821c1e1
commit a273a92
Showing
4 changed files
with
125 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const cds = require('../../cds.js') | ||
const bookshop = require('path').resolve(__dirname, '../../bookshop') | ||
|
||
describe('Bookshop - Order By', () => { | ||
const { expect } = cds.test(bookshop) | ||
|
||
test('collations', async () => { | ||
// the original query is sorted by the **column** "createdBy" | ||
// the resulting query has two query sources in the end --> Authors and Books | ||
// even though both Tables have the element "createdBy", the DB should be able to resolve the | ||
// order by reference to the column unambiguously | ||
const query = CQL(`SELECT from sap.capire.bookshop.Books { | ||
createdBy, | ||
author.name as author | ||
} order by createdBy, author | ||
limit 1`) | ||
const res = await cds.run(query) | ||
expect(res.length).to.be.eq(1) | ||
expect(res[0].author).to.eq('Charlotte Brontë') | ||
}) | ||
test('collations with val', async () => { | ||
if(cds.env.requires.db.impl === '@cap-js/hana') | ||
return // FIXME: the `val` is put into window function, which ends in an error on HANA | ||
const query = CQL(`SELECT from sap.capire.bookshop.Books { | ||
'simple string' as foo: cds.String, | ||
author.name as author | ||
} order by foo, author | ||
limit 1`) | ||
query.SELECT.localized = true | ||
const res = await cds.run(query) | ||
expect(res.length).to.be.eq(1) | ||
expect(res[0].author).to.eq('Charlotte Brontë') | ||
}) | ||
test('collations with func', async () => { | ||
const query = CQL(`SELECT from sap.capire.bookshop.Books { | ||
concat('simple', 'string') as bar: cds.String, | ||
author.name as author | ||
} order by bar, author | ||
limit 1`) | ||
const res = await cds.run(query) | ||
expect(res.length).to.be.eq(1) | ||
expect(res[0].author).to.eq('Charlotte Brontë') | ||
}) | ||
test('collations with xpr', async () => { | ||
const query = CQL(`SELECT from sap.capire.bookshop.Books { | ||
'simple' || 'string' as baz: cds.String, | ||
author.name as author | ||
} order by baz, author | ||
limit 1`) | ||
const res = await cds.run(query) | ||
expect(res.length).to.be.eq(1) | ||
expect(res[0].author).to.eq('Charlotte Brontë') | ||
}) | ||
}) |
What should happen here if no columns are provided (target.SELECT.columns === undefined)?