-
Notifications
You must be signed in to change notification settings - Fork 120
feat: standard database functions everywhere #1750
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
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- not available in CAP Java
- returns
String
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- CAP Java
Value.contains(other)
Value.contains(other, isCaseInsensitive)
to control if case sensitiveValue.contains
is exact and never fuzzy- represented by
CqnContainmentTest
- implemented by
LIKE
orILIKE
, 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all OData inspired functions are case sensitive
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- CAP Java:
startsWith
- case sensitive?
- return
Boolean
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.
all OData inspired functions are case sensitive
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- CAP Java:
endsWith
- case sensitive?
- return
Boolean
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.
all OData inspired functions are case sensitive
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-> 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- what is an
xs
? - please provide an example how this can be used in a view definition
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.
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)` |
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.
n/a in CAP Java
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In CAP Java you can use the refs $now
, $user
, $valid.from
, $valid.to
.
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found that using a negative precision does not work on SQLite.
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 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 <[email protected]>
Co-authored-by: René Jeglinsky <[email protected]>
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