Skip to content

Commit 6af175e

Browse files
Review TypeQL reference to ensure it is up to date (#980)
## Goal Updates to TypeQL reference pages
1 parent 9647dfd commit 6af175e

29 files changed

+227
-136
lines changed

core-concepts/modules/ROOT/pages/typeql/entities-relations-attributes.adoc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
= Entities, Relations, Attributes
22
:page-aliases: {page-version}@typeql::data_model.adoc
3-
// TODO: Out links to manual / fundamentals articles
43

54
TypeDB implements the Polymorphic Entity-Relation-Attribute (PERA) data model.
65
A TypeDB schema defines a hierarchy of these types and how they interact with each other through interface types.

core-concepts/modules/ROOT/pages/typeql/glossary.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
This page lists out terms reused across pages in this section,
44
and links to where they are introduced.
5+
A more complete list can be found in the xref:{page-version}@reference::typeql/keywords.adoc[TypeQL reference].
56

67
* xref:{page-version}@core-concepts::typeql/constraining-data.adoc#definition-annotation[Annotation]: Language fragments mainly used to add additional constraint to types.
78
* xref:{page-version}@core-concepts::typeql/query-variables-patterns.adoc#definition-answer[Answer]: A mapping of variables to the concepts the pattern "matched" in the database.

core-concepts/modules/ROOT/pages/typeql/index.adoc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ The relevant sections of the reference are linked at the end of each page.
2121
[.clickable]
2222
****
2323
A gentle introduction to the PERA data model - Entities, relations, attributes
24-
// TODO: Or: Introduces the TypeQL data model - entities, relations, and attributes -
2524
and what it means to "own" attributes and "play" roles in relations.
2625
****
2726

core-concepts/modules/ROOT/pages/typeql/queries-as-functions.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ using the reduce return modifier.
4242
[,typeql]
4343
.Find the number of posts by a page
4444
----
45-
fun post_count($page: page) -> { integer }:
45+
fun post_count($page: page) -> integer:
4646
match
4747
$posting isa posting, links (posted: $page);
4848
return count($post);
4949
----
5050

5151
[NOTE]
5252
====
53-
Since `reduce` can be used with `groupby`, the `reduce` modifier returns a stream.
53+
`reduce` returns a single answer, since it aggregates all answers into one.
5454
====
5555

5656
== Cyclic functions & tabling

core-concepts/modules/ROOT/pages/typeql/query-variables-patterns.adoc

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,8 @@ See xref:{page-version}@core-concepts::typeql/schema-data.adoc[].
125125
Variable names are unique within a pipeline -
126126
every usage of a variable with a certain name refers to the same variable.
127127

128-
In the following sections, the term [[definition-local-variable]]"local" is used to mean
128+
In the following sections, the term [[definition-internal-variable]]"internal" is used to mean
129129
a variable is bound in that pattern but not in its parent.
130-
This contrasts with the usage in programming languages where it refers to the scope of a variable name.
131-
As mentioned above, the scope of variable names in TypeQL is the xref:{page-version}@core-concepts::typeql/query-clauses.adoc[pipeline].
132130

133131
== Disjunctions, negations & optionals
134132

@@ -159,7 +157,7 @@ An answer to any pattern in the disjunction is an answer to the disjunction.
159157

160158
A variable is "bound" in a disjunction if it is bound in every branch of the disjunction.
161159
Variables which are present in & bound by only some of the branches of the disjunction
162-
(and not present outside it) are considered "local" to that disjunction.
160+
(and not present outside it) are considered "internal" to that disjunction.
163161

164162
----
165163
match
@@ -174,7 +172,7 @@ $p isa person, has name $p-name;
174172
};
175173
----
176174

177-
Here, `$emp`, `$company`, `$edu`, `$institute` are local to their patterns.
175+
Here, `$emp`, `$company`, `$edu`, `$institute` are internal to their patterns.
178176
`$p` occurs outside the disjunction.
179177
`$org-name` is present in every-branch and returned by the disjunction.
180178

@@ -203,11 +201,11 @@ Any variable that is present both outside and inside the negation is considered
203201
and *must* be bound before matching the negated pattern.
204202
This requires that the variable is bound in the parent conjunction.
205203

206-
Variables that are present only inside the negation are considered local to the negation.
204+
Variables that are present only inside the negation are considered internal to the negation.
207205
A negation without any inputs is extremely unusual.
208206
[NOTE]
209207
====
210-
Local variables are not bound by the negation,
208+
internal variables are not bound by the negation,
211209
since the negation is satisfied only if there are no answers to the negated pattern.
212210
====
213211

@@ -221,7 +219,7 @@ match
221219
};
222220
----
223221

224-
Here, `$p` is an input to the negation. `$e, $c` are local. The query returns:
222+
Here, `$p` is an input to the negation. `$e, $c` are internal. The query returns:
225223
----
226224
-------------
227225
$p-name | isa name "Jeff"
@@ -322,7 +320,7 @@ Finished. Total rows: 3
322320

323321
[NOTE]
324322
====
325-
Optional variables *are* bound by the optional block and not local to it.
323+
Optional variables *are* bound by the optional block and not internal to it.
326324
====
327325

328326
== Notes on variables
@@ -476,14 +474,14 @@ This will return any persons `$p1` & `$p2` when
476474
either (1) `$p1` is employed by *any* and `$p2` attended *any* institute;
477475
or (2) `$p2` is employed by *any* company and `$p1` attended *any* institute.
478476

479-
Notice `$company` is "local" to both the first and second disjunctions (The same is the case for `$institute`).
477+
Notice `$company` is "internal" to both the first and second disjunctions (The same is the case for `$institute`).
480478
TypeQL throws a "disjoint variable re-use" error for such cases.
481479

482480
==== Valid variable scopes:
483481
From these, it can be seen that a variable is either:
484482

485-
1. Local to one branch of one disjunction.
486-
2. Local to one negation.
483+
1. Internal to one branch of one disjunction.
484+
2. Internal to one negation.
487485
3. Bound & present in the answer of the pipeline.
488486

489487
== The select statement

core-concepts/modules/ROOT/pages/typeql/schema-data.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ insert
2626
----
2727

2828
Inserting a new instance will fail if the type is abstract. In the case of attributes,
29-
the value must also be of the value-type specified by the attribute, and satisfy all value constraints defined on the type.
29+
the value must also be of the value type specified by the attribute, and satisfy all value constraints defined on the type.
3030

3131
[#_iid]
3232
Remember that inserted entities and relations don't have a natural identifier in your domain unless you provide one. The caveat here is that TypeDB generates an instance ID (`iid`, which you'll see in output logs) for your inserted entities and relations. However, it is recommended that you create meaningful identifiers, especially keys, when needing to refer to specific entities or relations.

reference/modules/ROOT/pages/typeql/annotations/abstract.adoc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ The `@abstract` annotation does not accept any arguments.
2020

2121
// tag::description[]
2222
When defined for a type, the `@abstract` annotation enforces the `abstract` constraint, making the type abstract.
23-
An abstract type cannot be a direct type for an instance.
24-
Thus, a concrete subtype is required for instances creation, and an abstract type can be used as a query target to retrieve information about its subtypes.
23+
An abstract type cannot be instantiated, but can be used in a query (e.g., in an `isa` constraint to match instances of its subtypes).
2524
// end::description[]
2625

2726
[,typeql]

reference/modules/ROOT/pages/typeql/annotations/card.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ The `@card` annotation can be defined for any `<interface>` of: `owns`, `relates
2525
It accepts either a range argument or a single scalar argument.
2626
Arguments must be integers.
2727

28+
- Both bounds are inclusive.
2829
- A partially unbounded range `N..` has an infinite upper bound.
2930
- The minimal lower bound is `0` and must be explicitly specified (e.g., use `0..M` instead of `..M`).
3031
- A single scalar argument `N` is shorthand for `N..N` and means "exactly N".

reference/modules/ROOT/pages/typeql/expressions/index.adoc

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,34 @@
11
= Expressions
22
:page-aliases: {page-version}@typeql::expressions.adoc
33

4-
This reference covers the usage of expressions in TypeQL.
4+
A TypeQL expression uses operators and functions to
5+
compute a value from other values. It uses the following syntax:
6+
[,typeql]
7+
----
8+
let <var> = <expression>;
9+
----
10+
Examples:
11+
[,typeql]
12+
----
13+
let $x = 5;
514

15+
let $y = $x * 3.1;
16+
17+
let $z = ceil($y + 1);
18+
----
19+
20+
== Validation
21+
The following rules apply to variables involved in expressions:
22+
23+
* The variables used on the right-hand side of an expression must be bound to either attributes or values.
24+
* The attribute may be of various attribute types as long as they all have the same value type.
25+
* A value variable must be assigned to exactly once.
26+
27+
During compilation, the types of every subexpression are resolved, and the expression tree is constructed.
28+
If any function which is passed an argument which does not match the expected type,
29+
or any operator which is not defined for the given combination of types, will fail compilation with an error.
30+
31+
== Explore expressions
632
[cols-3]
733
--
834
.xref:{page-version}@reference::typeql/expressions/literals.adoc[]

reference/modules/ROOT/pages/typeql/functions/index.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
// tag::description[]
77
Functions provide powerful abstractions of query logic. They are a cornerstone of the functional xref:{page-version}@reference::typeql/data-model.adoc[query programming model], and generalize logic programs à la Datalog.
8-
Functions calls can be nested, recursive, and negated. There syntax natively embeds into TypeQL’s declarative pattern language.
8+
Functions calls can be nested, recursive, and negated. Their syntax natively embeds into TypeQL’s declarative pattern language.
99
// end::description[]
1010

1111
[[fun_types]]

0 commit comments

Comments
 (0)