Skip to content
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

Documentation for OQL #8431

Open
wants to merge 70 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
8786adf
Documentation for OQL clauses
dahfjkg Oct 4, 2024
c1c38c6
Move to new OQL section of Domain Model
MarkvanMents Oct 14, 2024
3df814d
Proofread
MarkvanMents Oct 14, 2024
7369d45
Proofread
MarkvanMents Oct 14, 2024
239aebd
Proofread
MarkvanMents Oct 15, 2024
5b87de2
Proofread
MarkvanMents Oct 17, 2024
1dc3853
Resolve review comments
dahfjkg Oct 21, 2024
778804a
Proofread to Subqueries section.
MarkvanMents Oct 21, 2024
7f32144
Update content/en/docs/refguide/modeling/domain-model/oql/oql-clauses.md
dahfjkg Oct 21, 2024
63990a7
Better examples for GROUP BY and HAVING
dahfjkg Oct 21, 2024
f421fa9
Update content/en/docs/refguide/modeling/domain-model/oql/oql-clauses.md
dahfjkg Oct 25, 2024
578850c
Describe OQL v2 behavior changes
dahfjkg Oct 25, 2024
4d41982
review comments
dahfjkg Oct 25, 2024
7915620
More review comments and more OQL v2 changes
dahfjkg Oct 30, 2024
3752329
Spellcheck and Lint
MarkvanMents Nov 5, 2024
9afddc3
Proofread oql/_index
MarkvanMents Nov 5, 2024
04aec8a
Proofread oql-clauses
MarkvanMents Nov 5, 2024
2954bd3
Proofread OQL V2
MarkvanMents Nov 6, 2024
db0ae27
Address review comments
dahfjkg Nov 13, 2024
02ea327
Update content/en/docs/refguide/modeling/domain-model/oql/oql-clauses.md
dahfjkg Nov 13, 2024
a659675
Combine existing content into oql-expressions doc
pijuskri Oct 1, 2024
3272da6
Parameter example improvements
pijuskri Oct 1, 2024
8266592
Aggregate documentation
pijuskri Oct 2, 2024
2c3bcff
Aggregate documentation, examples
pijuskri Oct 3, 2024
b5ed1ff
Correct parameter examples, remove bad examples
pijuskri Oct 10, 2024
99756a5
Move oql-expressions to domain-model/oql
MarkvanMents Oct 16, 2024
0f48af2
Proofread oql-expressions
MarkvanMents Oct 16, 2024
0971e3a
Improve wording, change example order
pijuskri Oct 17, 2024
6b361e0
Add reference tag to aggregates section
pijuskri Oct 21, 2024
ef8215b
Align definition of expressions with oql clauses doc
pijuskri Oct 21, 2024
769e32c
Handle review comments
pijuskri Oct 31, 2024
0156528
Proofread and confirm review changes
MarkvanMents Nov 5, 2024
e4f7605
Combine functions and operators into a single file
pijuskri Oct 4, 2024
a1a5b6b
Operator structure, Plus, Minus
pijuskri Oct 7, 2024
a75a123
Binary operator examples, null handling, precedence, string coercion
pijuskri Oct 10, 2024
dcddfa0
Complete other binary operators
pijuskri Oct 11, 2024
e462d7c
Add literals, update COALESCE
pijuskri Oct 15, 2024
90f6118
Add section on system variables
pijuskri Oct 21, 2024
fdbeec6
Add function examples
pijuskri Oct 21, 2024
687d47d
Add range, cast examples
pijuskri Oct 22, 2024
f27592b
Move file to correct location
pijuskri Oct 22, 2024
9c2a09f
Handle review comments
pijuskri Oct 30, 2024
26f4c0c
Spelling and Markdown Review
MarkvanMents Nov 11, 2024
5921b2e
Proofread to 5.4
MarkvanMents Nov 11, 2024
32659c5
Proofread to COALESCE
MarkvanMents Nov 11, 2024
bb45d27
Finish Proofread of oql-expression-syntax
MarkvanMents Nov 12, 2024
5d45760
Address review comments for Expressions Syntax
dahfjkg Nov 13, 2024
981a82e
Address more review comments for Expressions Syntax
dahfjkg Nov 13, 2024
a43dfd1
Document data type validations of expressions in OQL v2
dahfjkg Nov 13, 2024
9c30053
Add links to OQL v2 validations to corresponding functions
dahfjkg Nov 13, 2024
dcb1cea
Correct examples with missing attribute aliases
pijuskri Nov 19, 2024
0a4d137
Add oql UNION clause documentation section
pijuskri Nov 20, 2024
4e2a5ea
Improve oql-v2 docs on alias requirements
pijuskri Nov 21, 2024
841634a
Typo
MarkvanMents Nov 26, 2024
689cf90
Merge branch 'development' into pr/dahfjkg/8431
MarkvanMents Nov 26, 2024
3dc9a9c
Merge branch 'dat/oql-clauses' of https://github.com/dahfjkg/docs int…
MarkvanMents Nov 26, 2024
eb6cb7c
Proofread
MarkvanMents Nov 26, 2024
f692c0e
Add example about UNION of associations
pijuskri Nov 26, 2024
d542cc6
Delete old OQL Clauses
MarkvanMents Nov 27, 2024
34bac48
Remove old OQL Expressions documentation
MarkvanMents Nov 27, 2024
e2acf96
rename data-sets document
MarkvanMents Nov 27, 2024
d74afff
Move Datasets into Data/Entities section
MarkvanMents Nov 27, 2024
6181931
Rename Domain Model section to Data
MarkvanMents Nov 27, 2024
a118e63
Move OQL in navigation.
MarkvanMents Nov 27, 2024
09f2483
Reorganize reserved words
MarkvanMents Nov 27, 2024
0d8ccec
Proofread
MarkvanMents Nov 27, 2024
fa52d8d
Mention that FLOAT is not to be used in OQL
dahfjkg Dec 5, 2024
833492b
More details on system variables in OQL
dahfjkg Dec 18, 2024
7200ba2
Change link to setting that enables OQL v2
dahfjkg Dec 18, 2024
edeaf73
Add more information on tokens in OQL
dahfjkg Dec 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 125 additions & 3 deletions content/en/docs/refguide/modeling/domain-model/oql/oql-clauses.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Clauses must be presented in the following order, but can be left out if they ar
7. `LIMIT`
8. `OFFSET`

The `UNION` clause defies the usual order presented above. It will be presented in a [Union Clause](#oql-union) section at the end.

## `SELECT` Clause

The `SELECT` clause specifies which entity attributes or other specified data must be retrieved. The clause returns all the requested values of objects which match the `SELECT` clause.
Expand Down Expand Up @@ -813,10 +815,8 @@ HAVING

The `ORDER BY` clause specifies the sort order used on columns returned in a `SELECT` statement. Multiple columns can be specified. Columns are ordered in the sequence of the items in the `ORDER BY` clause.

{{% todo %}}Add link to UNION documentation{{% /todo %}}

{{% alert color="info" %}}
This clause can include items that do not appear in the `SELECT` clause, except when `SELECT DISTINCT` is specified or when a `GROUP BY` clause exists. When `UNION` is used, the column names or aliases must be those specified in the `SELECT` clause of the first part of the query.
This clause can include items that do not appear in the `SELECT` clause, except when `SELECT DISTINCT` is specified or when a `GROUP BY` clause exists. When `UNION` is used, the column names or aliases must be those specified in the `SELECT` clause of the first part of the query. More information is presented in the [Union Clause](#oql-union) section.
{{% /alert %}}

### Syntax
Expand Down Expand Up @@ -1027,6 +1027,128 @@ OFFSET 2
| Rekall | Utrecht | 4 |
| Veidt | Utrecht | 5 |

## `UNION` Clause {#oql-union}
dahfjkg marked this conversation as resolved.
Show resolved Hide resolved
The clause takes multiple select queries and combines their results into a single result set.
The resulting set by default only includes distinct rows. The `ALL` keyword can be used to include all rows. Rows are considered distinct if the combination of the column values is distinct from all other rows. Comparison logic of values is the same as the `DISTINCT` keyword of a `SELECT` clause.

All select queries must define the same number of columns in the same order and their datatypes should match. The resulting column names will those used in the very first `SELECT` clause.
MarkvanMents marked this conversation as resolved.
Show resolved Hide resolved

### Syntax

The syntax is as follows:

```sql
select_query
{
UNION [ALL] select_query
} [ ,...n ]
[ order_by_clause ]
[ LIMIT number ]
[ OFFSET number ]
```

{{% todo %}} Document data type behaviour when corresponding oql v2 issue is finished {{% /todo %}}

### Examples

The following query combines sales person and customer names into a single table:

```sql
SELECT FirstName, LastName
FROM Sales.SalesPerson
UNION
SELECT FirstName, LastName
FROM Sales.Customer
```

| FirstName | LastName |
|-----------|----------|
| John | Doe |
| Amelia | Doe |
| Oliver | Doe |
| Oliver | Moose |
| Jane | Moose |
| Jane | Doe |

Some names are duplicated across the tables, so only some entries are included in the result. The query below uses `UNION ALL` to include all names the result:

```sql
SELECT FirstName, LastName
FROM Sales.SalesPerson
UNION ALL
SELECT FirstName, LastName
FROM Sales.Customer
```

| FirstName | LastName |
|-----------|----------|
| John | Doe |
| Amelia | Doe |
| Oliver | Doe |
| Oliver | Moose |
| Jane | Moose |
| John | Doe |
| Jane | Doe |
| Jane | Doe |
| Jane | Moose |


The following query performs a self union of a table, returning fewer rows than the original table, as only distinct rows are included in the result.

```sql
SELECT FirstName FName, LastName LName
FROM Sales.Customer
UNION
SELECT FirstName FName, LastName LName
FROM Sales.Customer
```

| FName | LName |
| ----- | ----- |
| John | Doe |
| Jane | Doe |
| Jane | Moose |

The result of the union can also be sorted and limited, similar to a normal `SELECT` clause. This query retrieves the first 4 names sorted on both first and last name:

```sql
SELECT FirstName, LastName
FROM Sales.SalesPerson
UNION
SELECT FirstName, LastName
FROM Sales.Customer
ORDER BY FirstName, LastName
LIMIT 4
```

| FirstName | LastName |
|-----------|----------|
| Amelia | Doe |
| Jane | Doe |
| Jane | Moose |
| John | Doe |

`UNION` can be chained to use more than 2 select queries as a source. This query collects all distinct first and last names into a single column in a single table:

```sql
SELECT FirstName AS Name FROM Sales.SalesPerson
UNION
SELECT FirstName AS Name FROM Sales.Customer
UNION
SELECT LastName AS Name FROM Sales.SalesPerson
UNION
SELECT LastName AS Name FROM Sales.Customer
```

| Name |
|--------|
| John |
| Amelia |
| Oliver |
| Jane |
| Doe |
| Moose |

## Subqueries

A subquery is an OQL query nested inside another query. A subquery can contain the same clauses as a regular OQL query. The entities from the outer query can be referred to in a subquery. A subquery can be used in different parts of the query.
Expand Down
25 changes: 23 additions & 2 deletions content/en/docs/refguide/modeling/domain-model/oql/oql-v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ In OQL v2, you can no longer use a path over association in a `GROUP BY` query b
This query is not allowed anymore:

```sql
SELECT COUNT(*)
SELECT COUNT(*) AS count
FROM Module.Person
GROUP BY Module.Person/Module.Person_City/Module.City/Name
```

Instead, you can use the long path in the `JOIN` pattern as follows:

```sql
SELECT COUNT(*)
SELECT COUNT(*) AS count
FROM Module.Person AS P
JOIN Module.Person/Module.Person_City/Module.City AS C
GROUP BY C/Name
Expand Down Expand Up @@ -85,6 +85,7 @@ SELECT
)
FROM Module.City
```
The column names in this case would be `Name` and a `null` name which would not be possible to refer to.

In OQL v2, such queries are no longer allowed. You must always provide an alias for subqueries that do not result in a named column. The query above can be rewritten as follows:

Expand All @@ -99,6 +100,26 @@ SELECT
FROM Module.City
```

This also applies to constants as attributes, including `NULL`. The query below is no longer allowed:
```sql
SELECT
Name,
NULL
FROM Module.City
```

It can be rewritten to use aliases for constants:
```sql
SELECT
Name,
NULL as NullColumn
FROM Module.City
```

{{% alert color="info" %}}
This requirement only applies to attributes in the main `SELECT` query. `SELECT` clauses inside subquries are not affected, as are columns that are used for comparisons like in a `WHERE` clause.
{{% /alert %}}

### Duplicate Columns in ‘SELECT’

#### Specify Entity Name
Expand Down