Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: standard database functions everywhere #1750

Open
wants to merge 2 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

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

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

- `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

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

#### Numeric Functions

- `ceiling(x)`
Rounds the numeric parameter up 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.

n/a in CAP Java

- `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!

@@ -1015,7 +1008,8 @@ In addition to the OData and SAP HANA standard functions, the **CAP runtimes** p
Utilizes standard variable names to maintain session context.
Refer to [Session Variables](#session-variables) for additional information.


- `now()`
Returns the current datetime.
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 we have the ref $now but it returns the current Timestamp and not the current DateTime.

Copy link
Member Author

Choose a reason for hiding this comment

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

In node we return now: () => session_context('$now')` and this in turn returns the current timestamp, thanks for pointing this out. I will adapt the docs :)

Extracts a substring from `x` starting at index `i` (0-based) with an optional length `n`.
- `i`:
- Positive: starts at index `i`
- Negative: starts `i` positions before the end
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not covered by 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.

To me it reads like it is:

The two-argument substring function with string parameter values returns a substring of the first parameter string value, starting at the Nth character and finishing at the last character (where N is the second parameter integer value)
A negative start index N, if supported, returns a string/collection starting N characters/items before the end of the string/collection.

we could align the parameter names in our docu with those found in the OData spec

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants