-
Notifications
You must be signed in to change notification settings - Fork 99
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: Move DB agnostic sections out of sqlite
database guide
#973
Conversation
``` > q = SELECT`from ${Books} { ID, title} where ID != null` > q.toSQL() { sql: `SELECT json_insert('{}','$."ID"',ID,'$."title"',title) as _json_ FROM (SELECT Books.ID,Books.title FROM sap_capire_bookshop_Books as Books WHERE Books.ID is not NULL)`, values: [] } ``` but for non-`null` comparisons, `!=` is translated to `<>`: ``` > q = SELECT`from ${Books} { ID, title} where ID != 207` > q.toSQL() { sql: `SELECT json_insert('{}','$."ID"',ID,'$."title"',title) as _json_ FROM (SELECT Books.ID,Books.title FROM sap_capire_bookshop_Books as Books WHERE Books.ID <> ?)`, values: [ 207 ] } ```
!= null
is translated to is not null
but != <xpr>
is notsqlite
database guide
ping @johannes-vogel @stewsk |
does that also apply to java? |
@johannes-vogel Do you mean we'd need the equivalent docs for Java when moving those docs in the common guide? @patricebender Is there anything I can support you with? |
I think the "common operators" section must be moved to the generic part of the db guide, I would like to hear the POs opinions here. From my side, this change is fine (I only need to apply the suggestion from Bob). |
I was simply wondering whether this is node specific or also applicable for java. at the moment it's tagged as node specific. in general, fine for me:) |
@MattSchur @agoerler Could you please check this PR? It's about moving a topic and also what is probably Node/Java specific (or not!) |
guides/databases.md
Outdated
### Standard Operators {.impl .node} | ||
|
||
The database services guarantee identical behavior of these operators: | ||
|
||
* `==`, `=` — with `=` null being translated to `is null` | ||
* `!=`, `<>` — with `!=` translated to `IS NOT` in SQLite, or to `IS DISTINCT FROM` in standard SQL, or to an equivalent polyfill in SAP HANA | ||
* `<`, `>`, `<=`, `>=`, `IN`, `LIKE` — are supported as is in standard SQL | ||
* `||` — concatenation operator | ||
|
||
In particular, the translation of `!=` to `IS NOT` in SQLite — or to `IS DISTINCT FROM` in standard SQL, or to an equivalent polyfill in SAP HANA — greatly improves the portability of your code. | ||
|
||
> These operators are available for runtime queries, but not in CDS files. |
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.
The behaviour of the operators is not standardized in CAP and different in CAP Java. There is an open BLI to get to a common understanding: https://github.tools.sap/cap/dev/issues/909
The corresponding documentation for CAP Java is here: https://pages.github.tools.sap/cap/docs/java/working-with-cql/query-api#predicates
> These operators are available for runtime queries, but not in CDS files. | ||
|
||
|
||
### Functions Mappings for Runtime Queries {.impl .node} |
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.
We have a general agreement on the semantic of the functions: https://github.tools.sap/cap/dev/issues/1111
We could create a table here to capture which functions are supported by CAP Java and which by CAP Node.js. SImilar to what @patricebender compiled here: https://github.tools.sap/cap/dev/issues/1111#issuecomment-7092917
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.
@renejeglinsky As a first step, this list contains all functions which are supported by the node.js runtime. For months this list has been outdated and it was not at the right place of the documentation (those functions are supported by all db services, not only sqlite).
@agoerler what do you think about adding the functions which are supported by the java runtime ({.impl .java}
) in a similar fashion? As we already went over the list, I could also contribute this list (assuming the semantics of the functions are the same).
I would probably refrain from using a table in the documentation. The list of supported functions could be toggled instead, for better readability.
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 think adding the functions using the toggle would be great. Thanks Patrice!
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.
@patricebender As this section is toggled for node, should we include the table for Java in this PR or do this as a follow-up?
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'd be fine with following up in another change to add a java toggle here 👍
> For the SAP HANA functions, both usages are allowed: all-lowercase as given above, as well as all-uppercase. | ||
|
||
|
||
### Session Variables {.impl .node} |
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.
There is a completely different API in CAP Java.
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.
As this is toggled for Node we could provide the same section for Java. Would be really nice to have it in this PR but if capacity doesn't allow for that, I don't think that would be a blocker for this change, or?
|
||
### Functions Mappings for Runtime Queries {.impl .node} | ||
|
||
A specified set of standard functions is supported in a **database-agnostic**, hence portable way, and translated to database-specific variants or polyfills. |
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.
Another thing to consider. These standard functions are not only database-agnostic but even data-source-agnostic. They can also be used with remote OData. Moreover, they there names, semantics and parameters are closer to OData then to SQL. Maybe we should move this section out of database.md and rather to a CDS QL section.
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.
@johannes-vogel What do you think?
@stewsk @johannes-vogel could you kindly review |
For CAP Java, the set of supported functions is documented here:
As mentioned earlier, these functions can be used on the DBs but also in remote OData consumption. We could add a link in an ({.impl .java}) variant. Maybe in a follow-up PR). |
@renejeglinsky how can I fix the broken anchor links mentioned in the build:
I can't find them in the repository :( |
…973) * fix: `!= null` is translated to `is not null` but `!= <xpr>` is not ``` > q = SELECT`from ${Books} { ID, title} where ID != null` > q.toSQL() { sql: `SELECT json_insert('{}','$."ID"',ID,'$."title"',title) as _json_ FROM (SELECT Books.ID,Books.title FROM sap_capire_bookshop_Books as Books WHERE Books.ID is not NULL)`, values: [] } ``` but for non-`null` comparisons, `!=` is translated to `<>`: ``` > q = SELECT`from ${Books} { ID, title} where ID != 207` > q.toSQL() { sql: `SELECT json_insert('{}','$."ID"',ID,'$."title"',title) as _json_ FROM (SELECT Books.ID,Books.title FROM sap_capire_bookshop_Books as Books WHERE Books.ID <> ?)`, values: [ 207 ] } ``` * Update guides/databases-sqlite.md
With this change,
Common Operators
andCommon Functions
have been moved from thesqlite
guide to the generic database guide.The function list is now including all functions which are supported by all
cap-js/dbs
.Todos:
Also, it would be nice to remove the disclaimer
only supported in runtime queries
, but for that we first need compiler support for the functions as well as for the operators.