Skip to content

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

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

patricebender
Copy link
Member

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

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

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.
Copy link
Contributor

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

Copy link
Contributor

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.

Removes leading and trailing whitespaces.

- `contains(x, y)`
Checks whether `y` is contained in `x` (fuzzy matching may apply).
Copy link
Contributor

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 sensitive
    • Value.contains is exact and never fuzzy
    • represented by CqnContainmentTest
    • implemented by LIKE or ILIKE, if available
  • is the Compiler's implementation case sensitive or case insensitive
  • OData v4, CAP: case sensitive
  • OData v4, RAP: case insensitive (!)
  • returns Boolean

Copy link
Member Author

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, OData specifies this function as case sensitive:

String comparison is case-sensitive, case-insensitive comparison can be achieved in combination with tolower or toupper.

Checks whether `y` is contained in `x` (fuzzy matching may apply).

- `startswith(x, y)`
Checks whether `y` starts with `x`.
Copy link
Contributor

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

Copy link
Member Author

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

Copy link
Member Author

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

Copy link
Contributor

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:

Copy link
Member Author

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.

- `startswith(x, y)`
Checks whether `y` starts with `x`.

- `endswith(x, y)`
Copy link
Contributor

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

Copy link
Member Author

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

Copy link
Member Author

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-> case sensitive?

yes, like specified by OData.

Comment on lines 986 to 995
- `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.
Copy link
Contributor

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

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).
Copy link
Contributor

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

Copy link
Member Author

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 :)

- `ceiling(x)`
Rounds the numeric parameter up to the nearest integer.

- `floor(x)`
Copy link
Contributor

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

Comment on lines 1007 to 1011
- `session_context(v)`
Utilizes standard variable names to maintain session context.
Refer to [Session Variables](#session-variables) for additional information.

- `now()`
Copy link
Contributor

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.

Copy link
Member Author

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!

Checks whether `y` is contained in `x` (fuzzy matching may apply).

- `startswith(x, y)`
Checks whether `y` starts with `x`.
Copy link
Contributor

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.
Copy link
Contributor

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

@patricebender patricebender enabled auto-merge April 28, 2025 12:42

::: 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.
Copy link
Contributor

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.

Copy link
Member Author

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?

danjoa
danjoa previously requested changes Apr 29, 2025
@danjoa danjoa dismissed their stale review April 30, 2025 05:41

Resolved

@danjoa danjoa self-requested a review April 30, 2025 05:41
Co-authored-by: René Jeglinsky <[email protected]>
Co-authored-by: René Jeglinsky <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants