Skip to content

Commit 220be72

Browse files
committed
Fixed database guides
1 parent 924ba19 commit 220be72

File tree

6 files changed

+74
-44
lines changed

6 files changed

+74
-44
lines changed

cds/cxl.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ that multiplies the two factors `price` and `quantity`.
340340
</div>
341341

342342

343-
CAP supports a set of [portable functions](../guides/databases/cql-to-sql.md#portable-functions) that can be used in all expressions. Those functions are passed through to the underlying database, allowing you to leverage the same functions for different databases, which greatly enhances portability.
343+
CAP supports a set of [portable functions](../guides/databases/cap-level-dbs#portable-functions) that can be used in all expressions. Those functions are passed through to the underlying database, allowing you to leverage the same functions for different databases, which greatly enhances portability.
344344

345345
## ref (path expression) { #ref }
346346

@@ -835,4 +835,3 @@ navigates along the `author` association of the `Books` entity only if the autho
835835
}
836836

837837
</style>
838-

guides/databases/_menu.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!-- # [ CAP-level Database Usage ](index.md) -->
2-
# [ Mocked Out of the Box ](cql-to-sql)
2+
# [ CAP-level Database Support ](cap-level-dbs)
33
# [ CDL Compiled to DDL ](cdl-to-ddl)
44
# [ Adding Initial Data ](initial-data.md)
55
# Deployed to ...
Lines changed: 65 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
1-
# CDS Compilation to Database-Specific SQL
1+
# CAP-Level Database Integration
22

33
CAP supports a number of portable functions and operators in CQL. The compiler automatically translates these to the best-possible database-specific native SQL equivalents. You can safely use these in CDS view definitions and runtime queries expressed in CQL.
44
{.abstract}
55

66
[[toc]]
77

88

9-
## Operators
9+
## Mocked Out of the Box
10+
11+
When using CAP's mocked out-of-the-box database integration, these functions and operators are supported in the in-memory SQLite database used for development and testing.
12+
13+
#### TODO:
14+
15+
- Mocked by in-memory SQLite or H2 databases
16+
- With SAP HANA or PostgreSQL for production
17+
- With a defined set of portable functions and operators
18+
19+
## Standard Operators
20+
21+
This chapter lists standardized operators supported by CAP, and guaranteed to work across all supported databases with feature parity. You can safely use these in CDS view definitions and runtime queries expressed in CQL. The compiler translates them to the best-possible database-specific native SQL equivalents.
22+
23+
### Standard SQL Operators
1024

1125
Most native SQL operators are supported in CQL as-is, like these from the SQL92 standard:
1226

@@ -77,13 +91,15 @@ FROM Books;
7791
The compiler translates this operator to the best-possible equivalent in the target database: `CASE WHEN ... THEN ... ELSE ... END` in standard SQL, or `IF(..., ..., ...)` in SAP HANA.
7892

7993

80-
## Functions
94+
## Standard Functions
8195

82-
### Portable Functions
96+
The following sections list standardized string, numeric, data/time, and aggregate functions supported by CAP, and guaranteed to work across all supported databases with feature parity. You can safely use these in CDS view definitions and runtime queries expressed in CQL. The compiler translates them to the best-possible database-specific native SQL equivalents.
97+
98+
> [!important] Function names are case-sensitive
99+
> The names for standardized functions must be written exactly as listed above. For example, `toUpper` is invalid, while `toupper` is valid. Differently cased names might also work if they match native functions of the specific database, but are not guaranteed to be portable -> always use the exact casing as listed.
83100
84-
Following are portable functions supported by CAP. You can safely use these in CDS view definitions and runtime queries expressed in CQL. The compiler translates them to the best-possible database-specific native SQL equivalents.
85101

86-
String functions:
102+
### String Functions
87103

88104
- `concat(x,y,...)`
89105
- `length(x)`
@@ -97,48 +113,63 @@ String functions:
97113
- `substring(x,start, length)`
98114
- `matchespattern(x,pattern)`
99115

116+
In addition, to `concat()`, CAP also supports the common `||` operator for string concatenation in CQL queries, same as in SQL queries. For example, these two queries are equivalent:
117+
118+
```sql
119+
SELECT concat (firstName,' ',lastName) as fullName from Authors;
120+
```
121+
```sql
122+
SELECT firstName || ' ' || lastName as fullName from Authors;
123+
```
124+
125+
126+
> [!important] Indexes and Substring Details
127+
> The return value of `indexof()` as well as the `start` parameter in `substring()` are zero-based index values. If the substring is not found, `indexof()` returns `-1`. If the `start` index in `substring()` is negative, it is counted from the end of the string. If the `length` parameter is omitted, the substring to the end of the string is returned.
100128
101-
Numeric functions:
129+
130+
### Numeric Functions
102131

103132
- `ceil(x)`, `ceiling(x)`
104133
- `floor(x)`
105134
- `round(x)`
106135

107-
###### aggregate-functions
108-
Aggregate functions:
136+
> [!warning] Non-portable <code>round()</code> function with more than one argument
137+
> Note that databases support `round()` functions with multiple arguments, the second parameter being the precision. If you use that option, the `round()` function may behave differently depending on the database.
138+
139+
140+
### Date / Time Functions
141+
142+
- `date(x)` -> `yyyy-MM-dd` strings
143+
- `time(x)` -> `HH:mm:ss` strings
144+
<br/><br/>
145+
- `year(x)` -> integer
146+
- `month(x)` -> integer
147+
- `day(x)` -> integer
148+
- `hour(x)` -> integer
149+
- `minute(x)` -> integer
150+
- `second(x)` -> integer
151+
<br/><br/>
152+
- `years_between(x,y)` -> number
153+
- `months_between(x,y)` -> number
154+
- `days_between(x,y)` -> number
155+
- `seconds_between(x,y)` -> number
156+
157+
> [!note] CAP Java support coming soon...
158+
> The above `*_between` functions are currently only supported by CAP Node.js. \
159+
> Support for CAP Java is planned for a future release.
160+
161+
162+
### Aggregate Functions
109163

110164
- `avg(x)`, `average(x)`
111165
- `min(x)`, `max(x)`
112166
- `sum(x)`
113167
- `count(x)`
114168
<!-- - `countdistinct(x)` -->
115169

116-
Date / Time functions:
117-
118-
- `date(x)` -> `yyyy-MM-dd`
119-
- `time(x)` -> `HH:mm:ss`
120-
- `year(x)`
121-
- `month(x)`
122-
- `day(x)`
123-
- `hour(x)`
124-
- `minute(x)`
125-
- `second(x)`
126-
- `years_between(x,y)`
127-
- `months_between(x,y)`
128-
- `days_between(x,y)`
129-
- `seconds_between(x,y)`
130-
131-
> [!important] Function names are case-sensitive
132-
> The function names must be written exactly as listed above. For example, `toUpper` is invalid, while `toupper` is valid. Differently cased names might also work if they match native functions of the specific database, but are not guaranteed to be portable -> always use the exact casing as listed.
133-
134-
> [!important] Non-portable <code>round()</code> function with more than one argument
135-
> Note that databases support `round()` functions with multiple arguments, the second parameter being the precision. If you use that option, the `round()` function may behave differently depending on the database.
136-
137-
> [!note] Indexes and Substring Details
138-
> The return value of `indexof()` as well as the `start` parameter in `substring()` are zero-based index values. If the substring is not found, `indexof()` returns `-1`. If the `start` index in `substring()` is negative, it is counted from the end of the string. If the `length` parameter is omitted, the substring to the end of the string is returned.
139170

140171

141-
### Native Functions
172+
## Native Functions
142173

143174
In general, the CDS compiler doesn't 'understand' SQL functions but translates them to SQL _generically_ as long as they follow the standard call syntax of `fn(x,y,...)`. This allows to use all native database functions inside your CDS models, like this:
144175

@@ -152,7 +183,7 @@ SELECT from Books {
152183
> Using native functions like this makes your CDS models database-specific, and thus less portable. Therefore, prefer using the [portable functions](#portable-functions) listed above whenever possible.
153184
154185

155-
### Window Functions
186+
## Window Functions
156187

157188
[SQL window functions](https://en.wikipedia.org/wiki/Window_function_(SQL)) with `OVER` clauses are supported as well, for example:
158189

guides/databases/cdl-to-ddl.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ CREATE VIEW SomeProjection AS SELECT ... FROM SomeEntity;
160160
:::
161161

162162
> [!tip] Views are defined using CQL
163-
> Both view defined per `as projection on` and those using `as select from` are defined using CQL, which supports a broad scope of database-agnostic features. Learn more about that in the following guide: [_CQL Compilation to SQL_](cql-to-sql).
163+
> Both view defined per `as projection on` and those using `as select from` are defined using CQL, which supports a broad scope of database-agnostic features. Learn more about that in the following guide: [_CQL Compilation to SQL_](cap-level-dbs).
164164
165165
#### Qualified Names ⇒ Slugified
166166

guides/databases/index.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,19 @@ The illustration below shows what happens automatically under the hood:
3737

3838
The following guides explain the details of CAP-level database integration, which are mostly database-agnostic, and apply to all supported databases:
3939

40-
[CDL Compiled to DDL](cdl-to-ddl.md)
40+
[ CAP-level Database Integration ](cap-level-dbs.md)
4141
: How database-agnostic CDS models in CDL format are compiled to native DDL statements for different databases.
4242

43-
[CQL Compiled to SQL](cql-to-sql.md)
43+
[ CQL Compiled to SQL ](cdl-to-ddl.md)
4444
: How database-agnostic CDS queries in CQL format are compiled to native SQL statements for different databases.
4545

46-
[Adding Initial Data](initial-data.md)
46+
[ Adding Initial Data ](initial-data.md)
4747
: How to provide initial data and test data using CSV files, which are loaded into the database automatically.
4848

49-
[Schema Evolution](schema-evolution.md)
49+
[ Schema Evolution ](schema-evolution.md)
5050
: How to manage schema changes with appropriate schema evolution strategies for development and production.
5151

52-
[Performance Guide](performance.md)
52+
[ Performance Guide ](performance.md)
5353
: Pointing out performance considerations, and common pitfalls.
5454

5555

java/working-with-cql/query-api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ You can aggregate data in two ways:
713713

714714
#### Aggregation Functions { #aggregation-functions }
715715

716-
Use [aggregation functions](../../guides/databases/cql-to-sql#aggregate-functions) to calculate minimums, maximums, totals, averages, and counts of values. You can use them in *columns* of `Select` statements to include the aggregated values in the result set, or in the [having](#having) clause to filter based on aggregated values.
716+
Use [aggregation functions](../../guides/databases/cap-level-dbs#aggregate-functions) to calculate minimums, maximums, totals, averages, and counts of values. You can use them in *columns* of `Select` statements to include the aggregated values in the result set, or in the [having](#having) clause to filter based on aggregated values.
717717

718718

719719
#### Grouping { #grouping }

0 commit comments

Comments
 (0)