-
Notifications
You must be signed in to change notification settings - Fork 22
feat: sort selected columns & expands before formatting sql #1330
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
Open
PDT42
wants to merge
24
commits into
main
Choose a base branch
from
feat/order-selected-columns
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 19 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
19084fb
feat: at least make a naive solution work
PDT42 e9db0da
Merge branch 'main' into feat/order-selected-columns
PDT42 a01ddf9
test: add & update tests for column sorting
PDT42 908c032
feat: consider more column syntax options in sort
PDT42 2ebc4c7
Merge branch 'main' into feat/order-selected-columns
PDT42 81d4f6f
test: add tests for expression columns
PDT42 4bc3cbd
test: add test for non string value
PDT42 3950cca
feat: stringify values before comparison
PDT42 4eed3f6
fix: handle plain string columns
PDT42 0d27acf
Merge branch 'main' into feat/order-selected-columns
PDT42 9ca0ab2
feat: integrate column sorting in hana insert_select
PDT42 952284d
Merge branch 'main' into feat/order-selected-columns
PDT42 e516b56
feat: move column sorting related test out of symlinked tests
PDT42 8dc5b36
fix: test app root dir
PDT42 3a6a0f8
chore: rename test
PDT42 7a3eefb
feat: just use column_name
PDT42 edc88eb
Merge branch 'main' into feat/order-selected-columns
PDT42 72c5f07
fix: prevent column_name from being called for *
PDT42 90223ec
fix: array identity
PDT42 0ee17a5
feat: get rid of tuples and type check
PDT42 6e74a15
feat: check for asterisk explicitly
PDT42 05dd28f
feat: go back to checking type
PDT42 5c7e3f0
Merge branch 'main' into feat/order-selected-columns
PDT42 24e2038
fix: consider insert.as
PDT42 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,123 @@ | ||
const cds = require('../../test/cds.js') | ||
const bookshop = cds.utils.path.resolve(__dirname, '../../test/bookshop') | ||
|
||
describe('column order', () => { | ||
const { expect } = cds.test(bookshop) | ||
|
||
describe('regardless of column order specifed in query', () => { | ||
let hanaService | ||
|
||
beforeAll(async () => { | ||
hanaService = await cds.connect.to('db') | ||
}) | ||
|
||
const expectSqlScriptToBeEqual = (query1, query2) => { | ||
const sql1 = hanaService.cqn2sql(query1) | ||
const sql2 = hanaService.cqn2sql(query2) | ||
expect(sql1.sql).to.equal(sql2.sql) | ||
|
||
const sqlScript1 = hanaService.wrapTemporary(sql1.temporary, sql1.withclause, sql1.blobs) | ||
const sqlScript2 = hanaService.wrapTemporary(sql2.temporary, sql2.withclause, sql2.blobs) | ||
expect(sqlScript1).to.equal(sqlScript2) | ||
} | ||
|
||
test('should select columns in the same order', async () => { | ||
const query1 = SELECT.from('sap.capire.bookshop.Books').columns(['ID', 'title', 'descr', 'stock', 'price']) | ||
const query2 = SELECT.from('sap.capire.bookshop.Books').columns(['stock', 'title', 'price', 'ID', 'descr']) | ||
|
||
expectSqlScriptToBeEqual(query1, query2) | ||
}) | ||
|
||
test('should select expands in the same order', async () => { | ||
const query1 = SELECT.from('sap.capire.bookshop.Books').columns([ | ||
{ ref: ['author'], expand: [{ ref: ['name'] }] }, | ||
{ ref: ['genre'], expand: [{ ref: ['ID'] }] }, | ||
]) | ||
const query2 = SELECT.from('sap.capire.bookshop.Books').columns([ | ||
{ ref: ['genre'], expand: [{ ref: ['ID'] }] }, | ||
{ ref: ['author'], expand: [{ ref: ['name'] }] }, | ||
]) | ||
|
||
expectSqlScriptToBeEqual(query1, query2) | ||
}) | ||
|
||
test('should select flat expands in the same order', async () => { | ||
const query1 = SELECT.from('sap.capire.bookshop.Books').columns([ | ||
'ID', | ||
{ ref: ['author', 'ID'] }, | ||
{ ref: ['genre', 'ID'] }, | ||
{ ref: ['author', 'name'] }, | ||
]) | ||
const query2 = SELECT.from('sap.capire.bookshop.Books').columns([ | ||
{ ref: ['genre', 'ID'] }, | ||
{ ref: ['author', 'name'] }, | ||
{ ref: ['author', 'ID'] }, | ||
'ID', | ||
]) | ||
|
||
expectSqlScriptToBeEqual(query1, query2) | ||
}) | ||
|
||
test('should select columns and expands in the same order', async () => { | ||
const query1 = SELECT.from('sap.capire.bookshop.Books').columns([ | ||
'ID', | ||
{ ref: ['author'], expand: [{ ref: ['ID'] }, { ref: ['name'] }] }, | ||
{ ref: ['genre', 'ID'] }, | ||
]) | ||
const query2 = SELECT.from('sap.capire.bookshop.Books').columns([ | ||
{ ref: ['genre', 'ID'] }, | ||
{ ref: ['author'], expand: [{ ref: ['ID'] }, { ref: ['name'] }] }, | ||
'ID', | ||
]) | ||
|
||
expectSqlScriptToBeEqual(query1, query2) | ||
}) | ||
|
||
test('should select columns from expands in the same order', async () => { | ||
const query1 = SELECT.from('sap.capire.bookshop.Books').columns([ | ||
'ID', | ||
{ ref: ['author'], expand: [{ ref: ['ID'] }, { ref: ['name'] }] }, | ||
]) | ||
const query2 = SELECT.from('sap.capire.bookshop.Books').columns([ | ||
{ ref: ['author'], expand: [{ ref: ['name'] }, { ref: ['ID'] }] }, | ||
'ID', | ||
]) | ||
|
||
expectSqlScriptToBeEqual(query1, query2) | ||
}) | ||
|
||
test('should select functions in the same order', async () => { | ||
const query1 = SELECT.from('sap.capire.bookshop.Books').columns(['ID', { xpr: ['1=1'], as: 'always_true' }]) | ||
const query2 = SELECT.from('sap.capire.bookshop.Books').columns([{ xpr: ['1=1'], as: 'always_true' }, 'ID']) | ||
|
||
expectSqlScriptToBeEqual(query1, query2) | ||
}) | ||
|
||
test('should select expressions in the same order', async () => { | ||
const query1 = SELECT.from('sap.capire.bookshop.Books').columns([ | ||
'ID', | ||
{ func: 'max', args: [{ ref: ['price'] }] }, | ||
]) | ||
const query2 = SELECT.from('sap.capire.bookshop.Books').columns([ | ||
{ func: 'max', args: [{ ref: ['price'] }] }, | ||
'ID', | ||
]) | ||
|
||
expectSqlScriptToBeEqual(query1, query2) | ||
}) | ||
|
||
test('should select values in the same order', async () => { | ||
const query1 = SELECT.from('sap.capire.bookshop.Books').columns(['ID', { val: 'some-static-value' }]) | ||
const query2 = SELECT.from('sap.capire.bookshop.Books').columns([{ val: 'some-static-value' }, 'ID']) | ||
|
||
expectSqlScriptToBeEqual(query1, query2) | ||
}) | ||
|
||
test('should select numeric values in the same order', async () => { | ||
const query1 = SELECT.from('sap.capire.bookshop.Books').columns(['ID', { val: 1 }]) | ||
const query2 = SELECT.from('sap.capire.bookshop.Books').columns([{ val: 1 }, 'ID']) | ||
|
||
expectSqlScriptToBeEqual(query1, query2) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.