feat: standard database functions everywhere#1750
Conversation
The cds-compiler and the node database services now are on-par with regard to the supported standard database functions. With this change we move the standard database function section out of the "runtime" part. Once CAP Java closed the gap, we can remove the disclaimer that this is only available for cds-compiler + node database services
| #### String Functions | ||
|
|
||
| - `concat(x, y, ...)` | ||
| Concatenates the given strings or numbers. |
There was a problem hiding this comment.
- not available in CAP Java
- do you support the concat operator (
||) ? - https://github.wdf.sap.corp/cds-java/home/issues/1998
- returns
String
There was a problem hiding this comment.
Yes we support the concat operator
| Concatenates the given strings or numbers. | ||
|
|
||
| - `trim(x)` | ||
| Removes leading and trailing whitespaces. |
There was a problem hiding this comment.
- not available in CAP Java
- returns
String
There was a problem hiding this comment.
According to OData, this should be whitespace characters, according to Unicode rules.
I think these are:
- u2002
- \u3000
- \r
- \u0085
- \u200A
- \u2005
- \u2000
- \u3000
- \u2029
- \u000B
- \u3000
- \u2008
- \u2003
- \u205F
- \u3000
- \u1680
- \u0009
- \u0020
- \u2006
- \u2001
- \u202F
- \u00A0
- \u000C
- \u2009
- \u3000
- \u2004
- \u3000
- \u3000
- \u2028
- \n
- \u2007
- \u3000
@patricebender - do you trim these characters or just whatever the DB considers to be a whitespace? I think the latter would be fine for most practical purposes. (Although we recently had an issue with a Chinese WS character (!)). At least we need to document which interpretation of whitespace character we apply.
guides/databases.md
Outdated
| Removes leading and trailing whitespaces. | ||
|
|
||
| - `contains(x, y)` | ||
| Checks whether `y` is contained in `x` (fuzzy matching may apply). |
There was a problem hiding this comment.
- CAP Java
Value.contains(other)Value.contains(other, isCaseInsensitive)to control if case sensitiveValue.containsis exact and never fuzzy- represented by
CqnContainmentTest - implemented by
LIKEorILIKE, if available
- is the Compiler's implementation case sensitive or case insensitive
- OData v4, CAP: case sensitive
- OData v4, RAP: case insensitive (!)
- returns
Boolean
There was a problem hiding this comment.
all OData inspired functions are case sensitive
guides/databases.md
Outdated
| Checks whether `y` is contained in `x` (fuzzy matching may apply). | ||
|
|
||
| - `startswith(x, y)` | ||
| Checks whether `y` starts with `x`. |
There was a problem hiding this comment.
- CAP Java:
startsWith - case sensitive?
- return
Boolean
There was a problem hiding this comment.
all OData inspired functions are case sensitive
There was a problem hiding this comment.
maybe cap-java could also provide a case sensitive variant in all lowercase to be in line with OData
There was a problem hiding this comment.
all OData inspired functions are case sensitive
I am not referring to the function's name but to the comparison semantics. CAP Java has a case-sensitive and a case-insensitive variant of startsWith:
There was a problem hiding this comment.
thanks for the clarification, we are in line with the OData spec for this function:
String comparison is case-sensitive, case-insensitive comparison can be achieved in combination with tolower or toupper.
guides/databases.md
Outdated
| - `startswith(x, y)` | ||
| Checks whether `y` starts with `x`. | ||
|
|
||
| - `endswith(x, y)` |
There was a problem hiding this comment.
- CAP Java:
endsWith - case sensitive?
- return
Boolean
There was a problem hiding this comment.
all OData inspired functions are case sensitive
There was a problem hiding this comment.
maybe cap-java could also provide a case sensitive variant in all lowercase to be in line with OData
There was a problem hiding this comment.
-> case sensitive?
guides/databases.md
Outdated
| - `years_between` | ||
| Computes the number of years between two specified dates. | ||
| - `months_between` | ||
| Computes the number of months between two specified dates. | ||
| - `days_between` | ||
| Computes the number of days between two specified dates. | ||
| - `seconds_between` | ||
| Computes the number of seconds between two specified dates. | ||
| - `nano100_between` | ||
| Computes the time difference between two dates to the precision of 0.1 microseconds. |
There was a problem hiding this comment.
- n/a in CAP Java
- please link to the corresponding HANA functions.
- these functions are very prone to one-off errors -> require a very precise specification
guides/databases.md
Outdated
| In addition to the OData and SAP HANA standard functions, the **CAP runtimes** provides special functions that are only available for runtime queries: | ||
|
|
||
| - `search(xs, y)` | ||
| Checks whether `y` is contained in any element of `xs` (fuzzy matching may apply). |
There was a problem hiding this comment.
- what is an
xs? - please provide an example how this can be used in a view definition
There was a problem hiding this comment.
It cant be used in a view defintion as indicated by the section heading and description. I will change xs to x :)
guides/databases.md
Outdated
| - `ceiling(x)` | ||
| Rounds the numeric parameter up to the nearest integer. | ||
|
|
||
| - `floor(x)` |
guides/databases.md
Outdated
| - `session_context(v)` | ||
| Utilizes standard variable names to maintain session context. | ||
| Refer to [Session Variables](#session-variables) for additional information. | ||
|
|
||
| - `now()` |
There was a problem hiding this comment.
In CAP Java you can use the refs $now, $user, $valid.from, $valid.to.
There was a problem hiding this comment.
same for node, but this is besides the point of the standard functions. I will add a link to the other section though!
guides/databases.md
Outdated
| Checks whether `y` is contained in `x` (fuzzy matching may apply). | ||
|
|
||
| - `startswith(x, y)` | ||
| Checks whether `y` starts with `x`. |
There was a problem hiding this comment.
all OData inspired functions are case sensitive
I am not referring to the function's name but to the comparison semantics. CAP Java has a case-sensitive and a case-insensitive variant of startsWith:
| Rounds the numeric parameter down to the nearest integer. | ||
|
|
||
| - `round(x)` | ||
| Rounds the numeric parameter to the nearest integer. |
There was a problem hiding this comment.
Java:
- return type: Type of x.
- available now
guides/databases.md
Outdated
|
|
||
| ::: warning `round` function with more than one argument | ||
| please note that most databases support `round` functions with multiple arguments. | ||
| The second parameter being the precision. SAP HANA even has a third argument which is the rounding mode. |
There was a problem hiding this comment.
I found that using a negative precision does not work on SQLite.
There was a problem hiding this comment.
we only take care of the one argument variant of the round function, as we try to replicate the OData round. Everything else will be db-specific, which is what I tried to outline in this warning. @stewsk what do you think?
Co-authored-by: René Jeglinsky <rene.jeglinsky@sap.com>
Co-authored-by: René Jeglinsky <rene.jeglinsky@sap.com>
|
@renejeglinsky ready to be merged :) |
The cds-compiler and the node database services now are on-par with regard to the supported standard database functions.
With this change we move the standard database function section out of the "runtime" part. Once CAP Java closed the gap, we can remove the disclaimer that this is only available for cds-compiler + node database services