Skip to content

Conversation

@patricebender
Copy link
Contributor

TBD

Comment on lines +37 to +39
No matter where `CXL` is used, it always manifests in queries.
For example, [a calculated element](./cdl/#calculated-elements) defined in an entity will be resolved
to the respective calculation in the generated query when the entity is queried.
Copy link
Contributor

Choose a reason for hiding this comment

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

You can use expressions in various other places

  • translated to EDMX-expressions
  • to define projections between types
  • projections can be resolved at runtime (runtime views)
  • expressions can be evaluated in memory

Copy link
Contributor

@Akatuoro Akatuoro Dec 11, 2025

Choose a reason for hiding this comment

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

Query does not mean that it is a database query. There can be multiple vehicles for an expression. Conceptually though, it can be understood as part of a query - whether it is either sent to the database, converted to edmx (and then sent to the backend again), or evaluated in memory.
This is an important point though. Expressions are not only meant for database queries.

Keeping this open -> happy for suggestions on how to formulate this.

@renejeglinsky
Copy link
Contributor

There's one example where it's not the text but the box that is clickable. Is that on purpose?
image

@patricebender
Copy link
Contributor Author

There's one example where it's not the text but the box that is clickable. Is that on purpose? image

actually, I want to have clickable boxes. Will check!

Copy link
Contributor

@swaldmann swaldmann Dec 19, 2025

Choose a reason for hiding this comment

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

Whenever I see Venn diagrams explaining JOINs I'm reminded of this article/rant, where the author makes the case that set theory is a false analogy as JOINs are rather a cross product filtered by a predicate with an optional UNION:
https://blog.jooq.org/say-no-to-venn-diagrams-when-explaining-joins/

Food for thought 🤔 The JOIN diagrams shown there could also come in helpful in some Capire guides.

Copy link
Contributor

@Akatuoro Akatuoro Dec 19, 2025

Choose a reason for hiding this comment

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

Thanks for the link! This topic also came up when writing the theory section, because the inner join is indeed $\{ (a, b) \in \text{Authors} \times \text{Books} | a.\text{id} = b.\text{author\_id} \}$ -> a cross product with a filter.

Just jotting down my thoughts:
The key point of the blog entry in regards to why this can not be shown as a Venn diagram is that the sets (Authors and Books) are of a different type and are not union-compatible. So $\text{Authors} \cap \text{Books}$ is indeed not correct.
Rather, we implicitely look at the cross product
$$X = \{ \space (a_1, \dots, a_n, b_1, \dots, b_m) \in \{ \text{Authors} \cup \{(\omega, \dots, \omega)\} \} \times \{ \text{Books} \cup \{(\omega, \dots, \omega)\} \} - \{(\omega, \dots, \omega)\} \space \}$$
with each circle representing:
$$\text{Authors}' = \{ (a_1, \dots, a_n, b_1, \dots, b_m) \in X | a_\text{id} \ne \omega \}$$
$$\text{Books}' = \{ (a_1, \dots, a_n, b_1, \dots, b_m) \in X | b_\text{id} \ne \omega \}$$

Getting the actual authors back is now only an exercise of projection:
$$\{ (a_1, \dots, a_n) \} = \{ \pi_{a_1, \dots, a_n}(\text{Authors}') \} = \text{Authors}$$
-> Select distinct a.* from Authors a full join Books b on 1 = 1

Since the sets are independent of the projection (what we select), any join operations simply filter on the cross product, which imho can be nicely displayed using venn diagrams. So I do disagree with the author of the blog even though they have a point. I also think the join diagrams could come in helpful.

One of the key points in cql / cxl is that path navigation allows us to work on sets and only consider the select list (projection in relational algebra) at the end. When actually writing relational algebra, the tuple needs to be defined explicitely. CQL and SQL also handle null values nicely. When writing relational algebra, null values need to be explicitely included.

Copy link
Contributor

Choose a reason for hiding this comment

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

explaining JOINs

But we don't want to explain joins! We have sets of instances of some entity type that are associated with some other instances of in a different set. Sometimes our SQL backends use a JOIN in SQL to compute a cross product of these sets. But this is an implementation detail of the SQL backends.

???
In this example, we select all books and order them by the date of birth of their authors.
The table alias for the `author` association is used in the order by clause of the SQL query.

Copy link
Contributor

Choose a reason for hiding this comment

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

please add a hint that you should any path expression used in order by should also be on the select list


### after `exists` predicate

path expressions can also be used after the `exists` predicate to check for the existence.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
path expressions can also be used after the `exists` predicate to check for the existence.
Path expressions can also be used in the `exists` predicate to check wether the set that is referenced by the path is not empty.

path expressions can also be used after the `exists` predicate to check for the existence.
This is especially useful for to-many relations.

E.g., to select all authors that have written **at least** one book:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
E.g., to select all authors that have written **at least** one book:
E.g., to select all authors that have written **at least** one book:

cds/cxl.md Outdated



Every entity defines a set of all possible instances:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Every entity defines a set of all possible instances:
Every entity defines a set of all instances:

cds/cxl.md Outdated
Every entity defines a set of all possible instances:
$${ b \in \text{Books} }$$

A simple select query on Books returns the complete set → all books.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
A simple select query on Books returns the complete set → all books.
A simple select from Books returns the complete set → all books.

Comment on lines +600 to +601
group by genre
order by genre asc`
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
group by genre
order by genre asc`
group by genre.name
order by genre.name`

Comment on lines +589 to +590
Using the infix notation to specify the query modifiers is just
syntactic sugar:
Copy link
Contributor

Choose a reason for hiding this comment

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

No. Using the infix notation to specify the query modifiers makes it really hard to understand (and explain) what the infix does. I think the plain infix filter is easy to understand though.

syntactic sugar:

```js
await cds.ql`
Copy link
Contributor

Choose a reason for hiding this comment

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

this example is easy to understand

}
GROUP BY books.author.ID`

## ordering term <Badge class="badge-inline" type="tip" text="💡 clickable diagram" /> { #ordering-term }
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 related to the query language and not to the expression language, I think. Move to CQL chapter?


$$\text{books} = \{ (a,b) \in \text{Books} \times \text{Authors} \mid b.\text{author\_id} = a.\text{id} \}$$

We can select this set using the path expression `Authors:books` in the [from clause](#in-from-clause).
Copy link
Contributor

Choose a reason for hiding this comment

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

why not Authors.books ?

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.

6 participants