-
Notifications
You must be signed in to change notification settings - Fork 21
feat: sort selected columns & expands before formatting sql #1358
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: Bob den Os <108393871+BobdenOs@users.noreply.github.com>
patricebender
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was always under the impression, that the order of columns matters for users of our services. Why else do we have mechanism in place, which guarantee stable column order, like the smart wildcard?
The cds-compiler and cqn4sql have built-in logic to adhere to this principle. The rules can be summarized with the following case:
entity E {
a : String; b : String;
c : String; d : String;
};
entity After as select from E { *, 1 as b, 2 as c }; // a, b, c, d
entity Before as select from E { 1 as b, 2 as c, * }; // b, c, a, d
entity Around as select from E { 1 as b, *, 2 as c }; // b, a, c, d
entity Excluding as select from E { *, 2 as c } excluding { c }; // a, b, d, c→ this also goes for nested projections
please also see the sophisticated test suite, which makes sure that the cap-js database services adhere to those rules:
| it('MUST respect smart wildcard rules -> structure replacement before star', () => { |
|
with OData's $select clause this is exposed to the end user who can easily construct a different order to exhaust the execution plan cache. If the order in CSN is stable, we can also use that order. |
|
@johannes-vogel the order in the examples are already all different from one another. @patricebender the source of the problem is $select on the protocol level. Which allows end users to determine the column order. There is no problem with the order of the columns as they are in the cqn. It is only a problem with the order of the columns in the SQL statement. Additionally no matter what the order of the columns are at any point in time. The properties in the returned objects are sorted based upon the principles of the ecma script spec. So if people expect the order of the properties of the results to match the order of their column definitions. This can't be true depending on their column names. |
Reopens #1330 after it was reverted due to it causing failing tests in the base cds package.