Skip to content

Commit 8d6a551

Browse files
Implement optional scenarios (#372)
## Usage and product changes We implement scenarios testing the functionality of optional reads, and add scenarios to verify the behaviour of disjunctions with regards to shared and non-shared variables in each branch. Highlights: - Sibling optionals cannot share optional variables, though they can re-use any variables from parent scopes - Optionals can be nested - Optionals cannot be used in negations or disjunctions (at least until disjunctions can also return optional answers) - We call the value returned in a Variable when it is a failed optional `None`, instead of `empty`.
1 parent 5761cb0 commit 8d6a551

File tree

13 files changed

+367
-188
lines changed

13 files changed

+367
-188
lines changed

query/functions/usage.feature

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Feature: Function Usage
4141
let $six = five() + 1;
4242
"""
4343
Then uniquely identify answer concepts
44-
| six |
44+
| six |
4545
| value:integer:6 |
4646
Given transaction closes
4747

@@ -107,7 +107,7 @@ Feature: Function Usage
107107
let $ten = five() + five();
108108
"""
109109
Then uniquely identify answer concepts
110-
| ten |
110+
| ten |
111111
| value:integer:10 |
112112
Given transaction closes
113113

@@ -184,8 +184,8 @@ Feature: Function Usage
184184
"""
185185
Then answer size is: 1
186186
Then uniquely identify answer concepts
187-
| z |
188-
| value:integer:1 |
187+
| x | y | z |
188+
| value:integer:2 | value:integer:1 | value:integer:1 |
189189

190190

191191
Scenario: A variable that is input from a previous stage may not be assigned to

query/language/disjunction.feature

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ Feature: TypeQL Disjunction
5353
match $x isa $t; { $t label person; } or { $t label company; };
5454
"""
5555
Then uniquely identify answer concepts
56-
| x |
57-
| key:ref:0 |
58-
| key:ref:1 |
56+
| x | t |
57+
| key:ref:0 | label:person |
58+
| key:ref:1 | label:company |
5959
When get answers of typeql read query
6060
"""
6161
match $x isa $_; { $x has name "Jeff"; } or { $x has name "Amazon"; };
@@ -100,6 +100,61 @@ Feature: TypeQL Disjunction
100100
| key:ref:1 |
101101

102102

103+
Scenario: a variable reused across all nested branches of a nested disjunction is returned
104+
Given transaction commits
105+
106+
Given connection open write transaction for database: typedb
107+
Given typeql write query
108+
"""
109+
insert
110+
$p1 isa person, has ref 10, has name "Alice";
111+
$p2 isa person, has ref 11, has name "Bob";
112+
$p3 isa person, has ref 12, has name "Charlie";
113+
"""
114+
Given transaction commits
115+
116+
Given connection open read transaction for database: typedb
117+
When get answers of typeql read query
118+
"""
119+
match
120+
{
121+
{ $p has ref 10; } or { $p has ref 11; };
122+
} or {
123+
{ $p has ref 11; } or { $p has ref 12; };
124+
};
125+
"""
126+
Then uniquely identify answer concepts
127+
| p |
128+
| key:ref:10 |
129+
| key:ref:11 |
130+
| key:ref:12 |
131+
132+
133+
Scenario: a variable only used in one branch is not returned
134+
Given transaction commits
135+
136+
Given connection open write transaction for database: typedb
137+
Given typeql write query
138+
"""
139+
insert
140+
$p1 isa person, has ref 1, has name "Dave";
141+
$p2 isa person, has ref 2, has name "Eve";
142+
"""
143+
Given transaction commits
144+
145+
Given connection open read transaction for database: typedb
146+
When get answers of typeql read query
147+
"""
148+
match
149+
{ $p isa person, has ref 1; $other isa person, has ref 2; } or { $p isa person, has ref 2; };
150+
"""
151+
Then answers do not contain variable: other
152+
Then uniquely identify answer concepts
153+
| p |
154+
| key:ref:1 |
155+
| key:ref:2 |
156+
157+
103158
Scenario: a conjunction where one disjunction produces a variable, and the other only references it can be planned.
104159
Given transaction closes
105160
Given connection open read transaction for database: typedb

query/language/expression.feature

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ Feature: TypeQL Query with Expressions
7575
"""
7676
match
7777
$x isa person, has age $a, has height $h;
78-
let $v0 = $v; # TODO: Remove. once rebased on Dmitrii's changes
7978
{ let $v = $a * 2; } or { let $v = 0; };
8079
{ let $v = $h * 2; } or { let $v = 1; };
8180
select
@@ -85,7 +84,6 @@ Feature: TypeQL Query with Expressions
8584
"""
8685
match
8786
$x isa person, has age $a, has height $h;
88-
let $v0 = $v; # TODO: Remove. once rebased on Dmitrii's changes
8987
{ let $v = $a * 2; } or { let $v = 1; };
9088
match
9189
{ let $v = $h * 2; } or { let $v = 2; };
@@ -96,7 +94,6 @@ Feature: TypeQL Query with Expressions
9694
"""
9795
match
9896
$x isa person, has age $a, has height $h;
99-
let $v0 = $v; # TODO: Remove. once rebased on Dmitrii's changes
10097
{ let $v = $a * 2; } or { let $v = $h * 2; };
10198
select
10299
$v;
@@ -110,7 +107,6 @@ Feature: TypeQL Query with Expressions
110107
"""
111108
match
112109
$x isa person, has age $a, has height $h;
113-
let $v0 = $v; # TODO: Remove. once rebased on Dmitrii's changes
114110
{ let $v = 12; } or {
115111
let $v1 = $v;
116112
{ let $v = $a * 2; } or { let $v = $h * 2; };
@@ -198,8 +194,8 @@ Feature: TypeQL Query with Expressions
198194
select $x, $y;
199195
"""
200196
Then uniquely identify answer concepts
201-
| x |
202-
| attr:name:Lisa |
197+
| x | y |
198+
| attr:name:Lisa | attr:age:16 |
203199

204200

205201
Scenario: Value variables and concept variables may not share name
@@ -243,15 +239,13 @@ Feature: TypeQL Query with Expressions
243239
"""
244240
match
245241
$p isa person;
246-
let $v0 = $v; # TODO: Remove. once rebased on Dmitrii's changes
247242
{ $p has age $a; let $v = $a; } or
248243
{ $p has name $n; let $v = $n; };
249244
"""
250245
Then typeql read query; fails with a message containing: "All assignments of the variable 'v' must have the same value type."
251246
"""
252247
match
253248
$p isa person, has age $a;
254-
let $v0 = $v; # TODO: Remove. once rebased on Dmitrii's changes
255249
{ let $v = $a * 2; } or
256250
{ let $v = $a / 2.0; };
257251
"""

query/language/fetch.feature

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,10 +1596,10 @@ Feature: TypeQL Fetch Query
15961596
"""
15971597
Given answer size is: 3
15981598
Given uniquely identify answer concepts
1599-
| z |
1600-
| attr:person-name:Alice |
1601-
| attr:person-name:Allie |
1602-
| attr:person-name:Bob |
1599+
| p | z |
1600+
| key:ref:0 | attr:person-name:Alice |
1601+
| key:ref:0 | attr:person-name:Allie |
1602+
| key:ref:1 | attr:person-name:Bob |
16031603

16041604
Given get answers of typeql read query
16051605
"""
@@ -1615,8 +1615,8 @@ Feature: TypeQL Fetch Query
16151615
"""
16161616
Given answer size is: 1
16171617
Given uniquely identify answer concepts
1618-
| z |
1619-
| attr:age:10 |
1618+
| p | z |
1619+
| key:ref:0 | attr:age:10 |
16201620

16211621
When get answers of typeql read query
16221622
"""
@@ -1731,10 +1731,10 @@ Feature: TypeQL Fetch Query
17311731
"""
17321732
Given answer size is: 3
17331733
Given uniquely identify answer concepts
1734-
| z |
1735-
| value:string:Alice |
1736-
| value:string:Allie |
1737-
| value:string:Bob |
1734+
| p | z |
1735+
| key:ref:0 | value:string:Alice |
1736+
| key:ref:0 | value:string:Allie |
1737+
| key:ref:1 | value:string:Bob |
17381738

17391739
Given get answers of typeql read query
17401740
"""
@@ -1751,8 +1751,8 @@ Feature: TypeQL Fetch Query
17511751
"""
17521752
Given answer size is: 1
17531753
Given uniquely identify answer concepts
1754-
| z |
1755-
| value:integer:10 |
1754+
| p | z |
1755+
| key:ref:0 | value:integer:10 |
17561756

17571757
When get answers of typeql read query
17581758
"""
@@ -2113,9 +2113,9 @@ Feature: TypeQL Fetch Query
21132113
"""
21142114
Given answer size is: 2
21152115
Given uniquely identify answer concepts
2116-
| x | y | z |
2117-
| value:integer:2 | value:integer:20 | value:integer:2 |
2118-
| value:integer:0 | value:integer:0 | value:integer:0 |
2116+
| p | x | y | z |
2117+
| key:ref:0 | value:integer:2 | value:integer:20 | value:integer:2 |
2118+
| key:ref:1 | value:integer:0 | value:integer:0 | value:integer:0 |
21192119
When get answers of typeql read query
21202120
"""
21212121
match
@@ -2357,10 +2357,10 @@ Feature: TypeQL Fetch Query
23572357
"""
23582358
Given answer size is: 3
23592359
Given uniquely identify answer concepts
2360-
| z |
2361-
| attr:person-name:Alice |
2362-
| attr:person-name:Allie |
2363-
| attr:person-name:Bob |
2360+
| p | z |
2361+
| key:ref:0 | attr:person-name:Alice |
2362+
| key:ref:0 | attr:person-name:Allie |
2363+
| key:ref:1 | attr:person-name:Bob |
23642364

23652365
Given get answers of typeql read query
23662366
"""
@@ -2376,8 +2376,8 @@ Feature: TypeQL Fetch Query
23762376
"""
23772377
Given answer size is: 1
23782378
Given uniquely identify answer concepts
2379-
| z |
2380-
| attr:age:10 |
2379+
| p | z |
2380+
| key:ref:0 | attr:age:10 |
23812381

23822382
When get answers of typeql read query
23832383
"""
@@ -2452,10 +2452,10 @@ Feature: TypeQL Fetch Query
24522452
"""
24532453
Given answer size is: 3
24542454
Given uniquely identify answer concepts
2455-
| z |
2456-
| value:string:Alice |
2457-
| value:string:Allie |
2458-
| value:string:Bob |
2455+
| p | z |
2456+
| key:ref:0 | value:string:Alice |
2457+
| key:ref:0 | value:string:Allie |
2458+
| key:ref:1 | value:string:Bob |
24592459

24602460
Given get answers of typeql read query
24612461
"""
@@ -2472,8 +2472,8 @@ Feature: TypeQL Fetch Query
24722472
"""
24732473
Given answer size is: 1
24742474
Given uniquely identify answer concepts
2475-
| z |
2476-
| value:integer:10 |
2475+
| p | z |
2476+
| key:ref:0 | value:integer:10 |
24772477

24782478
When get answers of typeql read query
24792479
"""

query/language/insert.feature

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,8 +1142,8 @@ Parker";
11421142
match $r isa $rt; relation $rt;
11431143
"""
11441144
Then uniquely identify answer concepts
1145-
| r |
1146-
| key:ref:1 |
1145+
| r | rt |
1146+
| key:ref:1 | label:loneliness |
11471147
Then transaction commits; fails with a message containing: "at least one role"
11481148

11491149
Scenario: relations of relation types without role types can be inserted, then updated to have role players
@@ -1173,9 +1173,9 @@ Parker";
11731173
match $r isa $rt; relation $rt;
11741174
"""
11751175
Then uniquely identify answer concepts
1176-
| r |
1177-
| key:ref:1 |
1178-
| key:ref:2 |
1176+
| r | rt |
1177+
| key:ref:1 | label:loneliness |
1178+
| key:ref:2 | label:loneliness |
11791179

11801180
When typeql schema query
11811181
"""
@@ -1204,9 +1204,9 @@ Parker";
12041204
match $r isa $rt; relation $rt;
12051205
"""
12061206
Then uniquely identify answer concepts
1207-
| r |
1208-
| key:ref:1 |
1209-
| key:ref:2 |
1207+
| r | rt |
1208+
| key:ref:1 | label:loneliness |
1209+
| key:ref:2 | label:loneliness |
12101210
When transaction commits
12111211

12121212
When connection open read transaction for database: typedb
@@ -1222,8 +1222,8 @@ Parker";
12221222
match $r isa $rt; relation $rt;
12231223
"""
12241224
Then uniquely identify answer concepts
1225-
| r |
1226-
| key:ref:2 |
1225+
| r | rt |
1226+
| key:ref:2 | label:loneliness |
12271227

12281228
#######################
12291229
# ATTRIBUTE INSERTION #
@@ -1899,6 +1899,7 @@ Parker";
18991899
$y isa person, has name "Tarja";
19001900
insert
19011901
(employer: $x, employee: $y) isa employment, has ref 10;
1902+
select $x, $y;
19021903
"""
19031904

19041905
# Should only contain variables mentioned in the insert (so excludes '$z')

query/language/match.feature

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,10 +1412,10 @@ Feature: TypeQL Match Clause
14121412
match relation $t; $r isa $t;
14131413
"""
14141414
Given uniquely identify answer concepts
1415-
| r |
1416-
| key:ref:1 |
1417-
| key:ref:2 |
1418-
| key:ref:3 |
1415+
| r | t |
1416+
| key:ref:1 | label:employment |
1417+
| key:ref:2 | label:friendship |
1418+
| key:ref:3 | label:residency |
14191419
When get answers of typeql read query
14201420
"""
14211421
match ($x) isa $_;
@@ -2536,9 +2536,9 @@ Feature: TypeQL Match Clause
25362536
match $x has name $y;
25372537
"""
25382538
Then uniquely identify answer concepts
2539-
| x |
2540-
| key:ref:0 |
2541-
| key:ref:2 |
2539+
| x | y |
2540+
| key:ref:0 | attr:name:"Leila" |
2541+
| key:ref:2 | attr:name:"TypeDB" |
25422542

25432543

25442544
Scenario: using the 'attribute' meta label, 'has' can match things that own any attribute with a specified value
@@ -3012,9 +3012,9 @@ Feature: TypeQL Match Clause
30123012
$z isa age;
30133013
"""
30143014
Then uniquely identify answer concepts
3015-
| x |
3016-
| key:ref:1 |
3017-
| key:ref:2 |
3015+
| x | z |
3016+
| key:ref:1 | attr:age:25 |
3017+
| key:ref:2 | attr:age:18 |
30183018

30193019

30203020
Scenario: when the answers of a value comparison include both a 'double' and a 'integer', both answers are returned
@@ -3423,9 +3423,9 @@ Feature: TypeQL Match Clause
34233423
match $x isa! $t; $x has name $_;
34243424
"""
34253425
Then uniquely identify answer concepts
3426-
| t |
3427-
| label:人 |
3428-
| label:אדם |
3426+
| x | t |
3427+
| key:ref:0 | label:人 |
3428+
| key:ref:1 | label:אדם |
34293429

34303430
Given get answers of typeql read query
34313431
"""

0 commit comments

Comments
 (0)